Skip to content

Commit

Permalink
Closes: #104
Browse files Browse the repository at this point in the history
Set cursor.description to None instead of emtpy tuple if no description
is available for rows.
  • Loading branch information
ghaering committed Aug 30, 2016
1 parent 6d95c1b commit e52b173
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 14 additions & 1 deletion lib/test/regression.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-*- coding: ISO-8859-1 -*-
# pysqlite2/test/regression.py: pysqlite regression tests
#
# Copyright (C) 2006-2015 Gerhard Häring <gh@ghaering.de>
# Copyright (C) 2006-2015 Gerhard H�ring <gh@ghaering.de>
#
# This file is part of pysqlite.
#
Expand Down Expand Up @@ -332,6 +332,19 @@ def CheckNullCharacter(self):
self.assertRaises(ValueError, cur.execute, " \0select 2")
self.assertRaises(ValueError, cur.execute, "select 2\0")

def CheckNonSelectCursorDescription(self):
# https://github.com/ghaering/pysqlite/issues/104
con = sqlite.connect(":memory:")
cur = con.cursor()
cur.execute("create table test as select 1 foo")
self.assertEqual(cur.description, None)
cur.execute("delete from test")
self.assertEqual(cur.description, None)
cur.execute("insert into test values (1)")
self.assertEqual(cur.description, None)
cur.execute("update test set foo=2")
self.assertEqual(cur.description, None)

def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check")
return unittest.TestSuite((regression_suite,))
Expand Down
6 changes: 2 additions & 4 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,9 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
}

if (rc == SQLITE_ROW || rc == SQLITE_DONE) {
if (self->description == Py_None) {
Py_BEGIN_ALLOW_THREADS
numcols = sqlite3_column_count(self->statement->st);
Py_END_ALLOW_THREADS
numcols = sqlite3_column_count(self->statement->st);

if (self->description == Py_None && numcols > 0) {
Py_DECREF(self->description);
self->description = PyTuple_New(numcols);
if (!self->description) {
Expand Down

0 comments on commit e52b173

Please sign in to comment.