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