use oid constants
[postmodern.git] / cl-postgres / simple-date-tests.lisp
blob8d3348ae02e02bb7dd35722b1958a0f4d2634344
2 (defpackage :cl-postgres-simple-date-tests
3 (:use :common-lisp :fiveam :cl-postgres :cl-postgres-error :simple-date)
4 (:export #:prompt-connection #:*test-connection*))
6 (in-package :cl-postgres-simple-date-tests)
8 (defparameter *test-connection* '("test" "test" "" "localhost"))
10 (defun prompt-connection (&optional (list *test-connection*))
11 (flet ((ask (name pos)
12 (format *query-io* "~a (enter to keep '~a'): " name (nth pos list))
13 (finish-output *query-io*)
14 (let ((answer (read-line *query-io*)))
15 (unless (string= answer "") (setf (nth pos list) answer)))))
16 (format *query-io* "~%To run this test, you must configure a database connection.~%")
17 (ask "Database name" 0)
18 (ask "User" 1)
19 (ask "Password" 2)
20 (ask "Hostname" 3)))
22 (defmacro with-simple-date-readtable (&body body)
23 `(let ((*sql-readtable* (simple-date-cl-postgres-glue:simple-date-sql-readtable)))
24 ,@body))
26 (defmacro with-test-connection (&body body)
27 `(let ((connection (apply 'open-database *test-connection*)))
28 (with-simple-date-readtable
29 (unwind-protect (progn ,@body)
30 (close-database connection)))))
32 (def-suite :cl-postgres-simple-date)
33 (in-suite :cl-postgres-simple-date)
35 (test row-timestamp-without-time-zone-binary
36 (with-test-connection
37 (with-binary-row-values
38 (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
39 'list-row-reader))
40 (encode-timestamp 2010 4 5 14 42 21 500))))))
42 (test row-timestamp-with-time-zone-binary
43 (with-test-connection
44 (exec-query connection "set time zone 'GMT'")
45 (with-binary-row-values
46 (destructuring-bind (gmt pdt)
47 (caar
48 (exec-query
49 connection
50 (concatenate 'string
51 "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
52 " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
53 'list-row-reader))
54 (is (time= gmt (encode-timestamp 2010 4 5 14 42 21 500)))
55 (is (time= pdt (encode-timestamp 2010 4 5 6 42 21 500)))))))
57 (test row-timestamp-without-time-zone-array-binary
58 (with-test-connection
59 (with-binary-row-values
60 (is (time= (elt (caaar (exec-query connection "select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
61 'list-row-reader)) 0)
62 (encode-timestamp 2010 4 5 14 42 21 500))))))
64 (test row-time-binary
65 (with-test-connection
66 (with-binary-row-values
67 (is (time= (caaar (exec-query connection "select row('05:00'::time)"
68 'list-row-reader))
69 (encode-time-of-day 5 0))))))
71 (test row-timestamp-binary
72 (with-test-connection
73 (with-binary-row-values
74 (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp)"
75 'list-row-reader))
76 (encode-timestamp 2010 4 5 14 42 21 500))))))