sqlite: attempted fix for persistent MISUSE errors
- Sometimes, the bridge can get wedged in a state where doing DB operations returns SQLITE_MISUSE errors. - I don't really know what causes this, but I'm hoping unconditionally resetting the statements before they get used will ameliorate the problem? - Additionally, the reset statements now aren't wrapped in an IGNORE-ERRORS, meaning we might get error tracebacks that point to the actual problem now.
This commit is contained in:
parent
51821a774f
commit
14ff49b1d2
19
sqlite.lisp
19
sqlite.lisp
|
@ -45,26 +45,25 @@ In other words, prepares STATEMENT once, then returns the prepared statement aft
|
||||||
,statement-sym)))
|
,statement-sym)))
|
||||||
|
|
||||||
(defmacro with-prepared-statement ((name statement) &body forms)
|
(defmacro with-prepared-statement ((name statement) &body forms)
|
||||||
"Evaluates FORMS, binding a prepared statement with SQL text STATEMENT to NAME, and ensuring it is reset when control is transferred."
|
"Evaluates FORMS, binding a prepared statement with SQL text STATEMENT to NAME and making sure it is reset beforehand."
|
||||||
`(bt:with-recursive-lock-held (*db-lock*)
|
`(bt:with-recursive-lock-held (*db-lock*)
|
||||||
(let ((,name (prepared-statement ,statement)))
|
(let ((,name (prepared-statement ,statement)))
|
||||||
(multiple-value-prog1
|
(sqlite:reset-statement ,name)
|
||||||
(unwind-protect
|
(sqlite:clear-statement-bindings ,name)
|
||||||
(progn ,@forms)
|
,@forms)))
|
||||||
(ignore-errors (sqlite:reset-statement ,name)))))))
|
|
||||||
|
|
||||||
(defmacro with-prepared-statements (statements &body forms)
|
(defmacro with-prepared-statements (statements &body forms)
|
||||||
"Like WITH-PREPARED-STATEMENT, but takes multiple statements."
|
"Like WITH-PREPARED-STATEMENT, but takes multiple statements."
|
||||||
(let ((let-forms (loop for (name statement) in statements
|
(let ((let-forms (loop for (name statement) in statements
|
||||||
collect `(,name (prepared-statement ,statement))))
|
collect `(,name (prepared-statement ,statement))))
|
||||||
(reset-forms (loop for (name statement) in statements
|
(reset-forms (loop for (name statement) in statements
|
||||||
collect `(ignore-errors (sqlite:reset-statement ,name)))))
|
collect `(progn
|
||||||
|
(sqlite:reset-statement ,name)
|
||||||
|
(sqlite:clear-statement-bindings ,name)))))
|
||||||
`(bt:with-recursive-lock-held (*db-lock*)
|
`(bt:with-recursive-lock-held (*db-lock*)
|
||||||
(let (,@let-forms)
|
(let (,@let-forms)
|
||||||
(multiple-value-prog1
|
,@reset-forms
|
||||||
(unwind-protect
|
,@forms))))
|
||||||
(progn ,@forms))
|
|
||||||
(ignore-errors (progn ,@reset-forms)))))))
|
|
||||||
|
|
||||||
(defmacro column-values (statement)
|
(defmacro column-values (statement)
|
||||||
"Returns the values in the current row of the STATEMENT."
|
"Returns the values in the current row of the STATEMENT."
|
||||||
|
|
Loading…
Reference in a new issue