1 (defpackage :cl-postgres-tests
2 (:use
:common-lisp
:fiveam
:cl-postgres
:cl-postgres-error
)
3 (:export
#:prompt-connection
#:*test-connection
* #:with-test-connection
))
5 (in-package :cl-postgres-tests
)
7 (defparameter *test-connection
* '("test" "test" "" "localhost"))
9 (defun prompt-connection (&optional
(list *test-connection
*))
10 (flet ((ask (name pos
)
11 (format *query-io
* "~a (enter to keep '~a'): " name
(nth pos list
))
12 (finish-output *query-io
*)
13 (let ((answer (read-line *query-io
*)))
14 (unless (string= answer
"") (setf (nth pos list
) answer
)))))
15 (format *query-io
* "~%To run this test, you must configure a database connection.~%")
16 (ask "Database name" 0)
21 ;; Adjust the above to some db/user/pass/host/[port] combination that
22 ;; refers to a valid postgresql database, then after loading the file,
23 ;; run the tests with (fiveam:run! :cl-postgres)
25 (def-suite :cl-postgres
)
26 (in-suite :cl-postgres
)
28 (defmacro with-test-connection
(&body body
)
29 `(let ((connection (apply 'open-database
*test-connection
*)))
30 (unwind-protect (progn ,@body
)
31 (close-database connection
))))
33 (defmacro with-default-readtable
(&body body
)
34 `(let ((*sql-readtable
* (default-sql-readtable)))
37 (defmacro with-rollbacked-transaction
(&body body
)
39 (exec-query connection
"start transaction")
40 (unwind-protect (progn ,@body
)
41 (exec-query connection
"rollback"))))
45 (is (database-open-p connection
))))
49 (destructuring-bind ((a b c d e
))
50 (exec-query connection
"select 22::integer, 44.5::double precision, 'abcde'::varchar, true::boolean, 4.5::numeric(5,2)"
54 (is (string= c
"abcde"))
59 (is (string= (to-sql-string :null
) "NULL"))
60 (is (string= (to-sql-string t
) "true"))
61 (is (string= (to-sql-string 400) "400"))
62 (is (string= (to-sql-string "foo") "foo"))
63 (is (eq t
(nth-value 1 (to-sql-string "bar"))))
64 (is (eq nil
(nth-value 1 (to-sql-string 10)))))
67 (with-default-readtable
69 (destructuring-bind ((a b c
))
70 (exec-query connection
"select '1980-02-01'::date, '2010-04-05 14:42:21.500'::timestamp, '2 years -4 days'::interval"
74 (is (equal c
'((:MONTHS
24) (:DAYS -
4) (:SECONDS
0) (:USECONDS
0))))))))
76 (test timestamp-with-time-zone
77 (with-default-readtable
79 (with-rollbacked-transaction
80 ;; 1. set local time to GMT -- returned time should be what we
81 ;; pass in -- note we lose the 500 millesconds here :(
82 (exec-query connection
"set local time zone 'GMT'")
83 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp with time zone"
86 ;; 2. set local time to PST8PDT, now we should get back a time
87 ;; that is 7 hours later than. This means that the input time
88 ;; is specified in PST8PDT, but the returned timestamp is in
90 (exec-query connection
"set time zone 'PST8PDT'")
91 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp with time zone"
94 ;; 3. now we specify the time zone to be GMT but the input time
95 ;; is in EDT, so the returned time should be 4 hours later.
96 (exec-query connection
"set time zone 'GMT'")
97 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp at time zone 'America/New_York'"
101 (test timestamp-with-time-zone-text
102 (let ((*sql-readtable
* (copy-sql-readtable)))
103 (set-sql-reader oid
:+timestamptz
+ nil
)
104 (with-test-connection
105 (with-rollbacked-transaction
106 ;; 1. GMT input and GMT output
107 (exec-query connection
"set time zone 'GMT'")
108 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp with time zone"
110 '(("2010-04-05 14:42:21.5+00"))))
111 ;; 2. PST8PDT input and text representation of the same input
112 ;; time with a -7 hour offset
113 (exec-query connection
"set time zone 'PST8PDT'")
114 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp with time zone"
116 '(("2010-04-05 14:42:21.5-07"))))
117 ;; 3. EDT input with GMT output (4 hours later, 0 hour offset)
118 (exec-query connection
"set time zone 'GMT'")
119 (is (equalp (exec-query connection
"select '2010-04-05 14:42:21.500'::timestamp at time zone 'America/New_York'"
121 '(("2010-04-05 18:42:21.5+00"))))))))
123 (test alist-row-reader
124 (with-test-connection
125 (is (equal (exec-query connection
"select 42 as foo, 99 as bar" 'alist-row-reader
)
126 '((("foo" .
42) ("bar" .
99)))))))
128 (test prepared-statement
129 (with-test-connection
130 (prepare-query connection
"test" "select $1::integer, $2::boolean, $3::text")
131 (is (equal (exec-prepared connection
"test" '(42 nil
"foo") 'list-row-reader
)
132 '((42 nil
"foo"))))))
134 (test unprepare-statement
135 (with-test-connection
136 (prepare-query connection
"test" "select true")
137 (unprepare-query connection
"test")
138 (prepare-query connection
"test" "select false")
139 (is (equal (exec-prepared connection
"test" '() 'list-row-reader
)
142 (test prepared-array-param
143 (with-test-connection
144 (prepare-query connection
"test" "select ($1::int[])[2]")
145 (is (equal (exec-prepared connection
"test" '(#(1 2 3)) 'list-row-reader
)
147 (prepare-query connection
"test2" "select ($1::text[])[2]")
148 (is (equal (exec-prepared connection
"test2" '(#("A" "B" "C")) 'list-row-reader
)
152 (with-test-connection
153 (let* ((str "foobar42")
154 (bytes (coerce #(102 111 111 98 97 114 52 50) '(vector (unsigned-byte 8)))))
155 (prepare-query connection
"test" "select $1::varchar, $2::bytea")
156 (is (equalp (exec-prepared connection
"test" (list str bytes
) 'list-row-reader
)
157 (list (list str bytes
)))))))
160 (with-test-connection
161 (signals cl-postgres-error
:syntax-error-or-access-violation
162 (exec-query connection
"gubble gubble gabble goo"))
163 (is (equal (exec-query connection
"select false" 'list-row-reader
)
166 (test unique-violation-error
167 (with-test-connection
168 (exec-query connection
"create table test (id int not null primary key, name text)")
169 (exec-query connection
"insert into test values (1, 'bert')")
170 (signals unique-violation
171 (exec-query connection
"insert into test values (1, 'harry')"))
172 (exec-query connection
"drop table test")))
175 (with-test-connection
176 (let ((*sql-readtable
* (copy-sql-readtable)))
177 (set-sql-reader 2249 (lambda (text)
178 (with-input-from-string (*standard-input
* text
)
179 (read-char) ;; opening paren
183 (is (equal (exec-query connection
"select (10,20)" 'list-row-reader
)
185 (is (equal (exec-query connection
"select (30,40)" 'list-row-reader
)
188 (test sql-reader-binary
189 (with-test-connection
190 (with-binary-row-values
191 (let ((*sql-readtable
* (copy-sql-readtable)))
192 (set-sql-reader 2249 (lambda (text)
193 (with-input-from-string (*standard-input
* text
)
194 (read-char) ;; opening paren
198 (is (equal (exec-query connection
"select (10,20)" 'list-row-reader
)
200 (is (equal (exec-query connection
"select (30,40)" 'list-row-reader
)
204 (with-test-connection
205 (exec-query connection
"create table test (a int, b text, c date, d timestamp, e int[])")
206 (let ((stream (open-db-writer *test-connection
* 'test
'(a b c d e
))))
207 ;; test a variety of types (int, text, date, timstamp, int array)
208 (loop for row in
'((1 "one" "2012-01-01" "2012-01-01 00:00" #(1 2 3 42))
209 (2 "two" "2012-01-01" "2012-01-01 00:00" #(3 2 1 42))
211 ;; make sure utf-8 gets through ok
212 (3 "κόσμε" "2012-01-01" "2012-01-01 00:00" #(1))
214 ;; make sure tabs get through ok
215 (4 "one two three" "2012-01-01" "2012-01-01 00:00" #(1)))
217 (db-write-row stream row
))
218 (close-db-writer stream
))
219 (print (exec-query connection
"select * from test"))
220 (exec-query connection
"drop table test")))
222 (test row-boolean-array
223 (with-test-connection
224 (is (equalp (exec-query connection
"select row(ARRAY[TRUE, FALSE, TRUE])" 'list-row-reader
)
225 '(("(\"{t,f,t}\")"))))))
227 (test row-boolean-array-binary
228 (with-test-connection
229 (with-binary-row-values
230 (is (equalp (exec-query connection
"select row(ARRAY[TRUE, FALSE, TRUE])" 'list-row-reader
)
231 '(((#(T NIL T
)))))))))
234 (with-test-connection
235 (is (equalp (exec-query connection
"select cast(255 as bit(8)), cast(-44 as bit(128))" 'list-row-reader
)
237 #*11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111010100))))
238 (is (equalp (exec-query connection
"select row(cast(32 as bit(12)))" 'list-row-reader
)
239 '(("(000000100000)"))))
240 (is (equalp (exec-query connection
"select ARRAY[cast(32 as bit(16))]" 'list-row-reader
)
241 '((#(#*0000000000100000)))))
242 (is (equalp (exec-query connection
"select row(ARRAY[cast(32 as bit(16))])" 'list-row-reader
)
243 '(("({0000000000100000})"))))))
245 (test cast-to-bits-binary
246 (with-test-connection
247 (with-binary-row-values
248 (is (equalp (exec-query connection
"select cast(255 as bit(8)), cast(-44 as bit(128))" 'list-row-reader
)
250 #*11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111010100))))
251 (is (equalp (exec-query connection
"select row(cast(32 as bit(12)))" 'list-row-reader
)
252 '(((#*000000100000)))))
253 (is (equalp (exec-query connection
"select ARRAY[cast(32 as bit(16))]" 'list-row-reader
)
254 '((#(#*0000000000100000)))))
255 (is (equalp (exec-query connection
"select row(ARRAY[cast(32 as bit(16))])" 'list-row-reader
)
256 '(((#(#*0000000000100000)))))))))
258 (test cast-to-varbits
259 (with-test-connection
260 (is (equalp (exec-query connection
"select 255::bit(8)::varbit(8), 44::bit(128)::varbit(128)" 'list-row-reader
)
262 #*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100))))
263 (is (equalp (exec-query connection
"select row(32::bit(12)::varbit(12))" 'list-row-reader
)
264 '(("(000000100000)"))))
265 (is (equalp (exec-query connection
"select ARRAY[32::bit(16)::varbit(16)]" 'list-row-reader
)
266 '((#(#*0000000000100000)))))
267 (is (equalp (exec-query connection
"select row(ARRAY[32::bit(16)::varbit(16)])" 'list-row-reader
)
268 '(("({0000000000100000})"))))))
270 (test cast-to-varbits-binary
271 (with-test-connection
272 (with-binary-row-values
273 (is (equalp (exec-query connection
"select 255::bit(8)::varbit(8), 44::bit(128)::varbit(128)" 'list-row-reader
)
275 #*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100))))
276 (is (equalp (exec-query connection
"select row(32::bit(12)::varbit(12))" 'list-row-reader
)
277 '(((#*000000100000)))))
278 (is (equalp (exec-query connection
"select ARRAY[32::bit(16)::varbit(16)]" 'list-row-reader
)
279 '((#(#*0000000000100000)))))
280 (is (equalp (exec-query connection
"select row(ARRAY[32::bit(16)::varbit(16)])" 'list-row-reader
)
281 '(((#(#*0000000000100000)))))))))
285 (test row-integer-array
286 (with-test-connection
287 (is (equalp (exec-query connection
"select row(ARRAY[1,2,4,8])" 'list-row-reader
)
288 '(("(\"{1,2,4,8}\")"))))))
290 (test row-integer-array-binary
291 (with-test-connection
292 (with-binary-row-values
293 (is (equalp (exec-query connection
"select row(ARRAY[1,2,4,8])" 'list-row-reader
)
294 '(((#(1 2 4 8)))))))))
296 (test row-string-array
297 (with-test-connection
298 (is (equalp (exec-query connection
"select row(ARRAY['foo', 'bar', 'baz'])" 'list-row-reader
)
299 '(("(\"{foo,bar,baz}\")"))))))
301 (test row-string-array-binary
302 (with-test-connection
303 (with-binary-row-values
304 (is (equalp (exec-query connection
"select row(ARRAY['foo', 'bar', 'baz'])" 'list-row-reader
)
305 '(((#("foo" "bar" "baz")))))))))
307 (test row-bpchar-array
308 (with-test-connection
309 (is (equalp (exec-query connection
"select row(ARRAY[cast('foo' as bpchar)])" 'list-row-reader
)
312 (test row-bpchar-array-binary
313 (with-test-connection
314 (with-binary-row-values
315 (is (equalp (exec-query connection
"select row(ARRAY[cast('foo' as bpchar)])" 'list-row-reader
)
318 (test row-varchar-array
319 (with-test-connection
320 (is (equalp (exec-query connection
"select row(ARRAY['foo'::varchar])" 'list-row-reader
)
323 (test row-varchar-array-binary
324 (with-test-connection
325 (with-binary-row-values
326 (is (equalp (exec-query connection
"select row(ARRAY['foo'::varchar])" 'list-row-reader
)
330 (with-test-connection
331 (is (equalp (exec-query connection
"select row(ARRAY[1234::oid, 5678::oid])" 'list-row-reader
)
332 '(("(\"{1234,5678}\")"))))))
334 (test row-oid-array-binary
335 (with-test-connection
336 (with-binary-row-values
337 (is (equalp (exec-query connection
"select row(ARRAY[1234::oid, 5678::oid])" 'list-row-reader
)
338 '(((#(1234 5678)))))))))
341 (with-test-connection
342 (is (equalp (exec-query connection
"select row(ARRAY[1234::int2])" 'list-row-reader
)
345 (test row-int2-array-binary
346 (with-test-connection
347 (with-binary-row-values
348 (is (equalp (exec-query connection
"select row(ARRAY[1234::int2])" 'list-row-reader
)
352 (with-test-connection
353 (is (equalp (exec-query connection
"select row(ARRAY[123456789012::int8])" 'list-row-reader
)
354 '(("({123456789012})"))))))
356 (test row-int8-array-binary
357 (with-test-connection
358 (with-binary-row-values
359 (is (equalp (exec-query connection
"select row(ARRAY[123456789012::int8])" 'list-row-reader
)
360 '(((#(123456789012)))))))))
362 (test row-float-array
363 (with-test-connection
364 (is (equalp (exec-query connection
"select row(ARRAY[3.14::float])" 'list-row-reader
)
367 (test row-float-array-binary
368 (with-test-connection
369 (with-binary-row-values
370 (is (equalp (exec-query connection
"select row(ARRAY[3.14::float])" 'list-row-reader
)
371 '(((#(3.14d0
)))))))))
373 (test row-double-array
374 (with-test-connection
375 (is (equalp (exec-query connection
"select row(ARRAY[cast(3.14 as double precision)])" 'list-row-reader
)
378 (test row-double-array-binary
379 (with-test-connection
380 (with-binary-row-values
381 (is (equalp (exec-query connection
"select row(ARRAY[cast(3.14 as double precision)])" 'list-row-reader
)
382 '(((#(3.14d0
)))))))))
385 (with-default-readtable
386 (with-test-connection
387 (is (equalp (elt (exec-query connection
"select row(ARRAY['1980-02-01'::date])" 'list-row-reader
) 0)
388 '("({1980-02-01})"))))))
390 (test row-date-array-binary
391 (with-default-readtable
392 (with-test-connection
393 (with-binary-row-values
394 (is (= (elt (caaar (exec-query connection
"select row(ARRAY['1980-02-01'::date])" 'list-row-reader
)) 0)
398 (with-test-connection
399 (is (equalp (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp)"
401 '(("(\"2010-04-05 14:42:21.5\")"))))))
403 (test row-timestamp-without-time-zone
404 (with-test-connection
405 (is (equalp (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
407 '(("(\"2010-04-05 14:42:21.5\")"))))))
409 (test row-timestamp-with-time-zone
410 (with-test-connection
411 (with-rollbacked-transaction
412 (exec-query connection
"set time zone 'GMT'")
413 (is (equalp (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp with time zone)"
415 '(("(\"2010-04-05 14:42:21.5+00\")")))))))
417 (test row-timestamp-with-time-zone-binary
418 (with-default-readtable
419 (with-test-connection
420 (with-rollbacked-transaction
421 (exec-query connection
"set time zone 'GMT'")
422 (with-binary-row-values
423 (destructuring-bind (gmt pdt
)
428 "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
429 " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
431 (is (equalp (multiple-value-list gmt
)
433 (is (equalp (multiple-value-list pdt
)
434 '(3479438541)))))))))
436 (test row-timestamp-array
437 (with-default-readtable
438 (with-test-connection
439 (is (equalp (elt (exec-query connection
"select row(ARRAY['2010-04-05 14:42:21.500'::timestamp])"
441 '("(\"{\"\"2010-04-05 14:42:21.5\"\"}\")"))))))
443 (test row-timestamp-array-binary
444 (with-default-readtable
445 (with-binary-row-values
446 (with-test-connection
447 (is (equalp (elt (exec-query connection
"select row(ARRAY['2010-04-05 14:42:21.500'::timestamp])"
449 '((#(3479467341)))))))))
451 (test row-timestamp-without-time-zone-array
452 (with-test-connection
453 (is (equalp (elt (exec-query connection
"select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
455 '("(\"{\"\"2010-04-05 14:42:21.5\"\"}\")")))))
458 (with-test-connection
459 (is (equalp (exec-query connection
"select row('05:00'::time)"
461 '(("(05:00:00)"))))))
463 (test row-interval-array
464 (with-default-readtable
465 (with-test-connection
466 (with-binary-row-values
467 (is (equalp (elt (caaar (exec-query connection
"select row(ARRAY['2 years -4 days'::interval])"
468 'list-row-reader
)) 0)
469 '((:MONTHS
24) (:DAYS -
4) (:SECONDS
0) (:USECONDS
0))))))))
471 (defparameter *random-byte-count
* 8192)
474 (with-test-connection
475 (exec-query connection
"create table test (a bytea)")
477 (let ((random-bytes (make-array *random-byte-count
* :element-type
'(unsigned-byte 8))))
478 (loop for i below
*random-byte-count
*
479 do
(setf (aref random-bytes i
)
481 (prepare-query connection
"bytea-insert" "insert into test values ($1)")
482 (exec-prepared connection
"bytea-insert" (list random-bytes
))
483 (is (equalp (exec-query connection
"select a from test;" 'list-row-reader
)
484 `((,random-bytes
)))))
485 (exec-query connection
"drop table test"))))
487 (defun vector-to-hex-string (vec)
488 (with-output-to-string (s)
490 (format s
"~(~2,\'0x~)" x
))
494 (test write-row-bytea
495 (with-test-connection
496 (exec-query connection
"create table test (a bytea)")
497 (let ((*random-byte-count
* 16))
499 (let ((random-bytes (make-array *random-byte-count
* :element-type
'(unsigned-byte 8))))
500 (loop for i below
*random-byte-count
*
501 do
(setf (aref random-bytes i
)
503 (prepare-query connection
"bytea-insert" "insert into test values ($1)")
504 (exec-prepared connection
"bytea-insert" (list random-bytes
))
505 (is (equalp (exec-query connection
"select row(a) from test;" 'list-row-reader
)
506 `((,(concatenate 'string
508 (vector-to-hex-string random-bytes
)
510 (exec-query connection
"drop table test")))))
512 (test write-row-array-bytea
513 (with-test-connection
514 (exec-query connection
"create table test (a bytea)")
515 (let ((*random-byte-count
* 16))
517 (let ((random-bytes (make-array *random-byte-count
* :element-type
'(unsigned-byte 8))))
518 (loop for i below
*random-byte-count
*
519 do
(setf (aref random-bytes i
)
521 (prepare-query connection
"bytea-insert" "insert into test values ($1)")
522 (exec-prepared connection
"bytea-insert" (list random-bytes
))
523 (is (equalp (exec-query connection
"select row(ARRAY[a]) from test;" 'list-row-reader
)
524 `(((#(,random-bytes
)))))))
525 (exec-query connection
"drop table test")))))
527 (test write-row-array-bytea
528 (with-test-connection
529 (with-binary-row-values
530 (exec-query connection
"create table test (a bytea)")
532 (let ((random-bytes (make-array *random-byte-count
* :element-type
'(unsigned-byte 8))))
533 (loop for i below
*random-byte-count
*
534 do
(setf (aref random-bytes i
)
536 (prepare-query connection
"bytea-insert" "insert into test values ($1)")
537 (exec-prepared connection
"bytea-insert" (list random-bytes
))
538 (is (equalp (exec-query connection
"select row(ARRAY[a]) from test;" 'list-row-reader
)
539 `(((#(,random-bytes
)))))))
540 (exec-query connection
"drop table test")))))
542 (test write-row-array-bytea-binary
543 (with-test-connection
544 (with-binary-row-values
545 (exec-query connection
"create table test (a bytea)")
547 (let ((random-bytes (make-array *random-byte-count
* :element-type
'(unsigned-byte 8))))
548 (loop for i below
*random-byte-count
*
549 do
(setf (aref random-bytes i
)
551 (prepare-query connection
"bytea-insert" "insert into test values ($1)")
552 (exec-prepared connection
"bytea-insert" (list random-bytes
))
553 (is (equalp (exec-query connection
"select row(ARRAY[a]) from test;" 'list-row-reader
)
554 `(((#(,random-bytes
)))))))
555 (exec-query connection
"drop table test")))))
558 (with-test-connection
559 (is (equalp (exec-query connection
"select row(ARRAY['foo'::name])" 'list-row-reader
)
562 (test row-name-array-binary
563 (with-test-connection
564 (with-binary-row-values
565 (is (equalp (exec-query connection
"select row(ARRAY['foo'::name])" 'list-row-reader
)
569 (with-test-connection
570 (is (equalp (exec-query connection
"select point(1,2)" 'list-row-reader
)
571 '(((1.0d0
2.0d0
)))))))
574 (with-test-connection
575 (is (equalp (exec-query connection
"select row(point(1,2))" 'list-row-reader
)
576 '(("(\"(1,2)\")"))))))
578 (test row-point-binary
579 (with-test-connection
580 (with-binary-row-values
581 (is (equalp (exec-query connection
"select row(point(1,2))" 'list-row-reader
)
582 '((((1.0d0
2.0d0
)))))))))
584 (test row-point-array
585 (with-test-connection
586 (is (equalp (exec-query connection
"select row(ARRAY[point(1,2)])" 'list-row-reader
)
587 '(("(\"{\"\"(1,2)\"\"}\")"))))))
589 (test row-point-array-binary
590 (with-test-connection
591 (with-binary-row-values
592 (is (equalp (exec-query connection
"select row(ARRAY[point(1,2)])" 'list-row-reader
)
593 '(((#((1.0d0
2.0d0
))))))))))
596 (with-test-connection
597 (is (equalp (exec-query connection
"select lseg(point(1,2),point(3,4))" 'list-row-reader
)
598 '((((1.0d0
2.0d0
) (3.0d0
4.0d0
))))))))
601 (with-test-connection
602 (is (equalp (exec-query connection
"select row(lseg(point(1,2),point(3,4)))" 'list-row-reader
)
603 '(("(\"[(1,2),(3,4)]\")"))))))
605 (test row-lseg-binary
606 (with-test-connection
607 (with-binary-row-values
608 (is (equalp (exec-query connection
"select row(lseg(point(1,2),point(3,4)))" 'list-row-reader
)
609 '(((((1.0d0
2.0d0
) (3.0d0
4.0d0
))))))))))
612 (with-test-connection
613 (is (equalp (exec-query connection
"select row(ARRAY[lseg(point(1,2),point(3,4))])" 'list-row-reader
)
614 '(("(\"{\"\"[(1,2),(3,4)]\"\"}\")"))))))
616 (test row-lseg-array-binary
617 (with-test-connection
618 (with-binary-row-values
619 (is (equalp (exec-query connection
"select row(ARRAY[lseg(point(1,2),point(3,4))])" 'list-row-reader
)
620 '(((#(((1.0d0
2.0d0
) (3.0d0
4.0d0
)))))))))))
623 (with-test-connection
624 (is (equalp (exec-query connection
"select box(point(1,2),point(3,4))" 'list-row-reader
)
625 '((((3.0d0
4.0d0
) (1.0d0
2.0d0
))))))))
628 (with-test-connection
629 (is (equalp (exec-query connection
"select row(box(point(1,2),point(3,4)))" 'list-row-reader
)
630 '(("(\"(3,4),(1,2)\")"))))))
633 (with-test-connection
634 (with-binary-row-values
635 (is (equalp (exec-query connection
"select row(box(point(1,2),point(3,4)))" 'list-row-reader
)
636 '(((((3.0d0
4.0d0
) (1.0d0
2.0d0
))))))))))
639 (with-test-connection
640 (is (equalp (exec-query connection
"select row(ARRAY[box(point(1,2),point(3,4))])" 'list-row-reader
)
641 '(("(\"{(3,4),(1,2)}\")"))))))
643 (test row-box-array-binary
644 (with-test-connection
645 (with-binary-row-values
646 (is (equalp (exec-query connection
"select row(ARRAY[box(point(1,2),point(3,4))])" 'list-row-reader
)
647 '(((#(((3.0d0
4.0d0
) (1.0d0
2.0d0
)))))))))))
649 (test row-array-nulls
650 (with-test-connection
651 (is (equalp (exec-query connection
"select row((ARRAY[1,3,4])[5:99])" 'list-row-reader
)
654 (test row-array-nulls-binary
655 (with-test-connection
656 (cl-postgres::with-binary-row-values
657 (is (equalp (exec-query connection
"select row((ARRAY[1,3,4])[5:99])" 'list-row-reader
)
660 (test row-array-nulls-binary-2
661 (with-test-connection
662 (cl-postgres::with-binary-row-values
663 (is (equalp (exec-query connection
"select row(ARRAY[NULL, NULL]);" 'list-row-reader
)
664 '(((#(:null
:null
)))))))))
666 (test row-array-table-nulls-binary
667 (with-binary-row-values
668 (with-test-connection
669 (exec-query connection
"create table test (a integer[])")
672 (prepare-query connection
"integer-array-insert" "insert into test values ($1)")
673 (exec-prepared connection
"integer-array-insert" (list "{{0,0},{0,0}}"))
674 (exec-prepared connection
"integer-array-insert" (list "{{1,1}}"))
675 (exec-prepared connection
"integer-array-insert" (list "{{2,2}, {2,2}}"))
676 (exec-prepared connection
"integer-array-insert" (list "{{3,3}}"))
677 (exec-prepared connection
"integer-array-insert" (list "{{4,4}}"))
681 "select row(a[2:45]) from test"
683 '(((#2A
((0 0)))) ((NIL)) ((#2A
((2 2)))) ((NIL)) ((NIL))))))
684 (exec-query connection
"drop table test")))))
687 (with-test-connection
688 (is (equalp (exec-query connection
"select array_agg(row(1,2,3));" 'list-row-reader
)
689 '(("{\"(1,2,3)\"}"))))))
691 (test array-row-binary
692 (with-test-connection
693 (cl-postgres::with-binary-row-values
694 (is (equalp (exec-query connection
"select array_agg(row(1,2,3));" 'list-row-reader
)