Commit 3f194172 authored by Eric Marsden's avatar Eric Marsden

Allow NULL values for bound variables in prepared statements. Bug

pointed out by Steve Purcell <steve@sanityinc.com>.
parent 9002c4c8
......@@ -321,7 +321,7 @@ value of the parameter"
do
(ecase type
((:byte)
(check-type value (unsigned-byte 8))
(check-type value (signed-byte 8))
(setf (elt data position) value)
(incf position))
((:char)
......@@ -329,13 +329,12 @@ value of the parameter"
(setf (elt data position) (char-code value))
(incf position))
((:int16)
(check-type value (unsigned-byte 16))
(check-type value (signed-byte 16))
(setf (elt data position) (ldb (byte 8 8) value))
(setf (elt data (+ 1 position)) (ldb (byte 8 0) value))
(incf position 2))
((:int32)
(check-type value (unsigned-byte 32))
(check-type value (signed-byte 32))
(setf (elt data position) (ldb (byte 8 24) value))
(setf (elt data (+ 1 position)) (ldb (byte 8 16) value))
(setf (elt data (+ 2 position)) (ldb (byte 8 8) value))
......@@ -859,25 +858,28 @@ a result structure which can be decoded using `pg-result'."
(when list-of-types-and-values
(loop :for (type value) :in list-of-types-and-values
:do
(ecase type
((:int32)
(push '(:int32 4) data)
(push `(:int32 ,value) data))
((:int16)
(push '(:int32 2) data)
(push `(:int16 ,value) data))
((:byte)
(push '(:int32 1) data)
(push `(:int8 ,value) data))
((:char)
(push '(:int32 1) data)
(push `(:int8 ,(char-code value)) data))
;; this is not a NUL-terminated string, so send exactly
;; the string length rather than 1+
((:string)
(let ((encoded-length (length (convert-string-to-bytes value (pg-client-encoding connection)))))
(push `(:int32 ,encoded-length) data)
(push `(:string ,value) data)))))
(cond ((null value)
(push '(:int32 -1) data))
(t
(ecase type
((:int32)
(push '(:int32 4) data)
(push `(:int32 ,value) data))
((:int16)
(push '(:int32 2) data)
(push `(:int16 ,value) data))
((:byte)
(push '(:int32 1) data)
(push `(:int8 ,value) data))
((:char)
(push '(:int32 1) data)
(push `(:int8 ,(char-code value)) data))
;; this is not a NUL-terminated string, so send exactly
;; the string length rather than 1+
((:string)
(let ((encoded-length (length (convert-string-to-bytes value (pg-client-encoding connection)))))
(push `(:int32 ,encoded-length) data)
(push `(:string ,value) data)))))))
(setf data (nreverse data)))
(cond
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment