我有一个我在sqlite3模块周围编写的包装器,它允许我从多个线程序列化访问。它还允许我在更改其定义时自动迁移表。我注意到当我删除一个表并重新添加更多列时,我得到索引超出范围错误。像这样:
conn = sqlite3.connect("test.db", detect_types=sqlite3.PARSE_COLNAMES)
curs = conn.cursor()
curs.execute("CREATE TABLE test (derp TEXT);"); conn.commit()
curs.execute("INSERT INTO test (derp) VALUES ('deedle');"); conn.commit()
print curs.execute("SELECT * FROM test;").fetchall()
curs.execute("DROP TABLE test;"); conn.commit()
curs.execute("CREATE TABLE test (derp TEXT, val REAL);"); conn.commit()
curs.execute("INSERT INTO test (derp) VALUES ('deedle');"); conn.commit()
print curs.execute("SELECT * FROM test;").fetchall()
conn.close()
将打印出来:
[(u'deedle',)] Traceback (most recent
call last): File "test.py", line 23,
in <module>
print curs.execute("SELECT * FROM test;").fetchall() IndexError: list
index out of range
执行第二个SELECT语句时。有谁知道这是为什么?
答案 0 :(得分:1)
嗯,它对我来说很好
[(u'deedle',)]
[(u'deedle', None)]