根据sqlite3 documentation,创建一个主键为升序整数的表会导致主键成为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
则无效。
怎么了?