Re: [sqlite] Problem with inserting and integer primary key
On Wed, 15 Oct 2008 12:43:00 -0400, "Igor Tandetnik" <[EMAIL PROTECTED]> wrote: >Be aware that, in order to create a column that aliases ROWID (and thus >has special properties in SQLite, such as getting an automatically >assigned unique integer) it has to be spelled precisely INTEGER PRIMARY >KEY. Note that INT PRIMARY KEY is not sufficient, which may be useful. JAB -- John A. Belli Software Engineer Refrigerated Transport Electronics, Inc. http://www.rtelectronics.com ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Problem with inserting and integer primary key
Karl Lautman <[EMAIL PROTECTED]> wrote: > So, I create a table as follows: > > CREATE TABLE IF NOT EXISTS Lists ( > wID integer, > ltitle text, > llink text, > units text, > date text, > ListsID integer, > new integer > , CONSTRAINT Lists_pk PRIMARY KEY (ListsID)) Be aware that, in order to create a column that aliases ROWID (and thus has special properties in SQLite, such as getting an automatically assigned unique integer) it has to be spelled precisely INTEGER PRIMARY KEY. Doing it the way you show, with a CONSTRAINT clause, won't do the trick. Make it CREATE TABLE IF NOT EXISTS Lists ( wID integer, ltitle text, llink text, units text, date text, ListsID integer primary key, new integer); Scott Baker already addressed the rest of your problem. Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Problem with inserting and integer primary key
On 10/15/2008 09:27 AM, Karl Lautman wrote: > To insert data I do (this is in Python): > > > > x = dcur.execute('insert into Lists values (?, ?, ?, ?, ?, ?)', (123, > 'YouTube Videos','http://www.youtube.com', 'views', '10/14/08', 4)) Just add NULL for the primary key value. SQLite will autopopulate the number, but you have to tell it to do it. Just because it's a primary key doesn't mean you can't ALSO provide it a value (like 73). So you have to tell it to pick one itself by using NULL. -- Scott Baker - Canby Telcom RHCE - System Administrator - 503.266.8253 ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Problem with inserting and integer primary key
So, I create a table as follows: CREATE TABLE IF NOT EXISTS Lists ( wID integer, ltitle text, llink text, units text, date text, ListsID integer, new integer , CONSTRAINT Lists_pk PRIMARY KEY (ListsID)) To insert data I do (this is in Python): x = dcur.execute('insert into Lists values (?, ?, ?, ?, ?, ?)', (123, 'YouTube Videos', 'http://www.youtube.com', 'views', '10/14/08', 4)) And I get: OperationalError: table Lists has 7 columns but 6 values were supplied I only supplied 6 values because, according to the sqlite documentation: "If a table contains a column of type INTEGER PRIMARY KEY, then that column becomes an alias for the ROWID. You can then access the ROWID using any of four different names, the original three names described above or the name given to the INTEGER PRIMARY KEY column. All these names are aliases for one another and work equally well in any context. "When a new row is inserted into an SQLite table, the ROWID can either be specified as part of the INSERT statement or it can be assigned automatically by the database engine." So, if I want the engine to automatically assign the ROWID, do I have to specify the PK column or not? If the former, how do I get the table to automatically assign the ROWID? Thanks. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users