0
根据sqlite3 documentation,创建一个表,其中主键是一个升序整数,导致主键是rowID的别名。这不是为我发生的。sqlite3 rowid别名未正确创建
这里是我创建代码:
import sqlite3
con = sqlite3.connect("/tmp/emaildb.sqlite3")
c = con.cursor()
try:
c.execute("create table drives (driveid integer primary key asc, drivename text unique);")
con.commit()
except sqlite3.OperationalError:
pass
这里是我的检查代码:
try:
c.execute("insert into drives (drivename) values (?)",(drivename,))
print "new ID=",c.lastrowid
except sqlite3.IntegrityError:
c.execute("select rowid from drives where drivename=?",(drivename,))
driveid = c.fetchone()[0]
print "old ID=",driveid
这工作,如果我select rowid
但如果我select driveid
。
怎么了?
请参阅http://www.sqlite.org/lang_createtable.html#rowid – vy32 2010-11-20 22:26:41