diff options
author | Gerhard Haering <gh@ghaering.de> | 2011-05-09 10:24:09 (GMT) |
---|---|---|
committer | Gerhard Haering <gh@ghaering.de> | 2011-05-09 10:24:09 (GMT) |
commit | 936d518dc8fb8fb094de1391d5a0703287db694e (patch) | |
tree | 6ff3f3c2c7ca891b3b66e80494cfb463e04d811b /Lib/sqlite3 | |
parent | 83b8c0be93799b907b22d1db62695da57514496a (diff) | |
download | cpython-936d518dc8fb8fb094de1391d5a0703287db694e.zip cpython-936d518dc8fb8fb094de1391d5a0703287db694e.tar.gz cpython-936d518dc8fb8fb094de1391d5a0703287db694e.tar.bz2 |
#10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/test/regression.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 7d0553d..f80b269 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -281,6 +281,29 @@ class RegressionTests(unittest.TestCase): # Lone surrogate cannot be encoded to the default encoding (utf8) "\uDC80", collation_cb) + def CheckRecursiveCursorUse(self): + """ + http://bugs.python.org/issue10811 + + Recursively using a cursor, such as when reusing it from a generator led to segfaults. + Now we catch recursive cursor usage and raise a ProgrammingError. + """ + con = sqlite.connect(":memory:") + + cur = con.cursor() + cur.execute("create table a (bar)") + cur.execute("create table b (baz)") + + def foo(): + cur.execute("insert into a (bar) values (?)", (1,)) + yield 1 + + try: + cur.executemany("insert into b (baz) values (?)", ((i,) for i in foo())) + self.fail("should have raised ProgrammingError") + except sqlite.ProgrammingError: + pass + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") return unittest.TestSuite((regression_suite,)) |