SA-MP Forums Archive
cache_insert_id Problem. (BlueG's plugin) - 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: cache_insert_id Problem. (BlueG's plugin) (/showthread.php?tid=514590)



cache_insert_id Problem. (BlueG's plugin) - rappy93 - 22.05.2014

Hey. So basically my problem is that whenever I insert something in the database it returns ID 0 until I restart the server. Look here :

pawn Код:
mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `furnitures` (model, name, houseid, interior, virworld, marketprice, posx, posy, posz) VALUES (%d, '%s', %d, %d, %d, %d, %f, %f, %f)",
model, name, HouseInfo[houseid][hID], interior, world, price, x, y ,z);

mysql_tquery(dbHandle, query);
printf("Furniture inserted with ID : %d", cache_insert_id());
This is the log.
PHP код:
[15:24:05INSERT INTO `furnitures` (modelnamehouseidinteriorvirworldmarketpriceposxposyposzVALUES (1369'Wheelchair'16910149500388.0192261506.8521731080.092529)
[
15:24:05Furniture inserted with ID 
Any ideas why it keeps returning 0 instead of the actual ID ? The table has auto_increment.

I also tried with cache_insert_id(dbHandle), same result.


Re: cache_insert_id Problem. (BlueG's plugin) - Konstantinos - 22.05.2014

I don't think you can call that function outside of the callback you use in the mysql_(t/p)query function.
As you're sure that there is auto-increment for that field:
pawn Код:
mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `furnitures` (model, name, houseid, interior, virworld, marketprice, posx, posy, posz) VALUES (%d, '%s', %d, %d, %d, %d, %f, %f, %f)",
model, name, HouseInfo[houseid][hID], interior, world, price, x, y ,z);
mysql_tquery(dbHandle, query, "OnFurnitureInsert", "i", houseid);
pawn Код:
forward OnFurnitureInsert(house_ID);
public OnFurnitureInsert(house_ID)
{
    printf("Furniture inserted with ID \"%i\" for houseid \"%i\"", cache_insert_id(), HouseInfo[house_ID][hID]);
}



Re: cache_insert_id Problem. (BlueG's plugin) - rappy93 - 22.05.2014

Okay,I'm compiling it now and testing.
I'll be back with an edit afterwards.


Re: cache_insert_id Problem. (BlueG's plugin) - MacT - 22.05.2014

Kontantinos, can you check my MySQL privately ?


Re: cache_insert_id Problem. (BlueG's plugin) - rappy93 - 22.05.2014

Well,that worked.Thank's Konstantions. I don't know what everyone here would do without you !

I'd +rep you if I could do it again


Re: cache_insert_id Problem. (BlueG's plugin) - MacT - 22.05.2014

Haha nice work, partner. Yea I am too slow, damn old man