Repository navigation
Results
The MySQL_Get natives take no handle and no result. They read the result of the query whose public is running, or of the last MySQL_Run outside a public. A public called from inside another, such as a CallLocalFunction, keeps the result of its caller until it returns.
The whole result reaches the game thread at once, so reading it costs no round trip to the database.
Rows count from 0, and cells are found by the name of their field, in any case. A field the result does not have is logged once and reads as NULL.
| Native |
NULL reads as |
|---|---|
| MySQL_GetInt | 0 |
| MySQL_GetFloat | 0.0 |
| MySQL_GetBool | false |
| MySQL_GetString | an empty string, and the native returns false
|
MySQL_IsNull tells a NULL from a 0.
new MySQL:gDatabase;
forward OnGarageRead(playerid);
stock ListGarage(playerid, accountid) {
MySQL_Query(gDatabase, "OnGarageRead", playerid, "SELECT model, plate, impounded FROM vehicles WHERE owner = %i", accountid);
}
public OnGarageRead(playerid) {
new
plate[16],
line[64]
;
for (new row, rows = MySQL_GetRowCount(); row != rows; ++row) {
MySQL_GetString(row, "plate", plate);
format(line, sizeof (line), "%i: model %i, plate %s%s", row + 1, MySQL_GetInt(row, "model"), plate, MySQL_GetBool(row, "impounded") ? (", impounded") : (""));
SendClientMessage(playerid, -1, line);
}
return 1;
}MySQL_GetRow reads the fields of a row in their order into variables, with a letter for each: i an integer, f a float, b a bool, s[32] a string with the size of its array and - a field to skip. It finds no names and crosses into the component once, so it is faster than a native for each cell.
forward OnSpawnRead(playerid);
public OnSpawnRead(playerid) {
new
Float:x,
Float:y,
Float:z,
Float:angle,
interior,
world
;
if (MySQL_GetRow(0, "ffffii", x, y, z, angle, interior, world) == 6) {
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), x, y, z, angle);
SetPlayerInterior(playerid, interior);
SetPlayerVirtualWorld(playerid, world);
}
return 1;
}MySQL_GetFieldCount, MySQL_GetFieldName and MySQL_GetFieldIndex describe the fields of a result, for a script that reads a query it did not write, such as one an admin typed.
| Native | Gives |
|---|---|
| MySQL_GetAffectedRows | Rows an INSERT, UPDATE or DELETE changed, or the rows a SELECT returned. |
| MySQL_GetInsertID | The AUTO_INCREMENT id of the first row an INSERT added. |
| MySQL_GetWarningCount | Warnings, such as a value cut to fit its column. |
| MySQL_GetQueryTime | Milliseconds the query took on its connection. |
| MySQL_GetQuery | The text of the query. |
With multi_statements on, a query may hold several statements, and a stored procedure may give several results. Each is a result set. MySQL_GetResultSetCount counts them, and MySQL_SelectResultSet chooses the one the other natives read, the first by default.
A result is freed when its public returns. MySQL_KeepResult keeps it, MySQL_UseResult reads it again later, and MySQL_DestroyResult frees it. A kept result suits a table read once and looked up many times, such as the prices of a shop. The kept results of a script are freed when it unloads.
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