[Include] QueryBuilder.inc - Easy MySQL Savings/Loadings
#1

Introduction:

Well I had this idea for a while, just never thought of developing and releasing it.
This include is made to save and load from MySQL easily, and doesn't require much knowledge in SQL.

Notes:

There are some things that you should know before using it:

- This version is outdated for BlueG's MySQL Plugin versions above R6-2. See the plugin version here: http://forum.sa-mp.com/showthread.ph...56#post3087456

- This include only supports BlueG's MySQL Plugin which can be found here: https://sampforum.blast.hk/showthread.php?tid=56564
- This include only supports versions R5, R6, R6-2.
- This include does not support cached queries.
- When loading, make sure you fetch the record first, and free the result when you are done!

Version:

• QueryBuilder v1.0 - Initial release

Known Bugs:

- None yet, however if you find a bug you can PM me about it, or reply here with details about the bug.

Functions:
pawn Код:
QueryBuilder_UpdateTable(table[], where[], whereclause[], connectionHandle = 1);
QueryBuilder_UpdateString(field[], value[]);
QueryBuilder_UpdateFloat(field[], Float:value);
QueryBuilder_UpdateInt(field[], value);
QueryBuilder_UpdateFinish();
QueryBuilder_MultiUpdate(format[], {Float,_}:...);
QueryBuilder_UpdateStringSingle(table[], where[], whereclause[], field[], value[], connectionHandle = 1);
QueryBuilder_UpdateIntSingle(table[], where[], whereclause[], field[], value, connectionHandle = 1);
QueryBuilder_UpdateFloatSingle(table[], where[], whereclause[], field[], Float:value, connectionHandle = 1);
QueryBuilder_FetchRecord(table[], field[], record[], fetchstr[], limit = 0, connectionHandle = 1);
QueryBuilder_GetInt(field[]);
Float:QueryBuilder_GetFloat(field[]);
QueryBuilder_GetStr(field[]);
QueryBuilder_GetStrEx(field[], dest[], size = sizeof dest, bool:pack = false);
QueryBuilder_MultiGet(getformat[], {Float,_}:...);
QueryBuilder_GetRowCount(table[], connectionHandle = 1);
QueryBuilder_PrintQuery();
QueryBuilder_Insert(table[], insformat[], {Float,_}:...);
Function Explanations:
Код:
QueryBuilder_UpdateTable(table[], where[], whereclause[], connectionHandle = 1)

	description: start building a query
	
	table[] - the table to update
	where[] - where to update
	whereclause[] - what record to update
	connectionHandle = 1 - which connection to update (default: 1)
	
QueryBuilder_UpdateString(field[], value[])

	description: update a string
	
	field[] - which field to update
	value[] - new string value to set
	
QueryBuilder_UpdateFloat(field[], Float:value)

	description: update a float
	
	field[] - which field to update
	Float:value - new float value to set
	
QueryBuilder_UpdateInt(field[], value)

	description: update an integer

	field[] - which field to update
	value - new integer value to set
	
QueryBuilder_UpdateFinish()

	description: finish updating and send the query

QueryBuilder_MultiUpdate(format[], {Float,_}:...)

	description: update multiple fields at once
	
	format[] - format the field and values (like sscanf)
	{Float,_}:... - Fields & Their Values (field, value)

QueryBuilder_UpdateStringSingle(table[], where[], whereclause[], field[], value[], connectionHandle = 1)

	description: update a single field

	table[] - which table to update
	where[] - where to update
	whereclause[] - what record to update
	field[] - what field to update
	value[] - new string to set
	connectionHandle = which connection to update (default: 1)
	
QueryBuilder_UpdateIntSingle(table[], where[], whereclause[], field[], value, connectionHandle = 1)

    description: update a single field

	table[] - which table to update
	where[] - where to update
	whereclause[] - what record to update
	field[] - what field to update
	value[] - new integer to set
	connectionHandle = which connection to update (default: 1)
	
QueryBuilder_UpdateFloatSingle(table[], where[], whereclause[], field[], Float:value, connectionHandle = 1)

    description: update a single field

	table[] - which table to update
	where[] - where to update
	whereclause[] - what record to update
	field[] - what field to update
	value[] - new float to set
	connectionHandle = which connection to update (default: 1)
	
QueryBuilder_FetchRecord(table[], field[], record[], fetchstr[], limit = 0, connectionHandle = 1)

	description: fetch a record

	table[] - which table to fetch from
	field[] - which field to fetch from
	fetchstr[] - string to store the result
	limit = 0 - how many records to fetch
	connectionHandle = which connection to fetch (default: 1)

QueryBuilder_GetInt(field[])

	description: get an integer from a field
	
	field[] - which field to get the integer from

Float:QueryBuilder_GetFloat(field[])

	description: get a float from a field
	
	field[] - which field to get the float from
	
QueryBuilder_GetStr(field[])

	description: get a string from a field
	
	field[] - which field to get the string from
	
QueryBuilder_GetStrEx(field[], dest[], size = sizeof dest, bool:pack = false)

	description: get a string from a field (extra parameters)
	
	filed[] - which field to get the string from
	dest[] - array to store the string
	size - self explanatory
	pack - pack the string or not
	
QueryBuilder_MultiGet(getformat[], {Float,_}:...)

	description: load multiple values at once

	getformat[] - format the field and values (like sscanf)
	{Float,_}:... - Fields & Their Values (field, value)
	
QueryBuilder_GetRowCount(table[], connectionHandle = 1)

	description: count how many rows are in a table
	
	table[] - table to check how many rows are there
	connectionHandle = which connection to count (default: 1)
	
QueryBuilder_PrintQuery()

	description: print the current query (will print null if used outside of the query building
	
QueryBuilder_Insert(table[], insformat[], {Float,_}:...)

	description: insert a new row into a table
	
	insformat[] - format the field and values
	{Float,_}:... - Fields & Their Values (field, value)
Credits:

- ******: isnull macro
- BlueG: MySQL Plugin
- DrAkE: MultiUpdate and MultiGet idea

Downloads:

- BlueG's MySQL Plugin: Can be found here: https://sampforum.blast.hk/showthread.php?tid=56564
- QueryBuilder v1.0: Can be found here: http://www.solidfiles.com/d/cbc345d77d/

Please do not make any mirrors or upload to pastebin!

Conclusion:

This include can be useful for people who use MySQL in their gamemode.
If you have a suggestion, you can post here or just send me a PM on fourms.

I will be making a tutorial on how to use this include properly, if there is a demand for it, let me know!
Reply
#2

thank you bro
great job
Reply
#3

wow, good job. I like it
Reply
#4

Quote:
Originally Posted by godoy32
Посмотреть сообщение
wow, good job. I like it
Thanks!
Reply
#5

Good,i will use it !
Reply
#6

Quote:
Originally Posted by Marko Koprivanac
Посмотреть сообщение
Good,i will use it !
Thanks
Reply
#7

ah making work easy
and i am great lover of MySQL :X
Reply
#8

I dont see it much easier then usualy mysql_query, all I see is more , and " " typing thats all, also use shorter function names, rename them to QB_UpdateTable for example or QBUT even better, but its me, anyways, great job
Reply
#9

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
ah making work easy
and i am great lover of MySQL :X
Thank you!

Quote:
Originally Posted by ikey07
Посмотреть сообщение
I dont see it much easier then usualy mysql_query, all I see is more , and " " typing thats all, also use shorter function names, rename them to QB_UpdateTable for example or QBUT even better, but its me, anyways, great job
It is much easier! you don't even need to know SQL to use it!
and if you don't like the function name, you can always redefine it with #define.
Reply
#10

Quote:
Originally Posted by ikey07
Посмотреть сообщение
I dont see it much easier then usualy mysql_query, all I see is more , and " " typing thats all, also use shorter function names, rename them to QB_UpdateTable for example or QBUT even better, but its me, anyways, great job
I completely agree. The SQL syntax is simple enough, no need for slowing it down with extra functions just to make it tad easier to beginners. Just learn the syntax how it should be and you can use this knowledge you learn in other languages such as php.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)