diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 39c9bf5b61143d..b5a17564623f06 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -229,6 +229,23 @@ def test_execute_too_much_sql3(self): */ """) + def test_execute_too_long_string(self): + # The default value of SQLITE_MAX_LENGTH is 1_000_000_000, but it may + # be up to 2_147_483_647. + res = self.cu.execute("pragma compile_options") + opts = {k: v for k, v in [o[0].split("=") for o in res if "=" in o[0]]} + try: + max_length = int(opts['MAX_LENGTH']) + except (KeyError, TypeError): + max_length = 1_000_000_000 + try: + too_long = " " * (max_length + 1) + except OverflowError: + self.skipTest("Unable to create too large SQL string") + regex = "query string is too large" + self.assertRaisesRegex(sqlite.DataError, regex, self.cx, too_long) + self.assertRaisesRegex(sqlite.DataError, regex, self.cu.executescript, too_long) + def test_execute_wrong_sql_arg(self): with self.assertRaises(TypeError): self.cu.execute(42)