[EMAIL PROTECTED] wrote:

chetana bhargav <[EMAIL PROTECTED]> writes:

Auto increment seems to return a unsigned long long is there any way for it
to make it as 32 bit, as I am depending on this feilds to generate unique
id, and i have a constraint fot the id to be 32 bit only.

You'll have to add enough rows to the table to use up all id values that fit
in 32 bits before you'll have a problem.  You can, however, protect from wrap-
around with something like this:

CREATE TABLE x(i INTEGER PRIMARY KEY AUTOINCREMENT);

CREATE TRIGGER x_insert_tr
 AFTER INSERT
 ON x
 FOR EACH ROW
 BEGIN
   SELECT CASE
     WHEN new.i >= (1<<32) THEN RAISE(ROLLBACK, 'The table is full.')
     ELSE NULL
   END;
 END;

Derrell

Derrell,

If you are using SQLite 3.3.0 or newer then you can do the same thing in a more direct manner using a CHECK constraint.

CREATE TABLE x(i INTEGER PRIMARY KEY AUTOINCREMENT CHECK(i < (1<<32)));

Also, if you are concerned about signed vs unsigned interpretation of the 32 bit value you may want to change the maximum to a 31 bit shift which will restrict i to values that are always positive signed values.

HTH
Dennis Cote


Reply via email to