From 07ff713af2f86f3b1701fab26feb0fa6ba1bace4 Mon Sep 17 00:00:00 2001 From: Eitaro Fukamachi Date: Thu, 15 Aug 2024 13:48:24 +0000 Subject: [PATCH] Add 'close-cursor' to delete a declared cursor explicitly. --- src/dbd/postgres.lisp | 7 +++++++ src/driver.lisp | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/dbd/postgres.lisp b/src/dbd/postgres.lisp index 355027c..bb1f590 100644 --- a/src/dbd/postgres.lisp +++ b/src/dbd/postgres.lisp @@ -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) diff --git a/src/driver.lisp b/src/driver.lisp index edf2f02..2e55c2b 100644 --- a/src/driver.lisp +++ b/src/driver.lisp @@ -32,6 +32,8 @@ #:cursor-formatter #:cursor-declared-p #:make-cursor + #:close-cursor + #:close-cursor-using-connection #:prepare #:prepare-cached #:execute @@ -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) @@ -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.")