SQLite - Create multiple tables in db
#1

Hi all ^^

I created a gamemode from scratch with sqlite registration system and everything works great. Everything works perfectly using a single table in the database, but when I add more to an error. No edit/create the second table. I add the related code:

If I use only this, it works correctly.

pawn Code:
new string[256];
            format(string, sizeof(string), "INSERT INTO `CUENTAS` (`NOMBRE`, `PASSWORD`, `ACCESLEVEL`, `ESTADO`, `IP`) VALUES ('%s','%s','%i','%i','%s')", DB_Escape(NombrePersonaje(playerid)), (inputtext), ACCESLEVEL_DEFAULT, ESTADO_ONLINE, DB_Escape(DireccionIP(playerid)));
            db_free_result(db_query(Sqlite, string));
The error what I have to add the second table; no work :S

pawn Code:
new string[256];
            format(string, sizeof(string), "INSERT INTO `CUENTAS` (`NOMBRE`, `PASSWORD`, `ACCESLEVEL`, `ESTADO`, `IP`) VALUES ('%s','%s','%i','%i','%s')", DB_Escape(NombrePersonaje(playerid)), (inputtext), ACCESLEVEL_DEFAULT, ESTADO_ONLINE, DB_Escape(DireccionIP(playerid)));
            format(string, sizeof(string), "INSERT INTO `PERSONAJES` (`NOMBRE`, `PUNTOS`, `KARMA`, `POSX`, `POSY`, `POSZ, `SKIN``) VALUES ('%s','0','0','0','0','0','0')", DB_Escape(NombrePersonaje(playerid)));
            db_free_result(db_query(Sqlite, string));
Any suggestions? Thanks ^^

PS: I have no permission to post in the appropriate section of support, sorry :S
Reply
#2

Must be

format
db_free...
format
db_free..
Reply
#3

Quote:
Originally Posted by Jefff
View Post
Must be

format
db_free...
format
db_free..
No.. no work :S
Reply
#4

pawn Code:
format(string, sizeof(string), "INSERT INTO `CUENTAS` (`NOMBRE`, `PASSWORD`, `ACCESLEVEL`, `ESTADO`, `IP`) VALUES ('%s','%s','%i','%i','%s')", DB_Escape(NombrePersonaje(playerid)), (inputtext), ACCESLEVEL_DEFAULT, ESTADO_ONLINE, DB_Escape(DireccionIP(playerid)));
db_free_result(db_query(Sqlite, string));
format(string, sizeof(string), "INSERT INTO `PERSONAJES` (`NOMBRE`, `PUNTOS`, `KARMA`, `POSX`, `POSY`, `POSZ, `SKIN``) VALUES ('%s','0','0','0','0','0','0')", DB_Escape(NombrePersonaje(playerid)));
db_free_result(db_query(Sqlite, string));
and you heard about default value in table ?

Create Table PERSONAJES .... fieldname smallint(10) default 0
Reply
#5

Quote:
Originally Posted by Jefff
View Post
pawn Code:
format(string, sizeof(string), "INSERT INTO `CUENTAS` (`NOMBRE`, `PASSWORD`, `ACCESLEVEL`, `ESTADO`, `IP`) VALUES ('%s','%s','%i','%i','%s')", DB_Escape(NombrePersonaje(playerid)), (inputtext), ACCESLEVEL_DEFAULT, ESTADO_ONLINE, DB_Escape(DireccionIP(playerid)));
db_free_result(db_query(Sqlite, string));
format(string, sizeof(string), "INSERT INTO `PERSONAJES` (`NOMBRE`, `PUNTOS`, `KARMA`, `POSX`, `POSY`, `POSZ, `SKIN``) VALUES ('%s','0','0','0','0','0','0')", DB_Escape(NombrePersonaje(playerid)));
db_free_result(db_query(Sqlite, string));
and you heard about default value in table ?

Create Table PERSONAJES .... fieldname smallint(10) default 0
Mmm.. I have created the tables from SQLite Database Browser.

Reply
#6

pawn Code:
CREATE TABLE IF NOT EXISTS `PERSONAJES` (`NOMBRE` VARCHAR(25), `PUNTOS` SMALLINT(5) DEFAULT 0, `KARMA` SMALLINT(5) DEFAULT 0, `POSX` FLOAT DEFAULT 0.0, `POSY` FLOAT DEFAULT 0.0, `POSZ` FLOAT DEFAULT 0.0, `SKIN` SMALLINT(3) DEFAULT 0)
and then

pawn Code:
format(string, sizeof(string), "INSERT INTO `PERSONAJES` (`NOMBRE`) VALUES ('%s')", DB_Escape(NombrePersonaje(playerid)));
Reply
#7

Quote:

db_free_result(db_query(Sqlite, string));

That's not how you should use db_free_result. You should only use it when you're using the SELECT method, that way upon receiving a result you will free it later (to stop clogging anything?). In short, use it only on variables with the "DBResult: " tag.
Reply
#8

Thx, i fix this error. Now work ^^

Need help with storage of data, for example "money". My code:

Code:
format(string, sizeof(string), "UPDATE `DINERO` SET `EFECTIVO` = '%s' WHERE NOMBRE= '%s'", GetPlayerMoney(playerid), DB_Escape(NombrePersonaje(playerid)));
	db_free_result(db_query(Sqlite, string));
But in db save this :S



Same error in skin:

Code:
format(string, sizeof(string), "UPDATE `PERSONAJES` SET `SKIN` = '%s' WHERE NOMBRE= '%s'", GetPlayerSkin(playerid), DB_Escape(NombrePersonaje(playerid)));
	db_free_result(db_query(Sqlite, string));
In db:



-----------------------------------------------------------------------------------------------------

My db code:

Code:
CREATE TABLE IF NOT EXISTS `CUENTAS` (`NOMBRE` VARCHAR(45) NOT NULL DEFAULT '', `PASSWORD` VARCHAR(45) DEFAULT 0, `ACCESLEVEL` TINYINT NOT NULL DEFAULT 0, `ESTADO` VARCHAR(3) DEFAULT 0, `IP` CHAR(15) NULL DEFAULT NULL)


CREATE TABLE IF NOT EXISTS `PERSONAJES` (`NOMBRE` VARCHAR(45), `PUNTOS` SMALLINT(5) DEFAULT 0, `KARMA` SMALLINT(5) DEFAULT 0, `POSX` FLOAT DEFAULT 0.0, `POSY` FLOAT DEFAULT 0.0, `POSZ` FLOAT DEFAULT 0.0, `SKIN` SMALLINT(3) DEFAULT 0)

CREATE TABLE IF NOT EXISTS `DINERO` (`NOMBRE` VARCHAR(45), `EFECTIVO` INT UNSIGNED DEFAULT NULL, `ELECTRONICO` INT UNSIGNED DEFAULT NULL)
Reply
#9

Fix:

Code:
format(string, sizeof(string), "UPDATE `PERSONAJES` SET `SKIN` = '%d' WHERE NOMBRE= '%s'", GetPlayerSkin(playerid), DB_Escape(NombrePersonaje(playerid)));
	db_free_result(db_query(Sqlite, string));
Code:
format(string, sizeof(string), "UPDATE `DINERO` SET `EFECTIVO` = '%d' WHERE NOMBRE= '%s'", GetPlayerMoney(playerid), DB_Escape(NombrePersonaje(playerid)));
	db_free_result(db_query(Sqlite, string));
Thx for all ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)