dbTalk Databases Forums  

Sequence Record

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Sequence Record in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
shirley.cohen@gmail.com
 
Posts: n/a

Default Sequence Record - 03-29-2006 , 08:50 PM






Hi,

Can anyone please tell me what a Sequence Record is and how it is used?


Thanks,

Shirley


Reply With Quote
  #2  
Old   
Joseph Bruni
 
Posts: n/a

Default Re: Sequence Record - 03-29-2006 , 11:33 PM








shirley.cohen (AT) gmail (DOT) com wrote:
Quote:

Hi,

Can anyone please tell me what a Sequence Record is and how it is used?


Thanks,

Shirley

A sequence is simply an integer that is guaranteed to be unique among
competing concurrent tasks. Typically, they are used as primary keys in a
database. If you have multiple threads inserting records into a
database, and you need the key to be unique, a sequence is the best way to do
it.
You could do your own sequence by inserting a single record into a
database with the value being your integer. Then, when you need the next
value, you would lock the record, read it remembering the value somewhere,
increment it, write the new value into the same record, and then unlock
it, so that other processes could do the same. You could then use that
value as a key to insert your new data into your primary database.
In DB, they've done all that work for you. You create a sequence object
that is tied to a record in a database. You can set up your sequence
with an initial value as well as an increment amount (say you want to
increment by 5 instead of 1). You can also set a maximum value and whether
you want the sequence to wrap when you hit the maximum or just throw an
error.
SleepyCat has provided some sample code in ex_sequence.c.

-Joe
--




Reply With Quote
  #3  
Old   
shirley.cohen@gmail.com
 
Posts: n/a

Default Re: Sequence Record - 03-30-2006 , 06:50 PM



Thanks! This is very useful.

Shirley

Joseph Bruni wrote:
Quote:
shirley.cohen (AT) gmail (DOT) com wrote:


Hi,

Can anyone please tell me what a Sequence Record is and how it is used?


Thanks,

Shirley


A sequence is simply an integer that is guaranteed to be unique among
competing concurrent tasks. Typically, they are used as primary keys in a
database. If you have multiple threads inserting records into a
database, and you need the key to be unique, a sequence is the best way to do
it.
You could do your own sequence by inserting a single record into a
database with the value being your integer. Then, when you need the next
value, you would lock the record, read it remembering the value somewhere,
increment it, write the new value into the same record, and then unlock
it, so that other processes could do the same. You could then use that
value as a key to insert your new data into your primary database.
In DB, they've done all that work for you. You create a sequence object
that is tied to a record in a database. You can set up your sequence
with an initial value as well as an increment amount (say you want to
increment by 5 instead of 1). You can also set a maximum value and whether
you want the sequence to wrap when you hit the maximum or just throw an
error.
SleepyCat has provided some sample code in ex_sequence.c.

-Joe
--


Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.