2010-11-20 21 views
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もしこれが動作します。

どういうところが間違っていますか?

答えて

1

http://www.sqlite.org/autoinc.html

私はあなたの作成・表中の「ASC」ディレクティブに慣れていないです。

+0

http://www.sqlite.org/lang_createtable.html#rowidを参照してください。 – vy32

関連する問題