SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 10/11/2019, 01:25 PM   #1
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,477
Reputation: 1632
Default Extend MySQL

This is something I'm using in a gamemode I'm writing.
Thought it might be usefull for other people aswell.

Functions
mysql_error(const msg[], error_level = SQL_ERROR_FATAL, bool:showError = true, MySQL:handle = MYSQL_DEFAULT_HANDLE)
Send a mysql error. Return 0 if it's a fatal error, else 1. Choose whether you want to print the specific error code + description or not. Can be usefull to block gamemode initialisation for example. It's basically just an easier way of handling MySQL errors and sending a log to the server log/console or not.
Example usage:
Code:
mysql_connect(...)
if (mysql_errno() != 0)
    return mysql_error("Couldn't connect to the DB, abort initialisation!");

db_col_exists(const table[], const column[])
Check if a column exists in a table. returns true if it does, false if it doesn't
Example usage:
Code:
if (!db_col_exists("users", "password"))
    SendClientMessage(playerid, -1, "Column 'password' does NOT exist in in the table 'users'!");
else SendClientMessage(playerid, -1, 'Column 'password' does exist in the table 'users'!");
db_col_add(const table[], const column[], const column_data[], const add_after[] = "")
Add a column to a table. Returns true if it was succesfull, false if it wasn't. Note that it doesn't create a new table if the table doesn't exist. It also doesn't check if the column exists or not. Trying to add an existing column will print
Example usages:
Code:
if (!db_col_exists("users", "password"))
    db_col_add("users", "password", "VARCHAR(128) NOT NULL", "ID"); //Adds 'password' after column 'ID'

if (!db_col_exists("users", "adminlevel"))
    db_col_add("users", "adminlevel", "INT NOT NULL DEFAULT 0"); //Add 'adminlevel' as last column
db_remove_tables(bool:confirm = false, bool:print_names = false, MySQL:handle = MYSQL_DEFAULT_HANDLE)
Either drop all tables in a database or just count them. Returns the amount of existing or dropped tables or 0 if there was an error (or if there are no tables).
Example usages:
Code:
db_remove_tables(); //Simply count tables in the database you are connected to
db_remove_tables(.print_names = true); //Count tables and print all the tables to the console
db_remove_tables(true); //Remove all tables in database. Parameter print_names is ignored and will print deleted tables do the console/server log
Not sure if it's actualy usefull. I'm using this for an auto-updater script. Thought I might share it.


Sidenotes
- Queries are non-threaded. You should not use them after gamemode init.
- Strings are not escaped. If you're gonna use it, use it properly
- If people are actually interrested in this I might create more functions (on request too)

Download
https://pastebin.com/W5JRyCsh
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/

Last edited by Kwarde; 10/11/2019 at 04:39 PM.
Kwarde is online now   Reply With Quote
Old 10/11/2019, 01:50 PM   #2
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 91
Reputation: 1
Default Re: Extend MySQL

Nice
Hammad123 is offline   Reply With Quote
Old 10/11/2019, 04:38 PM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,477
Reputation: 1632
Default Re: Extend MySQL

Actually it wasn't nice (copied it from my gamemode so some variables in it didn't exist --> errors). Now that is fixed tho :P
Also added db_remove_tables()
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is online now   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
can't extend the letters amount in 3dtextlabel? DemME Scripting Help 3 31/05/2017 04:21 AM
Extend Command Pk93 Scripting Help 3 29/07/2013 01:17 AM
Garhouse help please extend limit? ironmenpr17 Help Archive 16 21/05/2011 07:34 PM
extend limits.. propilot Help Archive 19 25/12/2010 01:04 AM


All times are GMT. The time now is 01:44 AM.


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