Skip to content

Commit

Permalink
Implement use-store flag for SQLite3.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Mar 30, 2018
1 parent 9d642a6 commit a87d86e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/dbd/sqlite3.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
:database-name database-name
:handle (connect database-name :busy-timeout busy-timeout)))

@export
@export-accessors
(defclass <dbd-sqlite3-query> (<dbi-query>)
(%first-result))
(%results
(store :initarg :store
:initform t
:accessor sqlite3-use-store)))

(defmethod prepare ((conn <dbd-sqlite3-connection>) (sql string) &key)
(handler-case
Expand All @@ -46,9 +51,12 @@
(let ((count 0))
(dolist (param params)
(bind-parameter prepared (incf count) param)))
(slot-makunbound query '%first-result)
(setf (slot-value query '%first-result)
(fetch-using-connection conn query))
(slot-makunbound query '%results)
(when (sqlite3-use-store query)
(setf (slot-value query '%results)
(loop for result = (fetch-using-connection conn query)
while result
collect result)))
query))

(defmethod do-sql ((conn <dbd-sqlite3-connection>) (sql string) &rest params)
Expand All @@ -66,10 +74,8 @@

(defmethod fetch-using-connection ((conn <dbd-sqlite3-connection>) (query <dbd-sqlite3-query>))
@ignore conn
(if (slot-boundp query '%first-result)
(prog1
(slot-value query '%first-result)
(slot-makunbound query '%first-result))
(if (slot-boundp query '%results)
(pop (slot-value query '%results))
(let ((prepared (query-prepared query)))
(when (handler-case (step-statement prepared)
(sqlite-error (e)
Expand Down

0 comments on commit a87d86e

Please sign in to comment.