summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-08-21 16:38:47 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-08-21 16:38:47 (GMT)
commit6afe85827c209b9d1e76a65ffdb7420b5f46ad3d (patch)
tree22bc20a3337f66da96a7b90009c3b82fd5b9499a /Lib/sqlite3
parent8682f578c1c8fd0486c886b001729907a5409a9f (diff)
downloadcpython-6afe85827c209b9d1e76a65ffdb7420b5f46ad3d.zip
cpython-6afe85827c209b9d1e76a65ffdb7420b5f46ad3d.tar.gz
cpython-6afe85827c209b9d1e76a65ffdb7420b5f46ad3d.tar.bz2
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.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/test/types.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py
index 6667bc8..0b5b3e7 100644
--- a/Lib/sqlite3/test/types.py
+++ b/Lib/sqlite3/test/types.py
@@ -274,6 +274,45 @@ class ColNamesTests(unittest.TestCase):
self.cur.execute("select * from test where 0 = 1")
self.assertEqual(self.cur.description[0][0], "x")
+ def CheckCursorDescriptionInsert(self):
+ self.cur.execute("insert into test values (1)")
+ self.assertIsNone(self.cur.description)
+
+
+@unittest.skipIf(sqlite.sqlite_version_info < (3, 8, 3), "CTEs not supported")
+class CommonTableExpressionTests(unittest.TestCase):
+
+ def setUp(self):
+ self.con = sqlite.connect(":memory:")
+ self.cur = self.con.cursor()
+ self.cur.execute("create table test(x foo)")
+
+ def tearDown(self):
+ self.cur.close()
+ self.con.close()
+
+ def CheckCursorDescriptionCTESimple(self):
+ self.cur.execute("with one as (select 1) select * from one")
+ self.assertIsNotNone(self.cur.description)
+ self.assertEqual(self.cur.description[0][0], "1")
+
+ def CheckCursorDescriptionCTESMultipleColumns(self):
+ self.cur.execute("insert into test values(1)")
+ self.cur.execute("insert into test values(2)")
+ self.cur.execute("with testCTE as (select * from test) select * from testCTE")
+ self.assertIsNotNone(self.cur.description)
+ self.assertEqual(self.cur.description[0][0], "x")
+
+ def CheckCursorDescriptionCTE(self):
+ self.cur.execute("insert into test values (1)")
+ self.cur.execute("with bar as (select * from test) select * from test where x = 1")
+ self.assertIsNotNone(self.cur.description)
+ self.assertEqual(self.cur.description[0][0], "x")
+ self.cur.execute("with bar as (select * from test) select * from test where x = 2")
+ self.assertIsNotNone(self.cur.description)
+ self.assertEqual(self.cur.description[0][0], "x")
+
+
class ObjectAdaptationTests(unittest.TestCase):
def cast(obj):
return float(obj)
@@ -372,7 +411,8 @@ def suite():
adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check")
bin_suite = unittest.makeSuite(BinaryConverterTests, "Check")
date_suite = unittest.makeSuite(DateTimeTests, "Check")
- return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite))
+ cte_suite = unittest.makeSuite(CommonTableExpressionTests, "Check")
+ return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite, cte_suite))
def test():
runner = unittest.TextTestRunner()