Update of /project/pg/cvsroot/pg In directory clnet:/tmp/cvs-serv11251
Modified Files: v3-protocol.lisp Log Message: Allow NULL values for bound variables in prepared statements. Bug pointed out by Steve Purcell steve@sanityinc.com.
--- /project/pg/cvsroot/pg/v3-protocol.lisp 2006/09/24 15:50:18 1.25 +++ /project/pg/cvsroot/pg/v3-protocol.lisp 2006/10/22 15:48:45 1.26 @@ -321,7 +321,7 @@ 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 @@ (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 @@ (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