From 6afe85827c209b9d1e76a65ffdb7420b5f46ad3d Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 21 Aug 2016 19:38:47 +0300 Subject: Issue #21718: cursor.description is now available for queries using CTEs According to PEP 249, cursor.description must be available for any SELECT statements, such as those that use CTEs. Backported from https://github.com/ghaering/pysqlite/commit/f67fa9c898a4713850e16934046f0fe2cba8c44c Additional test cases added by me. --- Modules/_sqlite/cursor.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Modules/_sqlite/cursor.c') diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 300da2878e..e1676de907 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -646,12 +646,11 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* goto error; } - if (rc == SQLITE_ROW || (rc == SQLITE_DONE && statement_type == STATEMENT_SELECT)) { - if (self->description == Py_None) { - Py_BEGIN_ALLOW_THREADS - numcols = sqlite3_column_count(self->statement->st); - Py_END_ALLOW_THREADS - + if (rc == SQLITE_ROW || rc == SQLITE_DONE) { + Py_BEGIN_ALLOW_THREADS + numcols = sqlite3_column_count(self->statement->st); + Py_END_ALLOW_THREADS + if (self->description == Py_None && numcols > 0) { Py_SETREF(self->description, PyTuple_New(numcols)); if (!self->description) { goto error; -- cgit v1.2.1