Problem in my vehicle system. -
printer - 14.01.2012
OnGameModeInit:
pawn Код:
for(new v=0; v<sizeof(vInfo); v++)
{
format(mysql, sizeof(mysql), "SELECT * FROM `vehicles` WHERE `VID`=%d", v);
mysql_query(mysql);
mysql_store_result();
new result[200];
if(mysql_fetch_row_format(result))
{
sscanf("p<|>e<isiiiiiis[15]fffii>", vInfo[v]);
CreateVehicle(vInfo[v][vModel], vInfo[v][vX], vInfo[v][vY], vInfo[v][vZ], 1.0, vInfo[v][vColor1], vInfo[v][vColor2], 1000);
}
}
mysql_free_result();
It doesn't give any errors but it won't load any vehicles neither, help please..
Re: Problem in my vehicle system. -
Mean - 14.01.2012
I recommend you use native SQL functions instead of sscanf, the order of fields when using sscanf is very important.
You need to do:
pawn Код:
sscanf("p<|>siiiiiis[15]fffii", vInfo[v][INFO GOES HERE], vInfo[v][INFO GOES HERE], etc.);
You can't just do it all in one part of an array. Also: there's a string without string size.
Re: Problem in my vehicle system. -
printer - 14.01.2012
Quote:
Originally Posted by Mean
I recommend you use native SQL functions instead of sscanf, the order of fields when using sscanf is very important.
You need to do:
pawn Код:
sscanf("p<|>siiiiiis[15]fffii", vInfo[v][INFO GOES HERE], vInfo[v][INFO GOES HERE], etc.);
You can't just do it all in one part of an array. Also: there's a string without string size.
|
Like this?
pawn Код:
sscanf("p<|>isiiiiiisfffii", vInfo[v][vModel], vInfo[v][vOwner], vInfo[v][vLocked], vInfo[v][vLock], vInfo[v][vAlarm], vInfo[v][vInsurance], vInfo[v][vColor1], vInfo[v][vColor2], vInfo[v][vPlate], vInfo[v][vX], vInfo[v][vY], vInfo[v][vZ], vInfo[v][vOwned], vInfo[v][vID]);
When I run the server it says:
Код:
sscanf warning: Format specifier does not match parameter count.
Re: Problem in my vehicle system. -
Mean - 14.01.2012
That means it doesn't match. Check those parameters again, and also, you need the string size in that "s", so it should be "p<|>is[24]iiiiiisfffii"
Keep trying until you get it correct. Oh also, these parameters must match the database, for example, in the database you have first two fields "owner" and "model," it won't work because the order of fields must be the same as the sscanf format, THE SAME, so you need to swap "model" with "owner" either in the sscanf format or in the database, so that makes it "model" and "owner."
Must be completely the same, also the fields you don't use, still need to be added to the sscanf format and later they need to be ignored. For example, if you have that sscanf format, and at the end of the table you still have a few fields, you still need to put them to the sscanf format, but not use them, or destroy them with "#pragma unused."
This is exactly why using native SQL functions is recommended.
Re: Problem in my vehicle system. -
printer - 14.01.2012
Quote:
Originally Posted by Mean
That means it doesn't match. Check those parameters again, and also, you need the string size in that "s", so it should be "p<|>is[24]iiiiiisfffii"
Keep trying until you get it correct. Oh also, these parameters must match the database, for example, in the database you have first two fields "owner" and "model," it won't work because the order of fields must be the same as the sscanf format, THE SAME, so you need to swap "model" with "owner" either in the sscanf format or in the database, so that makes it "model" and "owner."
Must be completely the same, also the fields you don't use, still need to be added to the sscanf format and later they need to be ignored. For example, if you have that sscanf format, and at the end of the table you still have a few fields, you still need to put them to the sscanf format, but not use them, or destroy them with "#pragma unused."
This is exactly why using native SQL functions is recommended.
|
pawn Код:
sscanf("p<|>iis[24]iiiiiis[15]fffi", vInfo[v][vID], vInfo[v][vModel], vInfo[v][vOwner], vInfo[v][vLocked], vInfo[v][vLock], vInfo[v][vAlarm], vInfo[v][vInsurance], vInfo[v][vColor1], vInfo[v][vColor2], vInfo[v][vPlate], vInfo[v][vX], vInfo[v][vY], vInfo[v][vZ], vInfo[v][vOwned]);
It still gives the warning
Код:
sscanf warning: Format specifier does not match parameter count.
And what do you mean SQL native functions? can you give me an example of this with the native MySQL functions?
Re: Problem in my vehicle system. -
Mean - 14.01.2012
Delete, double post. Posted 2 at once without the 120sec time, wtf?
Re: Problem in my vehicle system. -
Mean - 14.01.2012
Depends on what plugin you use, I'm talking about "mysql_fetch_field," "mysql_fetch_field_row," "mysql_fetch_int," etc.
If you want, I can convert your code into standard SQL functions, just tell me which plugin you use. Do you use StrickenKid's SQL plugin or G-Stylez (BlueG) plugin?
An easy test to see which plugin you use is to see what do you have for your SQL include. If it's "mysql.inc," it's StickenKid's include, and if it's "a_mysql.inc," it's G-Stylez plugin.
Re: Problem in my vehicle system. -
printer - 14.01.2012
BlueG.
Re: Problem in my vehicle system. -
Mean - 14.01.2012
OK, first, you need these defines, to make it all easier:
pawn Код:
#define fetch_int(%1,%0) mysql_fetch_field_row(%0,field); \
%1=strval(field)
#define fetch_float(%1,%0) mysql_fetch_field_row(%0,field); \
%1=floatstr(field)
#define fetch_string(%1,%0) mysql_fetch_field_row(%0,%1)
OK, then:
pawn Код:
for(new v=0; v<sizeof(vInfo); v++) {
format(mysql, sizeof(mysql), "SELECT * FROM `vehicles` WHERE `VID`=%d", v);
mysql_query(mysql);
mysql_store_result();
new field[256]; // big, has to be AFAIK
if(mysql_retrieve_row()) {
fetch_int("FIELDNAME", vInfo[v][vID]);
fetch_int("FIELDNAME", vInfo[v][vModel]);
fetch_string("FIELDNAME", vInfo[v][vOwner]);
fetch_int("FIELDNAME", vInfo[v][vLocked]);
fetch_int("FIELDNAME", vInfo[v][vLock]);
fetch_int("FIELDNAME", vInfo[v][vAlarm]);
fetch_int("FIELDNAME", vInfo[v][vInsurance]);
fetch_int("FIELDNAME", vInfo[v][vColor1]);
fetch_int("FIELDNAME", vInfo[v][vColor2]);
fetch_string("FIELDNAME", vInfo[v][vPlate]);
fetch_float("FIELDNAME", vInfo[v][vX]);
fetch_float("FIELDNAME", vInfo[v][vY]);
fetch_float("FIELDNAME", vInfo[v][vZ]);
fetch_int("FIELDNAME", vInfo[v][vOwned]);
}
CreateVehicle(vInfo[v][vModel], vInfo[v][vX], vInfo[v][vY], vInfo[v][vZ], 1.0, vInfo[v][vColor1], vInfo[v][vColor2], 1000);
mysql_free_result();
}
That's it, just replace the field names and correct mistakes such as me putting "fetch_int" when there's a string, etc.
Re: Problem in my vehicle system. -
printer - 14.01.2012
Quote:
Originally Posted by Mean
OK, first, you need these defines, to make it all easier:
pawn Код:
#define fetch_int(%1,%0) mysql_fetch_field_row(%0,field); \ %1=strval(field) #define fetch_float(%1,%0) mysql_fetch_field_row(%0,field); \ %1=floatstr(field) #define fetch_string(%1,%0) mysql_fetch_field_row(%0,%1)
OK, then:
pawn Код:
for(new v=0; v<sizeof(vInfo); v++) { format(mysql, sizeof(mysql), "SELECT * FROM `vehicles` WHERE `VID`=%d", v); mysql_query(mysql); mysql_store_result(); new field[256]; // big, has to be AFAIK if(mysql_retrieve_row()) { fetch_int("FIELDNAME", vInfo[v][vID]); fetch_int("FIELDNAME", vInfo[v][vModel]); fetch_string("FIELDNAME", vInfo[v][vOwner]); fetch_int("FIELDNAME", vInfo[v][vLocked]); fetch_int("FIELDNAME", vInfo[v][vLock]); fetch_int("FIELDNAME", vInfo[v][vAlarm]); fetch_int("FIELDNAME", vInfo[v][vInsurance]); fetch_int("FIELDNAME", vInfo[v][vColor1]); fetch_int("FIELDNAME", vInfo[v][vColor2]); fetch_string("FIELDNAME", vInfo[v][vPlate]); fetch_float("FIELDNAME", vInfo[v][vX]); fetch_float("FIELDNAME", vInfo[v][vY]); fetch_float("FIELDNAME", vInfo[v][vZ]); fetch_int("FIELDNAME", vInfo[v][vOwned]); } CreateVehicle(vInfo[v][vModel], vInfo[v][vX], vInfo[v][vY], vInfo[v][vZ], 1.0, vInfo[v][vColor1], vInfo[v][vColor2], 1000); mysql_free_result(); }
That's it, just replace the field names and correct mistakes such as me putting "fetch_int" when there's a string, etc.
|
Pawn crashes.