sql vehicle ownership system - data not saving
#1

hello everyone i am trying to make a vehicle ownership system with sql this is what i have done so far

Код:
#define SCRIPT_CARS 100

new LoadedVehicles = 0;

new DB: VehicleDB;

enum vInfo
{
	vOwner[MAX_PLAYER_NAME],
	vOwnerID,
	vForSale,
	vModel,
	vCol1,
	vCol2,
	vPrice,
	Float:vPosX,
	Float:vPosY,
	Float:vPosZ,
	Float:vPosA,
}
new VehicleInfo[SCRIPT_CARS][vInfo];

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");

	VehicleDB = db_open("vehicles.db");

    if ((VehicleDB = db_open("vehicles.db")) == DB: 0)  
    { 
        print("Failed to open a connection to \"server.db\"");
    }
    else
    {
        db_query(VehicleDB, "PRAGMA synchronous = OFF");
        db_query(VehicleDB, "CREATE TABLE IF NOT EXISTS vehicles (owner VARCHAR(24) COLLATE NOCASE, ownerid INTEGER PRIMARY KEY AUTOINCREMENT, forsale INTEGER DEFAULT 1 NOT NULL, model INTEGER DEFAULT 0 NOT NULL, color1 INTEGER DEFAULT 0 NOT NULL, color2 INTEGER DEFAULT 0 NOT NULL, price INTEGER DEFAULT 0 NOT NULL, posx FLOAT, posy FLOAT, posz FLOAT, posa FLOAT)");
    }

	LoadVehicles();
	return 1;
}

public OnFilterScriptExit()
{
	db_close(VehicleDB);
	return 1;
}

CMD:aveh(playerid, params[])
{
    new model,color,color2,Float:cPos[4], price;
    if(sscanf(params, "iiii", model, price, color,color2)) return SendClientMessage(playerid, -1, "/aveh [model] [price] [color] [color]");
    if(model < 400 || model > 611) return SendClientMessage(playerid,-1, "vehicle IDs between 400 - 611!");
    if(color> 255 || color< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    if(color2> 255 || color2< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255");
    GetPlayerPos(playerid, cPos[0], cPos[1], cPos[2]);
    GetPlayerFacingAngle(playerid, cPos[3]);
    CreateVehicle(model, cPos[0], cPos[1]-3, cPos[2], cPos[3], color, color2, -1);
	LoadedVehicles ++;
	new Query[208];

	format(Query, sizeof Query, "INSERT INTO vehicles (owner, ownerid, price, forsale, model, x, y, z, a) VALUES ('%s', '%d', '%d', '%d', '%d','%f', '%f', '%f', '%f')", "NONE", -1, price, 1, model, cPos[0], cPos[1], cPos[2], cPos[3]);
	db_query(VehicleDB, Query);

    return 1;
}

stock LoadVehicles()
{
	new DBResult: Result, id, buf[255];

	format(buf, sizeof buf, "SELECT * FROM vehicles");
	Result = db_query(VehicleDB, buf);

	if (db_num_rows(Result))
	{
		id = LoadedVehicles;
		sscanf(buf, "p<|>e<s[25]iiiiiiiifffff>", VehicleInfo[id][vOwner], VehicleInfo[id][vOwnerID], VehicleInfo[id][vForSale], VehicleInfo[id][vModel], VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], VehicleInfo[id][vPrice], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ], VehicleInfo[id][vPosA]);
		CreateVehicle(VehicleInfo[id][vModel],VehicleInfo[id][vPosX],VehicleInfo[id][vPosY],VehicleInfo[id][vPosZ],VehicleInfo[id][vPosA],VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], 60*10000);
		LoadedVehicles = LoadedVehicles+1;
	}
	db_free_result(Result);
}
script creates the table but refuses to save data it should save data when i use /aveh command but its not working
Reply
#2

read wiki man
Reply
#3

any help?
Reply
#4

Do you have error logs? If so, Post them.
Reply
#5

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Do you have error logs? If so, Post them.
nothing it compiles perfectly without any errors i think the problem is in /aveh command but i dont know what is it
Reply
#6

Quote:
Originally Posted by Zerw
Посмотреть сообщение
read wiki man
Avoid posting if you aren't helping



I think the problem is when you load vehicles
Reply
#7

Quote:
Originally Posted by Lucases
Посмотреть сообщение
Avoid posting if you aren't helping



I think the problem is when you load vehicles
maybe but the real problem is saving the data its not saving in database
Reply
#8

Because you don't create that table, it has errors
Код:
Static analysis:

1 errors were found during analysis.

A comma or a closing bracket was expected. (near "AUTOINCREMENT" at position 99)
SQL query:

CREATE TABLE IF NOT EXISTS vehicles (owner VARCHAR(24) COLLATE NOCASE, ownerid INTEGER PRIMARY KEY AUTOINCREMENT, forsale INTEGER DEFAULT 1 NOT NULL, model INTEGER DEFAULT 0 NOT NULL, color1 INTEGER DEFAULT 0 NOT NULL, color2 INTEGER DEFAULT 0 NOT NULL, price INTEGER DEFAULT 0 NOT NULL, posx FLOAT, posy FLOAT, posz FLOAT, posa FLOAT)

MySQL said: Documentation

#1273 - Unknown collation: 'NOCASE'
AUTO_INCREMENT

and COLLATE NOCASE is suppose to be used in a select query.
You don't need case sensitivity on table creation/insert value, it is saved as is, you use it when you want to select.

EDIT:
Quote:

'%s', '%d', '%d', '%d', '%d','%f', '%f', '%f', '%f'

You don't need ' for integers (i.e. %d)
Reply
#9

No, Kaperstone. This is not MySQL - SQLite has different keywords for some things, AUTOINCREMENT is one of them. Also the table must be created with COLLATE NOCASE for player's name as "lackmail" and "lackMail" wouldn't be the same.

Add in server.cfg:
pawn Код:
db_logging 1
and run the server. It will report any error in queries.
Reply
#10

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
Because you don't create that table, it has errors
Код:
Static analysis:

1 errors were found during analysis.

A comma or a closing bracket was expected. (near "AUTOINCREMENT" at position 99)
SQL query:

CREATE TABLE IF NOT EXISTS vehicles (owner VARCHAR(24) COLLATE NOCASE, ownerid INTEGER PRIMARY KEY AUTOINCREMENT, forsale INTEGER DEFAULT 1 NOT NULL, model INTEGER DEFAULT 0 NOT NULL, color1 INTEGER DEFAULT 0 NOT NULL, color2 INTEGER DEFAULT 0 NOT NULL, price INTEGER DEFAULT 0 NOT NULL, posx FLOAT, posy FLOAT, posz FLOAT, posa FLOAT)

MySQL said: Documentation

#1273 - Unknown collation: 'NOCASE'
AUTO_INCREMENT

and COLLATE NOCASE is suppose to be used in a select query.
You don't need case sensitivity on table creation/insert value, it is saved as is, you use it when you want to select.

EDIT:

You don't need ' for integers (i.e. %d)
the table is created once i run the server but it does not save the data as i mentioned, i replaced "INTEGER PRIMARY KEY AUTOINCREMENT" to "INTEGER PRIMARY KEY AUTO_INCREMENT" it compiles but it does not create the table
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)