MySQL/SQLite warning -
Danijel. - 02.03.2014
Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
format(Query, sizeof(Query), "SELECT MAX(ID) FROM CARS");
idc = db_query(Database, Query); //warning line
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, idc);
db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
LoadPlayerCar(idc);
return true;
}
warning 213: tag mismatch
Re: MySQL/SQLite warning -
Konstantinos - 02.03.2014
When you execute a query and you want to store the result, you've got to use DBResult tag.
pawn Код:
new Query[512], DBResult: idc;
so you'll also need to use the tag in the first argument in LoadPlayerCar function.
Since you select, you should free the result at the end.
PS: It's SQLite.
Re: MySQL/SQLite warning -
Danijel. - 02.03.2014
When i add DBResult: idc; i get 3 tag missmatch warnings at:
Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBReslut: idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
format(Query, sizeof(Query), "SELECT MAX(ID) FROM CARS");
idc = db_query(Database, Query); // warning
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, idc); // warning db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
LoadPlayerCar(idc); // warning
return true;
}
I did that before you told me to but i removed it.
Re: MySQL/SQLite warning -
Konstantinos - 02.03.2014
"DBReslut" is wrong and "DBResult" is correct.
Like I said, you'll need to add the DBResult tag in the parameter from LoadPlayerCar function as well.
Re: MySQL/SQLite warning -
Danijel. - 02.03.2014
Like this?
Still errors
Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBResult: idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
format(Query, sizeof(Query), "SELECT MAX(ID) FROM CARS");
idc = db_query(Database, Query);//here
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, idc);
db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
LoadPlayerCar(DBResult: idc); //here
return true;
}
Re: MySQL/SQLite warning -
Konstantinos - 02.03.2014
pawn Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBResult: idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
idc = db_query(Database, "SELECT MAX(ID) FROM CARS");
LoadPlayerCar(idc);
db_free_result(idc);
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, idc);
db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
return true;
}
And I didn't mean the tag here:
pawn Код:
LoadPlayerCar(DBResult: idc);
but in the stock.
Re: MySQL/SQLite warning -
Danijel. - 02.03.2014
Copy/pasted the code and it gives me 2 tag mismatch warnings:
Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBResult: idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
idc = db_query(Database, "SELECT MAX(ID) FROM CARS"); // it should give warning
LoadPlayerCar(idc);//here
db_free_result(idc);
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, idc);//here
db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
return true;
}
Re: MySQL/SQLite warning -
Konstantinos - 02.03.2014
I already told you to add the DBResult tag in the parameter in the LoadPlayerCar stock..
I see about the format, I didn't read the whole line before but what you want to get is not the resultid but the result you retrieve from.
pawn Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBResult: idc;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
idc = db_query(Database, "SELECT * FROM CARS");
LoadPlayerCar(idc);
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, db_num_rows(idc));
db_free_result(idc);
db_query(Database, Query);
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
return true;
}
I haven't use MAX before so I don't know which way I can retrieve the result so I used all.
Re: MySQL/SQLite warning -
Danijel. - 02.03.2014
this is my LoadPlayerCar stock,what do i need to add to it?
Код:
stock LoadPlayerCar(carid)
{
new DBResult: Result, Field[22], Query[350];
format(Query, sizeof(Query), "SELECT * FROM CARS WHERE ID = %d", carid);
Result = db_query(Database, Query);
if(db_num_rows(Result) == 1)
{
printf("\n\n Car ID: %d" ,carid);
db_get_field_assoc(Result, "MODELID", Field, 30);
CarInfo[carid][ModelID] = strval(Field);
printf("Model = %d", CarInfo[carid][ModelID]);
db_get_field_assoc(Result, "COLOR1", Field, 30);
CarInfo[carid][Color1] = strval(Field);
printf("Boja 1: %d ", CarInfo[carid][Color1]);
db_get_field_assoc(Result, "COLOR2", Field, 30);
CarInfo[carid][Color2] = strval(Field);
printf("Boja 2: %d ", CarInfo[carid][Color2]);
db_get_field_assoc(Result, "FUEL", Field, 30);
CarInfo[carid][cFuel] = strval(Field);
db_get_field_assoc(Result, "REGISTERD", Field, 30);
CarInfo[carid][Rega] = strval(Field);
db_get_field_assoc(Result, "X", Field, 30);
CarInfo[carid][cX] = floatstr(Field);
db_get_field_assoc(Result, "Y", Field, 30);
CarInfo[carid][cY] = floatstr(Field);
db_get_field_assoc(Result, "Z", Field, 30);
CarInfo[carid][cZ] = floatstr(Field);
db_get_field_assoc(Result, "ANGLE", Field, 30);
CarInfo[carid][cRot] = floatstr(Field);
printf("Koordinate: %f %f %f ", CarInfo[carid][cX], CarInfo[carid][cY], CarInfo[carid][cZ]);
CarInfo[carid][cID] = CreateVehicle(CarInfo[carid][ModelID], CarInfo[carid][cX], CarInfo[carid][cY], CarInfo[carid][cZ], CarInfo[carid][cRot], CarInfo[carid][Color1], CarInfo[carid][Color2], 0);
}
db_free_result(Result);
return true;
}
And my goal with the MAX(ID) to give me the biggest ID witch is INTEGER PRIMARY KEY in my DB
Re: MySQL/SQLite warning -
Konstantinos - 02.03.2014
You execute a query to set the data to the database and then you execute another query to get them back? Totally pointless. Assign them directly.
pawn Код:
stock CreatePlayerCar(playerid, mid, col1, col2)
{
new Query[512], DBResult: idc, carid;
format(Query, sizeof(Query), "INSERT INTO CARS (MODELID) VALUES(%d)", mid);
db_query(Database, Query);
idc = db_query(Database, "SELECT * FROM CARS");
rows = db_num_rows(idc);
db_free_result(idc);
format(Query, sizeof(Query), "UPDATE CARS SET FUEL = '40.0', X = '2159.5457', Y = '-2321.5134', Z = '15.1379', ANGLE = '0.0', COLOR1 = '%d', COLOR2 = '%d' WHERE ID = %i", col1, col2, carid);
db_query(Database, Query);
CarInfo[carid][ModelID] = mid;
CarInfo[carid][Color1] = col1;
CarInfo[carid][Color2] = col2;
CarInfo[carid][cFuel] = 40;
CarInfo[carid][cX] = 2159.5457;
CarInfo[carid][cY] = -2321.5134;
CarInfo[carid][cZ] = 15.1379;
CarInfo[carid][cRot] = 0.0;
SendClientMessage(playerid, WHITE, "Kupili ste auto.");
return true;
}
This should work and by the way, what I meant was:
pawn Код:
stock LoadPlayerCar(DBResult:carid)
but you don't need the stock at all.