(defpackage :clsql-postgresql-socket3
(:use #:common-lisp #:clsql-sys #:postgresql-socket3)
(:export #:postgresql-socket3-database)
- (:documentation "This is the CLSQL socket interface (protocol version 3) to PostgreSQL."))
+ (:documentation
+ "This is the CLSQL socket interface (protocol version 3) to PostgreSQL."))
(in-package #:clsql-postgresql-socket3)
(defvar *sqlreader* (cl-postgres:copy-sql-readtable))
-(let ((dt-fn (lambda (useconds-since-2000)
- (let ((sec (truncate
- (/ useconds-since-2000
- 1000000)))
- (usec (mod useconds-since-2000
- 1000000)))
- (clsql:make-time :year 2000 :second sec :usec usec)))))
+
+
+(labels ((d-fn (days-since-2000)
+ (clsql:make-date :year 2000 :day (+ 1 days-since-2000)))
+ (dt-tz-fn (useconds-since-2000
+ &aux (dt (dt-fn useconds-since-2000)))
+ (setf (clsql-sys::time-is-utc? dt) t)
+ dt)
+ (dt-fn (useconds-since-2000)
+ (multiple-value-bind (sec usec)
+ (floor useconds-since-2000 1000000)
+ (clsql:make-time :year 2000 :second sec :usec usec))))
(cl-postgres:set-sql-datetime-readers
:table *sqlreader*
- :date (lambda (days-since-2000)
- (clsql:make-date :year 2000 :day (+ 1 days-since-2000)))
- :timestamp dt-fn
- :timestamp-with-timezone dt-fn))
+ :timestamp #'dt-fn
+ :timestamp-with-timezone #'dt-tz-fn
+ :date #'d-fn))
(etypecase host
(null
"localhost")
+ (keyword "unix")
(pathname (namestring host))
(string host))
(when port
(declare (type (signed-byte 32) cl-postgres::size))
(if (eq cl-postgres::size -1)
nil
- (funcall (cl-postgres::field-interpreter cl-postgres::field)
- stream cl-postgres::size)))))
+ (funcall (cl-postgres::field-interpreter cl-postgres::field)
+ stream cl-postgres::size)))))
(let ((results (loop :while (cl-postgres:next-row)
:collect (loop :for field :across fields
:collect (cl-postgres:next-field field))))
(clsql-sys:initialize-database-type :database-type :postgresql-socket3))
+
+;; TODO: there is a good chance this could always return nil as cl-postgres probably
+;; handles this nonsense anyway
+(defmethod clsql-sys::database-escape-backslashes ((database postgresql-socket3-database))
+ (let* ((it (gethash "standard_conforming_strings"
+ (cl-postgres:connection-parameters
+ (slot-value database 'connection))))
+ (sit (and it (string it))))
+ (and it (not (string-equal sit "on")))))