Quantcast

bounded id

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bounded id

Jan Danielsson
Hello,

   I have a wire-protocol which uses an uint32_t to identify transfers,
and each of the transfers is represented by a row in a table in an
sqlite database.

   I can't make the rowid a uint32_t, but that's essentially the
behavior I'm looking for -- I'd like to be able to insert a new row into
the table, then ask for the last inserted row id and use that identifier
in the wire-protocol.  Are there any good options to accomplish this
[limit the auto-assigned identifier]?

   The obvious solution is to record-keep identifiers outside of the
database, but the sqlite database is responsible for assigning other
other identifiers; it would be nice not to break that abstraction if
possible.

--
Kind regards,
Jan Danielsson

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bounded id

Clemens Ladisch
Jan Danielsson wrote:
> I can't make the rowid a uint32_t, but that's essentially the
> behavior I'm looking for

CREATE TABLE transfers (
    ID  INTEGER PRIMARY KEY  CHECK (ID BETWEEN 0 AND 4294967295),
    [...]
);

But if you want the values to wrap around after old ones have been
deleted, you have to implement it yourself.  (A random search is
efficient as long as the set of actually used IDs is sparse.)


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...