SA-MP Forums Archive
SQLite Help - 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 Help (/showthread.php?tid=480527)



SQLite Help - Norrin - 11.12.2013

Hi there,
I'm making a script using SQLite. Everything went well today, until I encountered this problem. I can't seem to find what's wrong within this piece of code.

It is supposed to create a table named "Accounts" if it doesn't exist, but it doesn't create the table anymore where as it used to.

pawn Код:
Database = db_open("database.db");
    new string[2048];
    strcat(string, "CREATE TABLE IF NOT EXISTS Accounts(");
    strcat(string, "UserID INTEGER PRIMARY KEY AUTOINCREMENT,");
    strcat(string, "Username VARCHAR(24) COLLATE NOCASE,");
    strcat(string, "Password VARCHAR(128),");
    strcat(string, "Age INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Gender INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Tutorial INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Group INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "GroupRank INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "GroupLeader INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "IP VARCHAR(16),");
    strcat(string, "Banned INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "BanReason VARCHAR(64),");
    strcat(string, "BanExpiry INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "JailTime INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "JailReason VARCHAR(64),");
    strcat(string, "AdminLevel INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Money INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "PositionX FLOAT DEFAULT 0.0,");
    strcat(string, "PositionY FLOAT DEFAULT 0.0,");
    strcat(string, "PositionZ FLOAT DEFAULT 0.0,");
    strcat(string, "FacingAngle FLOAT DEFAULT 0.0,");
    strcat(string, "Interior INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "VirtualWorld INTEGER DEFAULT 0 NOT NULL,");
    strcat(string, "Health FLOAT DEFAULT 0.0,");
    strcat(string, "Armour FLOAT DEFAULT 0.0,");
    strcat(string, "Skin INTEGER DEFAULT 0 NOT NULL)");
    db_query(Database, string);
Here's the code as a whole:
Код:
CREATE TABLE IF NOT EXISTS Accounts(UserID INTEGER PRIMARY KEY AUTOINCREMENT,Username VARCHAR(24) COLLATE NOCASE,Password VARCHAR(128),Age INTEGER DEFAULT 0 NOT NULL,Gender INTEGER DEFAULT 0 NOT NULL,Tutorial INTEGER DEFAULT 0 NOT NULL,Group INTEGER DEFAULT 0 NOT NULL,GroupRank INTEGER DEFAULT 0 NOT NULL,GroupLeader INTEGER DEFAULT 0 NOT NULL,IP VARCHAR(16),Banned INTEGER DEFAULT 0 NOT NULL,BanReason VARCHAR(64),BanExpiry INTEGER DEFAULT 0 NOT NULL,JailTime INTEGER DEFAULT 0 NOT NULL,JailReason VARCHAR(64),AdminLevel INTEGER DEFAULT 0 NOT NULL,Money INTEGER DEFAULT 0 NOT NULL,PositionX FLOAT DEFAULT 0.0,PositionY FLOAT DEFAULT 0.0,PositionZ FLOAT DEFAULT 0.0,FacingAngle FLOAT DEFAULT 0.0,Interior INTEGER DEFAULT 0 NOT NULL,VirtualWorld INTEGER DEFAULT 0 NOT NULL,Health FLOAT DEFAULT 0.0,Armour FLOAT DEFAULT 0.0,Skin INTEGER DEFAULT 0 NOT NULL)
I might have missed a comma or parenthesis somewhere, but I can't notice any. Please help. Thank you.


EDIT: There's something wrong with this code =>
strcat(string, "Group INTEGER DEFAULT 0 NOT NULL,");

When I replaced the Group with pGroup, it seemed to work..
But it would be better if I could use Group. Any suggestions?


Re: SQLite Help - Norrin - 11.12.2013

Sorry for the double post. Please delete this.


Re: SQLite Help - Vince - 11.12.2013

"Group", as in "group by", is an SQL reserved word and as such cannot be used as a field name. The engine detects this keyword in a place it's not supposed to be and errors out.