2

I've got a wrapper I wrote around the sqlite3 module that lets me serialize access from multiple threads. It also lets me automatically migrate tables when I change their definition. I noticed when I drop a table and re-add it with more columns, I get an index out of range error. Something like this:

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()

Will print this:

[(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

When executing the second SELECT statement. Does anyone know why this is?

1
  • 2
    I can not reproduce your problem, I am getting: >>> print curs.execute("SELECT * FROM test;").fetchall() [(u'deedle', None)] Commented May 11, 2011 at 19:19

1 Answer 1

1

Well, it works just fine for me [(u'deedle',)] [(u'deedle', None)]

Sign up to request clarification or add additional context in comments.

3 Comments

What's your sqlite3.version and sqlite3.sqlite_version say? Mine's 2.3.2 and 3.3.6, respectively.
2.6.0 and 3.7.5, running with python 2.7 You should try and upgrade, as this might be a fixed bug. Latest version is 3.7.6.2
Ah OK, I'm running python 2.5, so that may be the problem. I'll see what I can do about upgrading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.