Repository navigation
Queries
mysql_tquery runs a query after the queries of its handle sent before it, on one connection, and calls a public with the values of its format when it is done. mysql_tquery_format also formats the query in the plugin, with no length limit, the values of the public first and those of the query after.
new MySQL:gDatabase;
forward OnBanChecked(playerid);
stock CheckBan(playerid, const name[]) {
mysql_tquery_format(gDatabase, "SELECT reason FROM bans WHERE name = %q", "OnBanChecked", "i", playerid, name);
}
public OnBanChecked(playerid) {
if (cache_num_rows() != 0) {
Kick(playerid);
}
return 1;
}mysql_send formats and sends a query that needs no answer.
mysql_pquery and mysql_pquery_format hand the query to any connection of the pool, so it may finish before queries sent earlier. Without a pool they run in order.
mysql_query and mysql_query_format run the query on the game thread and wait for it. They suit the tables made at start up. A kept result is the active cache until another is chosen, and stays until cache_delete.
new MySQL:gDatabase;
stock MakeTables() {
mysql_query(gDatabase, "CREATE TABLE IF NOT EXISTS players (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(24) NOT NULL UNIQUE, score INT NOT NULL DEFAULT 0)", false);
}A query too long for one call is built with mysql_builder_create, mysql_builder_append and mysql_builder_trim, then sent with mysql_builder_tquery. %Q writes the text of a builder into another.
new MySQL:gDatabase;
stock SaveScores() {
new const
Builder:builder = mysql_builder_create(gDatabase, "INSERT INTO scores (player, score) VALUES ")
;
for (new i; i != MAX_PLAYERS; ++i) {
if (IsPlayerConnected(i)) {
mysql_builder_append(builder, "(%i, %i),", i, GetPlayerScore(i));
}
}
mysql_builder_trim(builder, 1);
mysql_builder_tquery(builder);
}mysql_tquery_file and mysql_query_file run the queries of a file in scriptfiles, split at semicolons outside quotes and comments. They stop at the first that fails, and each gives a result of the cache.
mysql_format writes a formatted query into an array, and mysql_escape_string escapes one string. See Specifiers.
mysql 0.6.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- The cache
- JSON cells
- Prepared statements
- Transactions
- The ORM
- Passwords
- Errors
- TLS
- Coming from another plugin
- Performance
Reference
Functions
Connections
Queries
Cache
- cache_get_row_count
- cache_get_field_count
- cache_get_result_count
- cache_get_field_name
- cache_get_field_type
- cache_get_field_index
- cache_set_result
- cache_get_value_index
- cache_get_value_index_int
- cache_get_value_index_float
- cache_get_value_index_bool
- cache_is_value_index_null
- cache_get_value_name
- cache_get_value_name_int
- cache_get_value_name_float
- cache_get_value_name_bool
- cache_is_value_name_null
- cache_get_row
- cache_save
- cache_delete
- cache_set_active
- cache_unset_active
- cache_is_any_active
- cache_is_valid
- cache_affected_rows
- cache_insert_id
- cache_warning_count
- cache_get_query_exec_time
- cache_get_query_string
- cache_get_errno