Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 6th, 2004, 10:53 AM
DoctorC DoctorC is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 DoctorC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Multi user environment and record ID

Hi,
I'm writing a delphi app connected to Firebird. I need to add in a multi user environment a new record with a random ID (but unique in the DB).
So the steps I should follow are:
1) generate the random ID
2) check if the ID exists
3) if not then add the record, else back to 1
I'm concerned about the time between ID checking and record adding. What if in that interval another user adds a record with the same ID.
What is the best way to solve it with SQL?
How can I "lock" a random ID?
Thanks
Enrico

Reply With Quote
  #2  
Old December 7th, 2004, 03:22 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
First of all you could use a generator for the ID (but that wouldn't be random) ... to solve your problem you need to create an unique INDEX on the ID, so that when the user tries to commit the transaction if the ID already exists, he receives an error.

Good luck,
Silver

Reply With Quote
  #3  
Old December 7th, 2004, 08:00 AM
hugo2 hugo2 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 20 hugo2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by DoctorC
Hi,
I'm writing a delphi app connected to Firebird. I need to add in a multi user environment a new record with a random ID (but unique in the DB).

Why do you need (why do you think you need) random IDs ? Can't you just use the standard method to obtain unique IDs, i.e. generators ?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Multi user environment and record ID


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway