SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 06/06/2019, 09:58 PM   #1
PatrickGTR
Little Clucker
 
PatrickGTR's Avatar
 
Join Date: Sep 2010
Location: United Kingdom
Posts: 18
Reputation: 55
Default MySQL Prepared Statements

Introduction
Hi, I'll keep it short and simple.
This emulates prepared statement when using the MySQL plugin.
Thank you for reading this really long introduction.

Download: Click me
Important: sampctl required! check github repository for installation instructions.

Reading Data (using inline)
Code:
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
Code:
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);
Functions

Open/Close
Code:
MySQL_StatementClose(Statement:statement)
MySQL_PrepareStatement(MySQL:handle, const query[])
MySQL_Statement_RowsLeft(&Statement:statement)
MySQL_Statement_FetchRow(Statement:statement)
Writing
Code:
MySQL_Bind(Statement:statement, param, const str[]) 
MySQL_BindInt(Statement:statement, param, value)
MySQL_BindFloat(Statement:statement, param, Float:value)
Reading
Code:
MySQL_BindResult(Statement:statement, field, const result[], len = sizeof(result))
MySQL_BindResultInt(Statement:statement, field, &result)
MySQL_BindResultFloat(Statement:statement, field, &Float:result)
Executing
Code:
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<>)
PatrickGTR is offline   Reply With Quote
Old 06/06/2019, 11:28 PM   #2
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: MySQL Prepared Statements

Ah something like SQLite, nice job.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 08/06/2019, 12:38 AM   #3
PatrickGTR
Little Clucker
 
PatrickGTR's Avatar
 
Join Date: Sep 2010
Location: United Kingdom
Posts: 18
Reputation: 55
Default Re: MySQL Prepared Statements

Quote:
Originally Posted by KeyOfKey View Post
Ah something like SQLite, nice job.
SQLite Improved yes, it's the core.

Added account example script.

https://github.com/PatrickGTR/MySQL-...le/account.pwn
PatrickGTR is offline   Reply With Quote
Old 08/06/2019, 07:31 AM   #4
SiaReyes
Huge Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 323
Reputation: 22
Default Re: MySQL Prepared Statements

Good one bro, it will be useful for newbie. +5 star!
__________________
Offshowtime Fuck It!

Quote:
Originally Posted by Toroi View Post
blackmail people that join your server using their ip address as hostage

or get a job and play sa-mp for fun
SiaReyes is offline   Reply With Quote
Old 13/08/2019, 01:02 PM   #5
PatrickGTR
Little Clucker
 
PatrickGTR's Avatar
 
Join Date: Sep 2010
Location: United Kingdom
Posts: 18
Reputation: 55
Default Re: MySQL Prepared Statements

Updated the include, should be stable now.

Recent commit:

PatrickGTR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Statements MichiCZ Scripting Help 4 10/04/2019 02:24 PM
BlueG's MySQL - Nested select statements causes crash denNorske Scripting Help 3 07/01/2017 05:29 PM
[Include] MySQL Prepared Stataments Dayvison_ Lançamentos/Releases 9 30/03/2016 05:43 AM
Un Prepared Servers... Cole_William General 22 20/05/2014 10:35 AM
for statements. TaLhA XIV Scripting Help 7 06/09/2012 10:14 AM


All times are GMT. The time now is 05:04 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.