表删除/添加后 Python sqlite 索引超出范围错误?

标签 python sqlite python-2.5

我有一个围绕 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 语句时。有谁知道这是为什么吗?

最佳答案

嗯,对我来说很好用 [(你'deedle',)] [(u'deedle', None)]

关于表删除/添加后 Python sqlite 索引超出范围错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969399/

相关文章:

ios - 将 sqlite3_exec 回调函数的结果保存到 Swift 中的字典中

python - 如何在 Python 中找到与正则表达式的所有匹配项?

python - 动态定义sympy.abc变量: name error handling

python - 如何在 virtualenv 中升级 python 2.7.3 中的 sqlite3?

python - 浮点值等于-1.#IND

python - 在 Windows 上使用 Python 2.5 的 Nan

python - 如何等待 20 秒让用户按下任意键?

python - 检查字符串是否包含 Python 数组中的多个元素

python - 没有排序结果的 Pandas 值计数

android - 在 SQLite 和 ListView 之间格式化数据