|
Re: Emulating a sequence: msg#00015python.db.pysqlite.user
David Pratt wrote: > I was thinking about faking a sequence. My first thought was to > create a sequence table with a single row where a field is a sequence > value and you just increment the value and retreive it as anything else. > It's simple but particulary good. No comment as such on the sequence class (never tried it myself). I just wanted to make sure you did know about sqlite's automatic autoincrement value. I know it's not the same as a sequence, but in case you were simply trying to achieve the same effect... If you create a column which is INTEGER NOT NULL PRIMARY KEY then sqlite will automatically auto-increment if you insert NULL (or don't insert): <sqlite prompt code> CREATE TABLE x ( id INTEGER NOT NULL PRIMARY KEY, code VARCHAR (10), name VARCHAR (60) ) ; INSERT INTO x (code, name) VALUES ('BLAH', 'Blah'); INSERT INTO x (code, name) VALUES ('BLAH-2', 'Blah2'); SELECT * FROM x; </code> will result in: 1|BLAH|Blah 2|BLAH-2|Blah2 Just so you know. TJG |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Getting the time during a transaction: 00015, Tim Golden |
|---|---|
| Next by Date: | Re: Getting the time during a transaction: 00015, David Pratt |
| Previous by Thread: | Emulating a sequencei: 00015, David Pratt |
| Next by Thread: | Re: Emulating a sequence: 00015, David Pratt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |