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