← Scripts and libraries
PatrickGTR/MySQL-Prepared-Statements
Prepared Statement implementation for PAWN MySQL
Library★ 27updated Oct 2021No licencePawnsampctl
Open on GitHubThis repository has no licence file. It is public to read, but that alone does not give permission to reuse it.
Install with sampctl
sampctl package install PatrickGTR/MySQL-Prepared-Statements
Run this in your project folder. sampctl downloads the package and what it depends on.
Try it in the Pawn compiler →
Adds its include files, with the libraries it depends on, to the Pawn compiler in your browser, ready to include in a script.
Depends on 3 packages
- sampctl/samp-stdlibnot in this directory
- pblueg/sa-mp-mysqlnot in this directory
- pawn-lang/YSI-Includes★ 227
Used by 3 packages
README.md
Installation
Simply install to your project:
sampctl package install PatrickGTR/MySQL-Prepared-Statements
Include in your code and begin using the library:
#include <mysql_prepared>
Usage
Functions
MySQL_StatementClose(Statement:statement)
MySQL_PrepareStatement(MySQL:handle, const query[])
MySQL_Statement_RowsLeft(&Statement:statement)
MySQL_Statement_FetchRow(Statement:statement)
Writing
MySQL_Bind(Statement:statement, param, const str[])
MySQL_BindInt(Statement:statement, param, value)
MySQL_BindFloat(Statement:statement, param, Float:value)
MySQL_BindPlayerName(Statement:statement, param, playerid)
MySQL_BindPlayerIp(Statement:statement, param, playerid)
Reading
MySQL_BindResult(Statement:statement, field, const result[], len = sizeof(result))
MySQL_BindResultInt(Statement:statement, field, &result)
MySQL_BindResultFloat(Statement:statement, field, &Float:result)
Executing
MySQL_ExecuteThreaded(Statement:statement, const callback[] = "", const fmat[] = "", {Float,_}:...)
MySQL_ExecuteParallel(Statement:statement, const callback[] = "", const fmat[] = "", {Float,_}:...)
MySQL_ExecuteThreaded_Inline(Statement:statement, Func:callback<>)
MySQL_ExecuteParallel_Inline(Statement:statement, Func:callback<>)
Testing
To test, simply run the package:
sampctl package run
Examples
Reading Data (Using inline)
new stmt_readloop = MySQL_PrepareStatement(MySQLHandle, "SELECT * FROM spawns");
// Run Threaded on statement
inline OnSpawnsLoad() {
new
spawnID,
Float:spawnX,
Float:spawnY,
Float:spawnZ,
Float:spawnA;
MySQL_BindResultInt(stmt_readloop, 0, spawnID);
MySQL_BindResultFloat(stmt_readloop, 1, spawnX);
MySQL_BindResultFloat(stmt_readloop, 2, spawnY);
MySQL_BindResultFloat(stmt_readloop, 3, spawnZ);
MySQL_BindResultFloat(stmt_readloop, 4, spawnA);
while(MySQL_Statement_FetchRow(stmt_readloop)) {
printf("%i, %.3f, %.3f, %.3f", spawnID, spawnX, spawnY, spawnZ, spawnA);
}
MySQL_StatementClose(stmt_readloop);
}
MySQL_ExecuteThreaded_Inline(stmt_readloop, using inline OnSpawnsLoad);
Writing Data
new Statement:stmt_insert = MySQL_PrepareStatement(MySQLHandle, "INSERT INTO accounts(username, password, salt, money, kills, deaths) VALUES (?,?,?,?,?,?)");
// Arrow values in questions (first 0, second is 1, etc ...)
MySQL_Bind(stmt_insert, 0 , "patrickgtr");
MySQL_Bind(stmt_insert, 1 , "patrickgtrpassword");
MySQL_Bind(stmt_insert, 2 , "pgtrhash");
MySQL_BindInt(stmt_insert, 3, 100);
MySQL_BindInt(stmt_insert, 4, 200);
MySQL_BindInt(stmt_insert, 5, 300);
MySQL_ExecuteParallel(stmt_insert);
MySQL_StatementClose(stmt_insert);
Full account system example can be found here
Special Thanks to:
| Username | |
|---|---|
| Southclaws | sampctl |
| Y_Less / JustMichael | YSI / Constructive feedback |
| Dayvison | Initial idea |
| Slice | Base code of sqlite improved |
| maddinat0r / BlueG | MySQL Plugin |
mysqlpawnpawn-packagepreparedsa-mpsampctlstmt
This page is built from what GitHub publishes about the repository. samp.directory does not host the code. Report a problem with this listing