Skip to content

Commit

Permalink
Add 'close-cursor' to delete a declared cursor explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Aug 15, 2024
1 parent f58761b commit 07ff713
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dbd/postgres.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@
:connection conn
:sql sql))

(defmethod close-cursor-using-connection ((conn dbd-postgres-connection) (cursor dbi-cursor))
(when (cursor-declared-p cursor)
(exec-query (connection-handle conn)
(format nil "CLOSE ~A" (cursor-name cursor)))
(setf (cursor-declared-p cursor) nil)
t))

(defmethod execute-using-connection ((conn dbd-postgres-connection) (cursor dbi-cursor) params)
(assert (in-transaction conn))
(with-accessors ((sql query-sql)
Expand Down
11 changes: 11 additions & 0 deletions src/driver.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#:cursor-formatter
#:cursor-declared-p
#:make-cursor
#:close-cursor
#:close-cursor-using-connection
#:prepare
#:prepare-cached
#:execute
Expand Down Expand Up @@ -183,6 +185,10 @@ This method may be overrided by subclasses."
(error 'dbi-unimplemented-error
:method-name 'make-cursor)))

(defgeneric close-cursor (cursor)
(:method ((cursor dbi-cursor))
(close-cursor-using-connection (dbi-connection cursor) cursor)))

(defgeneric execute (query &optional params)
(:documentation "Execute `query` with `params` and return the results.")
(:method (object &optional params)
Expand Down Expand Up @@ -271,6 +277,11 @@ This method must be implemented in each drivers.")
(error 'dbi-unimplemented-error
:method-name 'execute-using-connection)))

(defgeneric close-cursor-using-connection (conn cursor)
(:method (conn cursor)
(declare (ignore conn cursor))
(error 'dbi-unimplemented-error
:method-name 'close-cursor-using-connection)))

(defgeneric begin-transaction (conn)
(:documentation "Start a transaction.")
Expand Down

0 comments on commit 07ff713

Please sign in to comment.