Skip to content

Commit

Permalink
Allow to free results set of MySQL on GC.
Browse files Browse the repository at this point in the history
And also add free-query-resources for MySQL driver.
  • Loading branch information
fukamachi committed Jan 14, 2022
1 parent ade22ea commit fe3df73
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/dbd/mysql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#:owner-pool
#:+server-gone-error+
#:+server-lost+)
(:import-from #:trivial-garbage
#:finalize
#:cancel-finalization)
(:export #:dbd-mysql
#:dbd-mysql-connection
#:dbd-mysql-query
Expand Down Expand Up @@ -46,7 +49,9 @@

(defclass dbd-mysql-query (dbi-query)
((store :initarg :store :initform t
:accessor mysql-use-store)))
:accessor mysql-use-store)
(freedp :initform nil
:accessor query-freed-p)))

(defstruct (mysql-result-list (:constructor make-mysql-result-list (&optional result-set row-count)))
(result-set nil :type list)
Expand Down Expand Up @@ -103,7 +108,10 @@
(setf result (make-mysql-result-list rows count))
(setf (query-row-count query) count)))
(t
(sql-log (query-sql query) params nil took-usec)))
(sql-log (query-sql query) params nil took-usec)
(finalize result
(lambda ()
(mysql-free-result (result-set result))))))
(setf (query-results query) result)
query))

Expand Down Expand Up @@ -136,5 +144,12 @@
(return-from ping nil)))))
(cl-mysql:ping :database (connection-handle conn))))

(defmethod free-query-resources ((query dbd-mysql-query))
(unless (query-freed-p query)
(let ((result (query-results query)))
(mysql-free-result (result-set result))
(setf (query-freed-p query) t)
(cancel-finalization result))))

(defmethod row-count ((conn dbd-mysql-connection))
(second (fetch (execute (prepare conn "SELECT ROW_COUNT()" :store T)))))

0 comments on commit fe3df73

Please sign in to comment.