critical_enter("mysql");
request = SQL_Prepare("SELECT name, guid, rank FROM speedrun_ranks WHERE name = ?");
SQL_BindParam(request, "Iswenzz", level.MYSQL_TYPE_VAR_STRING);
SQL_BindResult(request, level.MYSQL_TYPE_VAR_STRING, 60);
SQL_BindResult(request, level.MYSQL_TYPE_VAR_STRING, 60);
SQL_BindResult(request, level.MYSQL_TYPE_LONG);
SQL_Execute(request);
status = AsyncWait(request);
rows = SQL_FetchRowsDict(request);
for (i = 0; i < rows.size; i++)
{
row = rows[i];
player = row["guid"];
rank = row["rank"];
}
SQL_Free(request);
critical_leave("mysql");
The example above use GSC functions defined in Critical Sections
level.MYSQL_TYPE_DECIMAL = 0;
level.MYSQL_TYPE_TINY = 1;
level.MYSQL_TYPE_SHORT = 2;
level.MYSQL_TYPE_LONG = 3;
level.MYSQL_TYPE_FLOAT = 4;
level.MYSQL_TYPE_DOUBLE = 5;
level.MYSQL_TYPE_NULL = 6;
level.MYSQL_TYPE_TIMESTAMP = 7;
level.MYSQL_TYPE_LONGLONG = 8;
level.MYSQL_TYPE_INT24 = 9;
level.MYSQL_TYPE_DATE = 10;
level.MYSQL_TYPE_TIME = 11;
level.MYSQL_TYPE_DATETIME = 12;
level.MYSQL_TYPE_YEAR = 13;
level.MYSQL_TYPE_NEWDATE = 14;
level.MYSQL_TYPE_VARCHAR = 15;
level.MYSQL_TYPE_BIT = 16;
level.MYSQL_TYPE_TIMESTAMP2 = 17;
level.MYSQL_TYPE_DATETIME2 = 18;
level.MYSQL_TYPE_TIME2 = 19;
level.MYSQL_TYPE_JSON = 245;
level.MYSQL_TYPE_NEWDECIMAL = 246;
level.MYSQL_TYPE_ENUM = 247;
level.MYSQL_TYPE_SET = 248;
level.MYSQL_TYPE_TINY_BLOB = 249;
level.MYSQL_TYPE_MEDIUM_BLOB = 250;
level.MYSQL_TYPE_LONG_BLOB = 251;
level.MYSQL_TYPE_BLOB = 252;
level.MYSQL_TYPE_VAR_STRING = 253;
level.MYSQL_TYPE_STRING = 254;
level.MYSQL_TYPE_GEOMETRY = 255;
Print information about the MySQL client.
SQL_Version();
Connect to a MySQL server.
SQL_Connect("127.0.0.1", 3306, "root", "rootpassword");
Close the MySQL connection.
SQL_Close();
Free a MySQL Request, this must be called after being done with the query/prepare request.
SQL_Free(request);
Prepends backslashes to the following characters: \x00 , \n , \r , \ , ' , " and \x1a . This function must always (with few exceptions) be used to make data safe before sending a query to MySQL.
SQL_EscapeString("\\");
Return a hex representation of the string.
hex = SQL_HexString("Iswenzz");
Select a MySQL database.
SQL_SelectDB("testdb");
Command for performing a query on the database server. The request should be freed when done using SQL_Free.
request = SQL_Query("SELECT * FROM players");
Command for performing a statement on the database server, binds must be set in order. The request should be freed when done using SQL_Free.
request = SQL_Prepare("SELECT name, guid, rank FROM speedrun_ranks WHERE name = ?");
SQL_BindParam(request, "Iswenzz", level.MYSQL_TYPE_VAR_STRING);
SQL_BindResult(request, level.MYSQL_TYPE_VAR_STRING, 60);
SQL_BindResult(request, level.MYSQL_TYPE_VAR_STRING, 60);
SQL_BindResult(request, level.MYSQL_TYPE_LONG);
SQL_BindResult(request, level.MYSQL_TYPE_LONG);
SQL_BindResult(request, level.MYSQL_TYPE_LONG);
SQL_Execute(request);
request = SQL_Prepare("INSERT INTO speedrun_ranks (name, guid, rank) VALUES (?, ?, ?)");
SQL_BindParam(request, "Iswenzz", level.MYSQL_TYPE_VAR_STRING);
SQL_BindParam(request, "313354b4", level.MYSQL_TYPE_VAR_STRING);
SQL_BindParam(request, "80", level.MYSQL_TYPE_LONG);
SQL_Execute(request);
Bind a value in the prepared statement.
SQL_BindParam(request, "Iswenzz", level.MYSQL_TYPE_VAR_STRING);
Bind a result in the prepared statement, if you want to retrieve the col when fetching rows. The <?string length> is optional for all types except strings where you have to specify the string length.
SQL_BindResult(request, level.MYSQL_TYPE_VAR_STRING, 60);
SQL_BindResult(request, level.MYSQL_TYPE_LONG);
Executes the prepared statement.
SQL_Execute(request);
Return the number of rows after a query or statement.
count = SQL_NumRows(request);
Return the number of fields after a query or statement.
count = SQL_NumFields(request);
Return the number of affected rows after a query or statement.
count = SQL_AffectedRows(request);
Retrieve rows data in a two dimensional GSC array after a query.
rows = SQL_FetchRows(request);
if (isDefined(rows) && isDefined(rows.size))
{
for (i = 0; i < rows.size; i++)
{
if (isDefined(rows[i]) && isDefined(rows[i].size))
{
for (j = 0; j < rows[i].size; j++)
comPrint(rows[i][j]);
}
}
}
Retrieve rows data in a two dimensional GSC string indexed array after a query.
rows = SQL_FetchRowsDict(request);
if (isDefined(rows) && isDefined(rows.size))
{
for (i = 0; i < rows.size; i++)
{
if (isDefined(rows[i]) && isDefined(rows[i].size))
{
for (j = 0; j < rows[i].size; j++)
comPrint(rows[i][j]);
}
}
}
Retrieve a single row data in a GSC array after a query.
row = SQL_FetchRow(request);
for (i = 0; i < row.size; i++)
comPrint(row[i]);
Retrieve a single row data in a GSC string indexed array after a query.
row = SQL_FetchRowDict(request);
for (i = 0; i < row.size; i++)
comPrint(row[i]);
Retrieve all fields in a GSC array after a query.
array = SQL_FetchFields(request);
Get all database names.
array = SQL_ListDB();
Get all table names.
array = SQL_ListTables();