Repository navigation
Errors
A query, statement or batch that fails is logged with its error and the start of its text, unless log_errors is off. Then OnMySQLError is called in the script that sent it, and then its own public, where MySQL_GetErrno and MySQL_GetError give the error. A query waited for with MySQL_Run returns false.
new MySQL:gDatabase;
forward OnNameChanged(playerid);
stock ChangeName(playerid, accountid, const name[]) {
MySQL_Query(gDatabase, "OnNameChanged", playerid, "UPDATE accounts SET name = %q WHERE id = %i", name, accountid);
}
public OnNameChanged(playerid) {
if (MySQL_GetErrno() == 1062) {
return SendClientMessage(playerid, -1, "That name is taken.");
}
if (MySQL_GetErrno() != 0) {
return SendClientMessage(playerid, -1, "The name could not be changed.");
}
SendClientMessage(playerid, -1, "Your name was changed.");
return 1;
}Errors from 2000 to 2999 come from the client, as 2013 for a connection lost during a query. The others come from the server, as 1062 for a duplicate key, 1146 for a table that does not exist and 1064 for a mistake in the SQL.
A query that cannot be sent never reaches the database, and the native returns false:
- the handle, the statement or the batch does not exist,
- the format is not valid, such as a specifier without a value, or the values do not match a statement,
- a limit of the connection refused it, as
max_query_length,max_pendingormax_queries_per_second.
Its public is not called, and the reason is logged, at most one line a second for the limits. See Configuration.
A query that loses its connection fails with its error, such as 2006 or 2013, and is not sent again, as the server may have run it already. The next query opens the connection again. While the server cannot be reached, the queries fail at once with the error of the last attempt, and the component tries again after half a second, then twice as long each time, up to five seconds.
The prepared statements of a lost connection are prepared again on the new one by themselves.
MySQL_Connect gives a handle also when the first connection fails, so a gamemode started before its database works when the database comes up. MySQL_IsConnected tells whether the connection is open, and MySQL_GetConnectionErrno and MySQL_GetConnectionError give the reason of the last failure.
INVALID_MYSQL_ID is given only when a setting is not valid, or when the file of MySQL_ConnectFile cannot be read.
MySQL_GetStats gives the queries a handle sent, those that failed, and the average and longest time they took. MySQL_GetPendingCount gives the queries waiting or running, which grows when the database falls behind. The slow_query setting logs every query slower than its milliseconds.
MySQL 0.2.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- Results
- JSON cells
- Prepared statements
- Passwords
- Errors
- TLS
- Coming from R41
- Performance
Reference
Functions