Skip to content

Commit

Permalink
Merge pull request #321 from svetlyak40wt/fix-defprepared-threadsafety
Browse files Browse the repository at this point in the history
Fix macro postmodern:defprepared which wasn't threadsafe when used with binary connections
  • Loading branch information
sabracrolleton authored Jul 7, 2023
2 parents 4b895e2 + df9d026 commit d5af863
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions postmodern/prepare.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(in-package :postmodern)

(define-condition mismatched-parameter-types (error)
((prepared-statement-types :initarg prepared-statement-types
((prepared-statement-types :initarg :prepared-statement-types
:reader prepared-statement-types)
(parameter-types :initarg parameter-types
(parameter-types :initarg :parameter-types
:reader parameter-types))
(:report (lambda (condition stream)
(format stream "Parameter types ~a do not match prepared statement parameter types ~a"
Expand Down Expand Up @@ -70,15 +70,17 @@ overwrite unless postgresql throws a duplicate-prepared-statement error."
(ensure-prepared *database* statement-id
query overwrite params))
(t
(let ((prepared-statement-param-types
(cl-postgres:parameter-list-types
(second
(find-postmodern-prepared-statement
statement-id))))
(param-types
(cl-postgres::parameter-list-types params)))
(if (equal prepared-statement-param-types
param-types)
(let* ((saved-prepared-statement
(find-postmodern-prepared-statement
statement-id))
(prepared-statement-param-types
(cl-postgres:parameter-list-types
(second saved-prepared-statement)))
(param-types
(cl-postgres::parameter-list-types params)))
(if (or (null saved-prepared-statement)
(equal prepared-statement-param-types
param-types))
(ensure-prepared *database* statement-id
query overwrite params)
(error
Expand Down

0 comments on commit d5af863

Please sign in to comment.