diff options
author | Carl Friedrich Bolz-Tereick <cfbolz@gmx.de> | 2022-11-16 20:40:44 +0100 |
---|---|---|
committer | Carl Friedrich Bolz-Tereick <cfbolz@gmx.de> | 2022-11-16 20:40:44 +0100 |
commit | c1bd957c6263d4cab138416bfdbe64350fed94ae (patch) | |
tree | 1e0938731de921b3f4613b08f300dbc5d1bdcb47 | |
parent | argh, fix silly wrong indentation problem (diff) | |
download | pypy-c1bd957c6263d4cab138416bfdbe64350fed94ae.tar.gz pypy-c1bd957c6263d4cab138416bfdbe64350fed94ae.tar.bz2 pypy-c1bd957c6263d4cab138416bfdbe64350fed94ae.zip |
check for recursive Cursor.__init__ calls
-rw-r--r-- | extra_tests/test_sqlite3.py | 16 | ||||
-rw-r--r-- | lib_pypy/_sqlite3.py | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/extra_tests/test_sqlite3.py b/extra_tests/test_sqlite3.py index 80eff86c4f..04686f4fee 100644 --- a/extra_tests/test_sqlite3.py +++ b/extra_tests/test_sqlite3.py @@ -515,3 +515,19 @@ def test_recursive_fetch(): finally: del _sqlite3.converters['ITER'] +def test_recursive_init(): + conn = _sqlite3.connect(":memory:", detect_types=_sqlite3.PARSE_COLNAMES) + cursor = conn.cursor() + cursor.execute("create table test(x foo)") + cursor.executemany("insert into test(x) values (?)", + [("foo",), ("bar",)]) + def conv(x): + cursor.__init__(conn) + return x + try: + _sqlite3.converters['INIT'] = conv + with pytest.raises(_sqlite3.ProgrammingError): + cursor.execute(f'select x as "x [INIT]", x from test') + finally: + del _sqlite3.converters['INIT'] + diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py index 1d31ff80df..8fb44368fd 100644 --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -778,8 +778,11 @@ class Connection(object): class Cursor(object): __initialized = False __statement = None + __locked = False def __init__(self, con): + if self.__locked: + raise ProgrammingError("Recursive use of cursors not allowed.") if not isinstance(con, Connection): raise TypeError self.__connection = con |