From 34ecf37fa8c8aa67be1672e4bc4a88c23a3ea3b9 Mon Sep 17 00:00:00 2001 From: Roger Binns Date: Sun, 16 Jun 2024 06:26:51 -0700 Subject: [PATCH] Fix error handling when using bindings --- apsw/shell.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apsw/shell.py b/apsw/shell.py index e985b9fc..be1b93ed 100644 --- a/apsw/shell.py +++ b/apsw/shell.py @@ -851,13 +851,20 @@ def et(cursor, statement, bindings): cur.execute(sql, bindings) except apsw.ExecTraceAbort: pass + except apsw.BindingsError as e: + return Shell._qd(None, None, "You must used named bindings (eg $name) and .parameter set", -1, e, explain) except apsw.Error as e: - return Shell._qd(sql[:len(saved)], sql[len(saved):], str(e), e.error_offset, e, explain) + return Shell._qd(sql[: len(saved)], sql[len(saved) :], str(e), getattr(e, "error_offset", -1), e, explain) except KeyError as e: var = e.args[0] - return Shell._qd(None, None, - f"No binding present for '{ var }' - use .parameter set { var } VALUE to provide one", -1, - e, explain) + return Shell._qd( + None, + None, + f"No binding present for '{ var }' - use .parameter set { var } VALUE to provide one", + -1, + e, + explain, + ) return Shell._qd(sql[:len(saved)], sql[len(saved):], None, None, None, explain) def process_sql(self, sql: str, bindings=None, internal=False, summary=None):