| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -274,6 +274,45 @@ def CheckCursorDescriptionNoRow(self): | |||
| 274 | 274 | self.cur.execute("select * from test where 0 = 1") | |
| 275 | 275 | self.assertEqual(self.cur.description[0][0], "x") | |
| 276 | 276 | ||
| 277 | + def CheckCursorDescriptionInsert(self): | ||
| 278 | + self.cur.execute("insert into test values (1)") | ||
| 279 | + self.assertIsNone(self.cur.description) | ||
| 280 | + | ||
| 281 | + | ||
| 282 | + @unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "CTEs not supported") | ||
| 283 | + class CommonTableExpressionTests(unittest.TestCase): | ||
| 284 | + | ||
| 285 | + def setUp(self): | ||
| 286 | + self.con = sqlite.connect(":memory:") | ||
| 287 | + self.cur = self.con.cursor() | ||
| 288 | + self.cur.execute("create table test(x foo)") | ||
| 289 | + | ||
| 290 | + def tearDown(self): | ||
| 291 | + self.cur.close() | ||
| 292 | + self.con.close() | ||
| 293 | + | ||
| 294 | + def CheckCursorDescriptionCTESimple(self): | ||
| 295 | + self.cur.execute("with one as (select 1) select * from one") | ||
| 296 | + self.assertIsNotNone(self.cur.description) | ||
| 297 | + self.assertEqual(self.cur.description[0][0], "1") | ||
| 298 | + | ||
| 299 | + def CheckCursorDescriptionCTESMultipleColumns(self): | ||
| 300 | + self.cur.execute("insert into test values(1)") | ||
| 301 | + self.cur.execute("insert into test values(2)") | ||
| 302 | + self.cur.execute("with testCTE as (select * from test) select * from testCTE") | ||
| 303 | + self.assertIsNotNone(self.cur.description) | ||
| 304 | + self.assertEqual(self.cur.description[0][0], "x") | ||
| 305 | + | ||
| 306 | + def CheckCursorDescriptionCTE(self): | ||
| 307 | + self.cur.execute("insert into test values (1)") | ||
| 308 | + self.cur.execute("with bar as (select * from test) select * from test where x = 1") | ||
| 309 | + self.assertIsNotNone(self.cur.description) | ||
| 310 | + self.assertEqual(self.cur.description[0][0], "x") | ||
| 311 | + self.cur.execute("with bar as (select * from test) select * from test where x = 2") | ||
| 312 | + self.assertIsNotNone(self.cur.description) | ||
| 313 | + self.assertEqual(self.cur.description[0][0], "x") | ||
| 314 | + | ||
| 315 | + | ||
| 277 | 316 | class ObjectAdaptationTests(unittest.TestCase): | |
| 278 | 317 | def cast(obj): | |
| 279 | 318 | return float(obj) | |
@@ -372,7 +411,8 @@ def suite(): | |||
| 372 | 411 | adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check") | |
| 373 | 412 | bin_suite = unittest.makeSuite(BinaryConverterTests, "Check") | |
| 374 | 413 | date_suite = unittest.makeSuite(DateTimeTests, "Check") | |
| 375 | - return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite)) | ||
| 414 | + cte_suite = unittest.makeSuite(CommonTableExpressionTests, "Check") | ||
| 415 | + return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite, cte_suite)) | ||
| 376 | 416 | ||
| 377 | 417 | def test(): | |
| 378 | 418 | runner = unittest.TextTestRunner() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,8 @@ Core and Builtins | |||
| 36 | 36 | Library | |
| 37 | 37 | ------- | |
| 38 | 38 | ||
| 39 | + - Issue #21718: cursor.description is now available for queries using CTEs. | ||
| 40 | + | ||
| 39 | 41 | - Issue #27819: In distutils sdists, simply produce the "gztar" (gzipped tar | |
| 40 | 42 | format) distributions on all platforms unless "formats" is supplied. | |
| 41 | 43 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -645,12 +645,11 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* | |||
| 645 | 645 | goto error; | |
| 646 | 646 | } | |
| 647 | 647 | ||
| 648 | - if (rc == SQLITE_ROW || (rc == SQLITE_DONE && statement_type == STATEMENT_SELECT)) { | ||
| 649 | - if (self->description == Py_None) { | ||
| 650 | - Py_BEGIN_ALLOW_THREADS | ||
| 651 | - numcols = sqlite3_column_count(self->statement->st); | ||
| 652 | - Py_END_ALLOW_THREADS | ||
| 653 | - | ||
| 648 | + if (rc == SQLITE_ROW || rc == SQLITE_DONE) { | ||
| 649 | + Py_BEGIN_ALLOW_THREADS | ||
| 650 | + numcols = sqlite3_column_count(self->statement->st); | ||
| 651 | + Py_END_ALLOW_THREADS | ||
| 652 | + if (self->description == Py_None && numcols > 0) { | ||
| 654 | 653 | Py_SETREF(self->description, PyTuple_New(numcols)); | |
| 655 | 654 | if (!self->description) { | |
| 656 | 655 | goto error; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments