And of course I also suggest to write this code one time and use it over and over for the whole application. Assuming the RETURNING clause works whether an. If not for the superiority of the RETURNING clause and the limitations of having a single rowid result from the existing API, one might make a compelling argument for a new API. You can use max() as some suggest - but I tend to avoid that approach, since I might be use some custom incrementing code for the last insert (and below the max value).Īs a result, such a number not always going to be the max most high value - so I suggest last_insert_rowid() over that of using max() function. Karsten Hilbert wrote: > In sqlite and mysql, I can do > c.execute(insert into foo ( v ) values ( xyz )) > k c.lastrowid >. I would agree that 'lastinsertrowid' would be a poor name for something better called 'lastinsertorupdaterowid'. So, I have general routine - write it once, and then use it for all cases in which I need/require the last inserted auto number PK id. I want to get the last inserted row id in my android application using this code : String query 'SELECT from SQLITESEQUENCE' int createdUserId Integer.parseInt (dbHelper.executeSQLQuery (query). I also alias the column name last_insert_rowid() to "ID", and that was done since you can't get columns by their index (say 0), but have to use name. You can use the function lastinsertrowid (): The lastinsertrowid () function returns the ROWID of the last row insert from the database connection which invoked the function. Possible Duplicate: Get generated id after insert. So in my first "main" routine/activity - I have a global database object "sqlite". If you don't have that global database object/handle, then you could I suppose modify the above to include/pass the database object sqlite in above. If you are trying to insert/update a player whose ID already exists, the SQLite engine will delete that row and insert the. In other words, you dont have foreign key, or if you have them, your SQLite engine is configured so that there no are integrity exceptions. Now, I adopt a standard in my main module that the database object is "sqlite". Option 1: You can afford deleting the row.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |