mysql_insert_id issue
#1

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
Reply
#2

Bump. Still have this problem. Help would be appreciated.
Reply
#3

Are you using threaded queries? If not, you should.
Reply
#4

Thanks for your answer, Vince.

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

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

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)