branch: elpa/pg
commit fdf41b90915ed44d4bf5bb3d196a6e64f56e551b
Author: Eric Marsden <[email protected]>
Commit: Eric Marsden <[email protected]>

    Parsing: support for NULL values in integer arrays
---
 pg.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/pg.el b/pg.el
index 4bb44e32bc4..884ee0d78b3 100644
--- a/pg.el
+++ b/pg.el
@@ -2944,15 +2944,19 @@ Return nil if the extension could not be loaded."
 
 (defun pg-intarray-parser (str _encoding)
   "Parse PostgreSQL value STR as an array of integers."
-  (let ((len (length str)))
-    (unless (and (eql (aref str 0) ?{)
-                 (eql (aref str (1- len)) ?}))
-      (signal 'pg-protocol-error (list "Unexpected format for int array")))
-    (let ((maybe-items (cl-subseq str 1 (- len 1))))
-      (if (zerop (length maybe-items))
-          (vector)
-        (let ((items (split-string maybe-items ",")))
-          (apply #'vector (mapcar #'cl-parse-integer items)))))))
+  (cl-flet ((parse-int (str)
+              (if (string= "NULL" str)
+                  pg-null-marker
+                (cl-parse-integer str))))
+    (let ((len (length str)))
+      (unless (and (eql (aref str 0) ?{)
+                   (eql (aref str (1- len)) ?}))
+        (signal 'pg-protocol-error (list "Unexpected format for int array")))
+      (let ((maybe-items (cl-subseq str 1 (- len 1))))
+        (if (zerop (length maybe-items))
+            (vector)
+          (let ((items (split-string maybe-items ",")))
+            (apply #'vector (mapcar #'parse-int items))))))))
 
 (pg-register-parser "_int2" #'pg-intarray-parser)
 (pg-register-parser "_int2vector" #'pg-intarray-parser)

Reply via email to