SQL crashing
#1

I've got a problem while trying to read values using db_get_field_assoc. It keeps crashing the server.

Here's the problem code
pawn Код:
if(db_num_rows(Result)) {
        new PickedSkin[100];
        db_get_field_assoc(Result, "SKIN", PickedSkin, 100);
       
        new C1Message[90];
        format(C1Message, 90, "SKIN %i", strval(PickedSkin));
        TextDrawSetString(SkinLine, C1Message);
       
        new C2Message[90];
        format(C2Message, 90, "~b~%s", Name);
        TextDrawSetString(CharacterName, C2Message);
       
        new C3Message[90];
        new PickedAge[100];
        db_get_field_assoc(Result, "AGE", PickedAge, 100);
        format(C3Message, 90, "%i Years old", strval(PickedAge));
        TextDrawSetString(AgeLine, C3Message);
       
        new C4Message[90];
        new PickedGender[100];
        db_get_field_assoc(Result, "GENDER", PickedGender, 100);
        format(C4Message, 90, "%s", PickedGender);
        TextDrawSetString(GenderLine, C4Message);
       
        new C5Message[90];
        new PickedMoney[100];
        db_get_field_assoc(Result, "MONEY", PickedMoney, 100);
        format(C5Message, 90, "~g~%i$", strval(PickedMoney));
        TextDrawSetString(Finance, C5Message);
And here's the crash log I get ( Using crashdetect )
Код:
[00:42:55] [debug] Server crashed while executing crp.amx
[00:42:55] [debug] AMX backtrace:
[00:42:55] [debug] #0 native db_get_field_assoc () [0044de30] from samp-server.exe
[00:42:55] [debug] #1 000078a4 in ?? (0x00000000) from crp.amx
[00:42:55] [debug] #2 0000310c in public OnDialogResponse (0x00000000, 0x00000004, 0x00000001, 0xffffffff, 0x00004674) from crp.amx
[00:42:55] [debug] Native backtrace:
[00:42:55] [debug] #0 0044dad1 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #1 004010b6 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #2 688f60ba in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\plugins\crashdetect.DLL
[00:42:55] [debug] #3 688f7fee in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\plugins\crashdetect.DLL
[00:42:55] [debug] #4 688f0091 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\plugins\crashdetect.DLL
[00:42:55] [debug] #5 688f610a in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\plugins\crashdetect.DLL
[00:42:55] [debug] #6 0046da61 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #7 004527d0 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #8 688f610a in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\plugins\crashdetect.DLL
[00:42:55] [debug] #9 0046d7e0 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #10 00498ba9 in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #11 0045b22a in ?? () from C:\Users\Administrator\Desktop\SQL SAMP\samp-server.exe
[00:42:55] [debug] #12 769b1129 in ?? () from C:\WINDOWS\SYSTEM32\KERNELBASE.dll
[00:42:55] [debug] #13 769b11f8 in ?? () from C:\WINDOWS\SYSTEM32\KERNELBASE.dll
[00:42:55] [debug] #14 769b1221 in ?? () from C:\WINDOWS\SYSTEM32\KERNELBASE.dll
Reply
#2

It crashes on null values. You could use the DEFAULT constraint when creating tables. Example:
Код:
CREATE TABLE IF NOT EXISTS bla (
	id_bla INTEGER PRIMARY KEY,
	text TEXT DEFAULT '',
	money INTEGER DEFAULT 0);
That way there won't be null values.
Reply
#3

Thanks for replying. Although I'm pretty sure all the variables used to get from db_get_field_assoc have a defined value.

Here take a look.

Creating the table
pawn Код:
db_query(Database, "CREATE TABLE IF NOT EXISTS `ACCOUNTS` (`NAME`, `PASSWORD`, `MONEY` `FACTION`, `LEVEL`, `ADMINLEVEL`, `HELPER`, `DONATOR`, `MODERATOR`, `FRANK`, `SKIN`, `GENDER`, `AGE`)");
Inserting Values
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `ACCOUNTS` (`NAME`, `PASSWORD`, `MONEY`, `FACTION`, `LEVEL`, `ADMINLEVEL`, `HELPER`, `DONATOR`, `MODERATOR`, `FRANK`) VALUES('%s', '%s', '4000', '-1', '0', '0', '0', '0', '0', '0')", DB_Escape(sCzName), DB_Escape(inputtext));
Money variable is defined above.

And for the skin, gender and age variables
pawn Код:
format(Query, sizeof(Query), "update `ACCOUNTS` set `SKIN` = '%i' where `NAME` = '%s'", DB_Escape(SkinID[playerid]), szName);
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET `AGE` = '%i' WHERE `NAME` = '%s' AND SET `GENDER` = '%s' WHERE `NAME` = '%s'", DB_Escape(AgeID[playerid]), szName, DB_Escape(GenderID), szName);
The problem only appeared when I attempted to grab those values from the DB.
Reply
#4

Quote:
Originally Posted by Alexis1999
Посмотреть сообщение
Thanks for replying. Although I'm pretty sure all the variables used to get from db_get_field_assoc have a defined value.

Here take a look.

Creating the table
pawn Код:
db_query(Database, "CREATE TABLE IF NOT EXISTS `ACCOUNTS` (`NAME`, `PASSWORD`, `MONEY` `FACTION`, `LEVEL`, `ADMINLEVEL`, `HELPER`, `DONATOR`, `MODERATOR`, `FRANK`, `SKIN`, `GENDER`, `AGE`)");
Inserting Values
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `ACCOUNTS` (`NAME`, `PASSWORD`, `MONEY`, `FACTION`, `LEVEL`, `ADMINLEVEL`, `HELPER`, `DONATOR`, `MODERATOR`, `FRANK`) VALUES('%s', '%s', '4000', '-1', '0', '0', '0', '0', '0', '0')", DB_Escape(sCzName), DB_Escape(inputtext));
Money variable is defined above.

And for the skin, gender and age variables
pawn Код:
format(Query, sizeof(Query), "update `ACCOUNTS` set `SKIN` = '%i' where `NAME` = '%s'", DB_Escape(SkinID[playerid]), szName);
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET `AGE` = '%i' WHERE `NAME` = '%s' AND SET `GENDER` = '%s' WHERE `NAME` = '%s'", DB_Escape(AgeID[playerid]), szName, DB_Escape(GenderID), szName);
The problem only appeared when I attempted to grab those values from the DB.
pawn Код:
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET AGE = '%d', GENDER = '%d' WHERE `NAME` = '%s'", DB_Escape(AgeID[playerid]), DB_Escape(GenderID), szName);
Try this.
Reply
#5

Do you use any programs/tools to test your queries? I'd recommend SQLite Manager (Firefox addon).
Reply
#6

Quote:
Originally Posted by Stylock
Посмотреть сообщение
Do you use any programs/tools to test your queries? I'd recommend SQLite Manager (Firefox addon).
Thank you so much, With the SQLite Manager I recreated fresh table and defined the default values and now it's working as charm! REP +
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)