SQLite question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQLite question (
/showthread.php?tid=630840)
SQLite question -
RyderX - 19.03.2017
Hello there! so i have started learning SQLite ways, but i got a little question about it,
For example i tried this first to test,
PHP код:
#include <a_samp>
#include <a_sampdb>
#include <zcmd>
main() { }
new DB: someDB; // Handle for database. Our queries need to use this so the queries know where to handle things
public OnGameModeInit() {
someDB = db_open("your.db"); // file 'your.db' will be our SQLite database
}
CMD:getmyname(playerid, params[]) {
new szQuery[74], szOut[32], DBResult: query, szPlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
format(szQuery, sizeof(szQuery), "select * from `players` where `playername` = '%s'", szPlayerName);
query = db_query(someDB, szQuery);
if(db_num_rows(query) > 0) {
SendClientMessage(playerid, 0, "There is more than 0 rows, meaning there is at least 1 row!");
SendClientMessage(playerid, 0, "So there is a registered account with my name!");
db_get_field_assoc(query, "Motto", szOut, sizeof(szOut));
SendClientMessage(playerid, 0, "Your motto is:");
SendClientMessage(playerid, 0, szOut);
db_free_result(query);
}
return 1;
}
it's from a tutorial, i would know how to make a database in scriptfiles, for example like
yourdb.dll, it got compiled gratefully but didn't show any file in scriptfiles, does it require player to join the server and use it and to be showen? thanks anyway!
Re: SQLite question -
iKarim - 19.03.2017
db_open native will automatically create the database if doesn't exist.
Re: SQLite question -
Konstantinos - 19.03.2017
As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.
Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
Re: SQLite question -
RyderX - 19.03.2017
Quote:
Originally Posted by Konstantinos
As soon as the server will start, it will create the file which will be empty. Make sure scriptfiles have correct permissions.
Two more things: %q in format to escape strings and free the result at the very end (because it doesn't free the result if there are not any rows).
|
Yea i have noticed that, thanks btw
Quote:
Originally Posted by PawnHunter
db_open native will automatically create the database if doesn't exist.
|
Okay
Thanks.
Re: SQLite question -
Logic_ - 19.03.2017
Good to see you doing something finally
(sarcastic facepalm :P)
I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
Re: SQLite question -
Hunud - 19.03.2017
He is.not.even responsible to do yini but this.... Nice try
Re: SQLite question -
RyderX - 19.03.2017
Quote:
Originally Posted by Hunud
He is.not.even responsible to do yini but this.... Nice try
|
Thanks pro.
Quote:
Originally Posted by Logic_
Good to see you doing something finally (sarcastic facepalm :P)
I'd recommend you to read Sreyas' SQL introduction and some other good tutorials to know some basics. Best of luck in learning.
|
Ok thank you.
Re: SQLite question -
Eoussama - 19.03.2017
Nice decision moving to SQL, best of luck mate