SQLite question
#1

I wonder what is difference and advantage/disadvantage of using 's and `s.

For example without:
"SELECT * FROM users WHERE username = '%s'

or with:

"SELECT * FROM `users` WHERE `username` = '%s'
Reply
#2

It's not necessary to use ` ` around table's/fields' name and by that, you reduce the size of the query (imagive if it had many fields etc).
Reply
#3

Quote:
Originally Posted by Konstantinos
View Post
It's not necessary to use ` ` around table's/fields' name and by that, you reduce the size of the query (imagive if it had many fields etc).
And it won't make any difference? like ability to get bugged easier or something?

EDIT: Also, the SAMP player name size was reduced to 20 characters, that means we can reduce the var sizes to 21? 20 characters + 1 empty.

BTW in your tutorial I saw this:
"UPDATE users SET admin = %d WHERE username = '%s'"

why is ' used in username and not in admin?
like it's used here: '%s' but not at admin where it's only: %d without 's.
So can we also remove the 's from the name or?
Reply
#4

Well, just now I re-scripted it with help of Konstantinos' tutorial, but I get an error when player disconnects, the stats aren't saved.

OnPlayerDisconnect
pawn Code:
new Query[185], DBResult:Result;
    format(Query, sizeof(Query), "UPDATE users SET ip = %s, money = %d, score = %d, kills = %d, deaths = %d, adminlevel = %d, viplevel = %d WHERE name = '%s'",
    PlayerInfo[playerid][IP], PlayerInfo[playerid][Money], GetPlayerScore(playerid), PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Admin], PlayerInfo[playerid][VIP], DB_Escape(PlayerName(playerid)));
    Result = db_query(BFU, Query);
    if(Result) printf("SQLITE: account of %s - SAVED.", PlayerName(playerid));
    else if(!Result) printf("SQLITE ERROR: account of %s - NOT SAVED.", PlayerName(playerid));
    db_free_result(Result);
OnGameModeInit
pawn Code:
db_query(BFU, "CREATE TABLE IF NOT EXISTS users (name VARCHAR(24) COLLATE NOCASE, password VARCHAR(24), ip VARCHAR(16), money INTEGER DEFAULT 0 NOT NULL, score INTEGER DEFAULT 0 NOT NULL, kills INTEGER DEFAULT 0 NOT NULL, deaths INTEGER DEFAULT 0 NOT NULL, adminlevel INTEGER DEFAULT 0 NOT NULL, viplevel INTEGER DEFAULT 0 NOT NULL)");
I can't manage to see the mistake, help?
Reply
#5

On strings you have to use apostrofes around the specifier like this: '%s' but on integers/floats, you don't. So change:
pawn Code:
"UPDATE users SET ip = %s ..."
to:
pawn Code:
"UPDATE users SET ip = '%s' ..."
Reply
#6

Alright, it works now.
Thanks for help.

Can you tell me what does LIMIT do?
pawn Code:
SELECT * FROM users WHERE name = '%s' AND password = '%s' LIMIT 0, 1
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)