diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-04-26 21:57:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 19:57:48 +0000 |
commit | bb8aa7a2b41ad7649d66909e5266fcee039e63ed (patch) | |
tree | 69b936d96b77a82a34968934abdb97632efa455c /Lib/test/test_sqlite3/test_dbapi.py | |
parent | 222c63fc6b91f42e7cc53574615f4e9b7a33c28f (diff) | |
download | cpython-bb8aa7a2b41ad7649d66909e5266fcee039e63ed.tar.gz cpython-bb8aa7a2b41ad7649d66909e5266fcee039e63ed.zip |
gh-103489: Add get/set config methods to sqlite3.Connection (#103506)
Diffstat (limited to 'Lib/test/test_sqlite3/test_dbapi.py')
-rw-r--r-- | Lib/test/test_sqlite3/test_dbapi.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index 3013abfa730..1bb0e13e356 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -577,6 +577,30 @@ class ConnectionTests(unittest.TestCase): cx.executemany, "insert into t values(?)", ((v,) for v in range(3))) + def test_connection_config(self): + op = sqlite.SQLITE_DBCONFIG_ENABLE_FKEY + with memory_database() as cx: + with self.assertRaisesRegex(ValueError, "unknown"): + cx.getconfig(-1) + + # Toggle and verify. + old = cx.getconfig(op) + new = not old + cx.setconfig(op, new) + self.assertEqual(cx.getconfig(op), new) + + cx.setconfig(op) # defaults to True + self.assertTrue(cx.getconfig(op)) + + # Check that foreign key support was actually enabled. + with cx: + cx.executescript(""" + create table t(t integer primary key); + create table u(u, foreign key(u) references t(t)); + """) + with self.assertRaisesRegex(sqlite.IntegrityError, "constraint"): + cx.execute("insert into u values(0)") + class UninitialisedConnectionTests(unittest.TestCase): def setUp(self): |