lundi 4 mai 2015

PRAGMA table_info messes up result set

I have this script:

#!/usr/bin/env python3

import sqlite3

conn = sqlite3.connect('sample.dbf')
try:
    conn.execute('''DROP TABLE mytable''')
except:
    pass

conn.execute('''CREATE TABLE mytable (parentId TEXT, childId TEXT)''')
conn.execute('''INSERT INTO mytable VALUES('A', 'B')''')
conn.execute('''INSERT INTO mytable VALUES('C', 'D')''')

c1 = conn.cursor()
c1.execute('''SELECT * FROM mytable''')

#c2 = conn.cursor()
#c2.execute('''PRAGMA table_info(mytable)''')

for row in c1:
    print(row)

The output is as expected:

('A', 'B')
('C', 'D')

However, if I re-add the two commented lines to read the table information before iterating the result set from the first cursor, I get

('A', 'B')
('A', 'B')
('C', 'D')

Should the cursors not be independent? Why does the PRAGMA table_info statement mess up the result set from the first query? Looks like a bug in sqlite to me, but maybe I also missed something ...

Version is sqlite3 2.6.0 with SQLite runtime 3.8.3.1 on Python 3.4.2

Aucun commentaire:

Enregistrer un commentaire