mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-89022: Improve sqlite3 exceptions related to binding params and API misuse (#91572)
* Map SQLITE_MISUSE to sqlite3.InterfaceError SQLITE_MISUSE implies misuse of the SQLite C API, which, if it happens, is _not_ a user error; it is an sqlite3 extension module error. * Raise better errors when binding parameters fail. Instead of always raising InterfaceError, guessing what went wrong, raise accurate exceptions with more accurate error messages.
This commit is contained in:
parent
d716a0dfe2
commit
090819ec5f
5 changed files with 28 additions and 20 deletions
|
|
@ -743,7 +743,7 @@ def test_execute_arg_string_with_zero_byte(self):
|
|||
self.assertEqual(row[0], "Hu\x00go")
|
||||
|
||||
def test_execute_non_iterable(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
with self.assertRaises(sqlite.ProgrammingError) as cm:
|
||||
self.cu.execute("insert into test(id) values (?)", 42)
|
||||
self.assertEqual(str(cm.exception), 'parameters are of unsupported type')
|
||||
|
||||
|
|
|
|||
|
|
@ -255,9 +255,9 @@ def test_foo(self):
|
|||
|
||||
def test_error_in_conform(self):
|
||||
val = DeclTypesTests.BadConform(TypeError)
|
||||
with self.assertRaises(sqlite.InterfaceError):
|
||||
with self.assertRaises(sqlite.ProgrammingError):
|
||||
self.cur.execute("insert into test(bad) values (?)", (val,))
|
||||
with self.assertRaises(sqlite.InterfaceError):
|
||||
with self.assertRaises(sqlite.ProgrammingError):
|
||||
self.cur.execute("insert into test(bad) values (:val)", {"val": val})
|
||||
|
||||
val = DeclTypesTests.BadConform(KeyboardInterrupt)
|
||||
|
|
@ -269,13 +269,13 @@ def test_error_in_conform(self):
|
|||
def test_unsupported_seq(self):
|
||||
class Bar: pass
|
||||
val = Bar()
|
||||
with self.assertRaises(sqlite.InterfaceError):
|
||||
with self.assertRaises(sqlite.ProgrammingError):
|
||||
self.cur.execute("insert into test(f) values (?)", (val,))
|
||||
|
||||
def test_unsupported_dict(self):
|
||||
class Bar: pass
|
||||
val = Bar()
|
||||
with self.assertRaises(sqlite.InterfaceError):
|
||||
with self.assertRaises(sqlite.ProgrammingError):
|
||||
self.cur.execute("insert into test(f) values (:val)", {"val": val})
|
||||
|
||||
def test_blob(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue