Page 1 of 1 |
spankie
VIP Member
Posts: 2958
Location: Belgium
|
Posted: Wed, 8th Apr 2009 22:35 Post subject: vbscript database problem |
|
 |
hi, i made a website that allows you to send data to a db and sends an email to another person that allows the other user to see the data.
I hava a db that has an auto increment column as id and other columns. When you submit something to the db, the auto incrementer goes up.
Afterwards the data can be extracted from the db by using the id.
Now i have a problem. I need a solid strategy to know what the id is that gets auto created when the data goes to the db, so i can send it in the email.
Is there a function to extract it while submitting to the db or is there another solid strategy to get the id?
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73194
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Wed, 8th Apr 2009 22:44 Post subject: |
|
 |
You could just query for the last (with max function) id in that table and sending that. This is the workaround I used in a project. 
|
|
Back to top |
|
 |
Rinze
Site Admin
Posts: 2343
|
Posted: Wed, 8th Apr 2009 23:30 Post subject: |
|
 |
Using the max function sets you up for race conditions.
There isn't a standard for this, MSSQL has SCOPE_IDENTITY(), MySQL has a C interface, Access has @@IDENTITY
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73194
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Wed, 8th Apr 2009 23:36 Post subject: |
|
 |
Wouldn't accessing these also potentially introduce race condition problems (not sure exactly what they are, but have a good idea)? Why not just send the data that was sent to the DB, to the other page which sends the data by mail?
|
|
Back to top |
|
 |
spankie
VIP Member
Posts: 2958
Location: Belgium
|
Posted: Wed, 8th Apr 2009 23:51 Post subject: |
|
 |
i found a solution finally.
There appears to be a "requery function" to extract autoincrement values on insertion... i knew someone had experienced the samen problem before...
|
|
Back to top |
|
 |
Rinze
Site Admin
Posts: 2343
|
Posted: Thu, 9th Apr 2009 04:16 Post subject: |
|
 |
No, there are no problems there, they are specifically intended to return the last autoincrement for the current session.
The race condition is when two threads put something into the database at the same time. By the time they query the max value they might both get the same number.
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73194
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Thu, 9th Apr 2009 04:34 Post subject: |
|
 |
Yes I know what race condition is, had my fair share of such problems with threads. Just wasn't sure what the things you mentioned were. Thanks!
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |