15.05.2014, 12:46
Hello,
I'm writting an inventory include and I want to give an optional MySQL saving.
Items are loaded when a player connects and saved when he disconnects. Loading is simple: a select query. Now with the saving, I'm not sure which one to send.
I used to send an update and then if there were no affected rows send an insert one. But I noticed if I try to UPDATE one column and its old value is the same as the one I'm setting it to it return affected rows - 0. And if that's the case, I send an insert query. So when this happens I have two rows for the same thing.
Ofcourse I could send a SELECT query, then check if it exists and update or insert a new one, but that sounds stupid and unefficient.
I considered using a primary key, but both the name and item name can already exist in the table. I do have an auto increment column, but I do now keep track of it in Pawn.
I also read a post about never using delete queries(by ****** I believe). I guess I could add another column for a timestamp and when selecting just select 1 and order by that column. But is it a good idea for an include to do such a thing?
All thoughts will be appreciated
I'm writting an inventory include and I want to give an optional MySQL saving.
Items are loaded when a player connects and saved when he disconnects. Loading is simple: a select query. Now with the saving, I'm not sure which one to send.
I used to send an update and then if there were no affected rows send an insert one. But I noticed if I try to UPDATE one column and its old value is the same as the one I'm setting it to it return affected rows - 0. And if that's the case, I send an insert query. So when this happens I have two rows for the same thing.
Ofcourse I could send a SELECT query, then check if it exists and update or insert a new one, but that sounds stupid and unefficient.
I considered using a primary key, but both the name and item name can already exist in the table. I do have an auto increment column, but I do now keep track of it in Pawn.
I also read a post about never using delete queries(by ****** I believe). I guess I could add another column for a timestamp and when selecting just select 1 and order by that column. But is it a good idea for an include to do such a thing?
All thoughts will be appreciated