SA-MP Forums Archive
mysql_insert_id issue - 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: mysql_insert_id issue (/showthread.php?tid=456156)



mysql_insert_id issue - DrDoom151 - 04.08.2013

Hello,

I've made a function which adds a row to my sql database containing the vehicle's information. I refer to this row again with an ID, which I auto-increment (AI). So for example, if it loads 3 vehicles I'll be able to refer back to any of them with the ID in the database, which I saved into the vehicleinfo enum when I load the vehicles.

I have created a function so I can save new vehicles into the database from in-game and I'll have to retrieve the AI-integer it gave the row, to save it into the vehicleinfo enum. You can easily do this with the mysql_insert_id. The thing is that either the query's too slow or the mysql_insert_id too fast, so I'm not able to retrieve it properly.

Assuming I have 3 vehicles and I'm saving the 4th. Currently, the first time I do it it'll give me a 0 (which means it's no result), whereas it's supposed to give 4. If I then add another vehicle, the 5th one, it'll give me the 'old' result, 4, instead of the 5 it's supposed to show me. I have checked, if I run it with a timer function of 6 milliseconds, it'll work properly. The problem is that it's just unpractical and I was wondering if you guys knew either a solution or a workaround.


If you have any further questions, feel free to ask! Thanks in advance


Re: mysql_insert_id issue - DrDoom151 - 17.08.2013

Bump. Still have this problem. Help would be appreciated.


Re: mysql_insert_id issue - Vince - 17.08.2013

Are you using threaded queries? If not, you should.


Re: mysql_insert_id issue - DrDoom151 - 18.08.2013

Thanks for your answer, Vince.

I'm using BlueG's MySQL plugin, aren't all queries threaded since R7?


Re: mysql_insert_id issue - Vince - 18.08.2013

Yes, but that also means that you need to have a callback if you want to retrieve an insert_id.


Re: mysql_insert_id issue - DrDoom151 - 18.08.2013

Alright so basicly mysql_insert_id doesn't work because, since it's a threaded query, it executes it before it's done, right?

So I'll just have to create a quick callback without passing any values through the query and then just calling the insert_id in the callback?