Hi Experts,
I want to save the data of a record to the database (which has many rows). I will need to do this in a transaction. I want to get what the next ID should be (without using auto-incrementing rows). So I want some way of locking the table so that I can do the following:
- Lock the table
- Get the next logical ID I should use
- insert my rows
- unlock the table
Is there a way to do this without using database-specific calls?
I could do something like this:
while(true) {
while (lock table does not exist) {
create lock table
query other table for max ID
insert using MaxID + 1
delete lock table
return
}
sleep (2000)
}
>>Is there a way to do this without using database-specific calls?
If you can guarantee that no other process will be accessing the DB during such an operation - yes. If not, I cannot imagine any way that is not specific to the DB. However, if you can use ODBC (http://en.wikipedia.org/wiki/Open_Database_Connectivity), you can reduce the 'specificness' of that.
0
Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
select @@scopeidenty
it will return the current id