Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use Pervasive to give me incrementng serial numbers?

Status
Not open for further replies.

pederalm

Programmer
Jul 5, 2006
6
SE
I want to build a software in Delphi and use the Pervasive database to give me unique incrementing serial numbers. Is it possible to use Pervasive 8 in this way?

A solution is to get the number in row one, number++ and then update the field in the table. This needs exclusive access to the table (how to do that?). But I would like a automated function/solution if there is one available.
 
Yes. PSQL offers an autoincrement / identity field. It supports both a 2 byte and a 4 byte size for that field.
You cannot seed the field and have it start at the seed value. It'll start at 1. The 2 byte field supports a range of 1 to 32767 and the 4 byte field supports 1 to 2,147,483,647.

Exclusive access depends on the access method you are using (Btrieve vs Relational).

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Actually, you can seed the table. Normally, when inserting a row with an identity column, you specify the identity value as 0 and the next highest value will be automatically assigned and inserted. However, you can specify a non-zero value during the insert and it will be used (as long as it doesn't already exist). So, if you insert an inital row with a specific identity value, all subsequent inserts done with a value of 0 will increment from the highest value currently in the table.

In other words,

create table seedtest (id identity, name char(20));
insert into seedtest values(10000, 'Linda');
insert into seedtest values(0, 'Mirtheil');

This will result in two rows with id values of 10000 and 10001.

Linda
Pervasive Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top