Skip to content

Commit

Permalink
Clear description cache between statements
Browse files Browse the repository at this point in the history
Fixes #186
  • Loading branch information
rogerbinns committed Apr 16, 2015
1 parent 1952380 commit 5f7586e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Change History
3.8.9-r1
========

Fixed column description caching which could be preserved between
multiple statements in the same execution (:issue:`186`)

Updated documentation building tool to use new database of information
from the SQLite site. This is simpler and more reliable. (Previously
used site scraping.)
Expand Down
3 changes: 3 additions & 0 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ APSWCursor_step(APSWCursor *self)

assert(!PyErr_Occurred());

Py_CLEAR(self->description_cache[0]);
Py_CLEAR(self->description_cache[1]);

if(APSWCursor_dobindings(self))
{
assert(PyErr_Occurred());
Expand Down
38 changes: 38 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,44 @@ def testIssue142(self):
time.strftim=orig_strftime
getpass.getuser=orig_getuser

def testIssue186(self):
"Issue 186: desription cache between statements"
cur=self.db.cursor()

for i, row in enumerate(cur.execute("select 1; select 1,2; select 1,2,3; select 1,2,3,4;")):
# this catches if the order of getting them makes a difference
if i%2:
self.assertEqual(len(cur.description), len(cur.getdescription()))
else:
self.assertEqual(len(cur.getdescription()), len(cur.description))
self.assertEqual(len(cur.description), i+1)

# check executemany too
for i, row in enumerate(cur.executemany("select ?; select ?,?; select ?,?,?; select ?,?,?,?;",
[(1, 1,2, 1,2,3, 1,2,3,4),
(1, 1,2, 1,2,3, 1,2,3,4),
])):
i%=4
self.assertEqual(len(cur.getdescription()), i+1)

# and the tracers
def tracer(cursor, *args):
self.assertEqual(len(cursor.getdescription()), expect)
return True
expect=1
cur.setexectrace(tracer)
cur.setrowtrace(tracer)
for i, row in enumerate(cur.execute("select 1; select 1,2; select 1,2,3; select 1,2,3,4;")):
expect+=1
expect=1
for i, row in enumerate(cur.executemany("select ?; select ?,?; select ?,?,?; select ?,?,?,?;",
[(1, 1,2, 1,2,3, 1,2,3,4),
(1, 1,2, 1,2,3, 1,2,3,4),
])):
expect+=1
if expect>4: expect=1


def testTicket2158(self):
"Check we are not affected by SQLite ticket #2158"
# https://sqlite.org/cvstrac/tktview?tn=2158
Expand Down

0 comments on commit 5f7586e

Please sign in to comment.