SA-MP Forums Archive
SQLite using more tables - 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 using more tables (/showthread.php?tid=453413)



SQLite using more tables - Sk1lleD - 24.07.2013

I've used a query to create, if the table doesn't exists, the table called "bizs" with all info of BizInfo
But, unlike the users table, it doens't create, and the infos doens't get save.

Код:
new dbstring[1024], bizquery[1024];
	strcat(dbstring, "CREATE TABLE IF NOT EXISTS users (userid INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(24) COLLATE NOCASE, password VARCHAR(129),admin INT DEFAULT 0 NOT NULL, nome VARCHAR(24) COLLATE NOCASE, money INT DEFAULT 0 NOT NULL, level INT DEFAULT 1 NOT NULL, skin INT DEFAULT 299 NOT NULL, tutorial INT DEFAULT 0 NOT NULL");
	strcat(dbstring, ",interior INT DEFAULT 0 NOT NULL, virtualworld INT DEFAULT 0 NOT NULL,  anno INT DEFAULT 0 NOT NULL, mese INT DEFAULT 0 NOT NULL)");
	db_query( Database, dbstring);
//Till here it works, from here nope
	strcat(bizquery, "CREATE TABLE IF NOT EXISTS bizs (bizid INTEGER PRIMARY KEY AUTOINCREMENT, owned INTEGER DEFAULT 0 NOT NULL, owner VARCHAR(30), entratax FLOAT, entratay FLOAT, entrataz FLOAT, uscitax FLOAT, uscitay FLOAT, uscitaz FLOAT, locked INTEGER DEFAULT 0 NOT NULL, entrance INTEGER DEFAULT 0 NOT NULL, interior INT DEFAULT 0 NOT NULL");
	strcat(bizquery, ", buyprice INTEGER DEFAULT 999999 NOT NULL");
	db_query( Database, bizquery);
Код:
public SaveBiz()
{
	for(new b=0; b < MAX_BIZ; b++)
	{
	    new Query[ 128 ];
        format( Query, sizeof( Query ), "UPDATE bizs SET owned = %d WHERE bizid = %d", BizInfo[b][bOwned], b);
        db_query( Database, Query );
	}
	return 1;
}
Any help please? +rep


Re: SQLite using more tables - iggy1 - 25.07.2013

It's most likely because you're trying to create a column called "interior". Remember if the column name also contains a typename, you must wrap it in a couple of "backticks" (`).

pawn Код:
`interior` INT DEFAULT 0 NOT NULL
You can reuse the same array for the queries too.
pawn Код:
new szQuery[1024];
strcat(szQuery, "CREATE TABLE IF NOT EXISTS users (userid INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(24) COLLATE NOCASE, password VARCHAR(129),admin INT DEFAULT 0 NOT NULL, nome VARCHAR(24) COLLATE NOCASE, money INT DEFAULT 0 NOT NULL, level INT DEFAULT 1 NOT NULL, skin INT DEFAULT 299 NOT NULL, tutorial INT DEFAULT 0 NOT NULL");
strcat(szQuery, ",interior INT DEFAULT 0 NOT NULL, virtualworld INT DEFAULT 0 NOT NULL,  anno INT DEFAULT 0 NOT NULL, mese INT DEFAULT 0 NOT NULL)");
db_query( Database, szQuery);

strdel(szQuery, 0, sizeof(szQuery));//clean up query as it's been used

strcat(szQuery, "CREATE TABLE IF NOT EXISTS bizs (bizid INTEGER PRIMARY KEY AUTOINCREMENT, owned INTEGER DEFAULT 0 NOT NULL, owner VARCHAR(30), entratax FLOAT, entratay FLOAT, entrataz FLOAT, uscitax FLOAT, uscitay FLOAT, uscitaz FLOAT, locked INTEGER DEFAULT 0 NOT NULL, entrance INTEGER DEFAULT 0 NOT NULL, `interior` INT DEFAULT 0 NOT NULL");
strcat(szQuery, ", buyprice INTEGER DEFAULT 999999 NOT NULL");
db_query( Database, szQuery);



Re: SQLite using more tables - Sk1lleD - 25.07.2013

Thanks! +rep
And have you seen some problems in the save ? cause it doesn't works