Skip to content

Commit

Permalink
Fix error handling when using bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerbinns committed Jun 16, 2024
1 parent 9604e72 commit 34ecf37
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions apsw/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 34ecf37

Please sign in to comment.