From emarsden at common-lisp.net Sun Jul 17 13:46:51 2005 From: emarsden at common-lisp.net (Eric Marsden) Date: Sun, 17 Jul 2005 15:46:51 +0200 (CEST) Subject: [pg-cvs] CVS update: pg/parsers.lisp pg/sysdep.lisp pg/v3-protocol.lisp Message-ID: <20050717134651.C77AB8852B@common-lisp.net> Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv32538 Modified Files: parsers.lisp sysdep.lisp v3-protocol.lisp Log Message: Three fixes from Bj??rn Lindberg : - Two trivial bugs with regards to use with Allegro - Handling of the special timestamp values infinity and -infinity. They gave an error, but now returns the symbols :INFINITY and :-INFINITY respectively. - A bug in the version 3 of the protocol, where it would return NIL for fields in the database containing the empty string, rather than an empty string. Date: Sun Jul 17 15:46:50 2005 Author: emarsden Index: pg/parsers.lisp diff -u pg/parsers.lisp:1.6 pg/parsers.lisp:1.7 --- pg/parsers.lisp:1.6 Tue Sep 7 14:52:19 2004 +++ pg/parsers.lisp Sun Jul 17 15:46:50 2005 @@ -170,9 +170,14 @@ ;; for a fix for timestamp format in PostgreSQL 7.3 (with or without ;; tz, with or without milliseconds). (defun timestamp-parser (str) - (multiple-value-bind (year month day hours minutes seconds) - (parse-timestamp str) - (encode-universal-time seconds minutes hours day month year))) + ;; Test for the special values 'infinity' and '-infinity' + (cond ((digit-char-p (schar str 0)) + (multiple-value-bind (year month day hours minutes seconds) + (parse-timestamp str) + (encode-universal-time seconds minutes hours day month year))) + ((equal str "infinity") :infinity) + ((equal str "-infinity") :-infinity) + (t (error "Unknown special timestamp value ~A" str)))) (defun precise-timestamp-parser (str) (multiple-value-bind (year month day hours minutes seconds milliseconds) Index: pg/sysdep.lisp diff -u pg/sysdep.lisp:1.7 pg/sysdep.lisp:1.8 --- pg/sysdep.lisp:1.7 Wed May 4 22:51:35 2005 +++ pg/sysdep.lisp Sun Jul 17 15:46:50 2005 @@ -1,7 +1,7 @@ ;;; sysdep.lisp -- system-dependent parts of pg-dot-lisp ;;; ;;; Author: Eric Marsden -;;; Time-stamp: <2004-04-23 emarsden> +;;; Time-stamp: <2005-07-17 emarsden> ;; ;; @@ -261,7 +261,6 @@ end) -;; there seems to be a bug in ECL's binary socket streams; data is corrupted #+ecl (defun socket-connect (port host) (declare (type integer port)) @@ -320,8 +319,9 @@ (%sysdep "convert string to bytes" #+(and clisp unicode) (ext:convert-string-to-bytes string encoding) - #+(and acl ics) - (excl:string-to-octets string :external-format encoding) + #+(and allegro ics) + (excl:string-to-octets string :null-terminate nil + :external-format encoding) #+(and :sbcl :sb-unicode) (sb-ext:string-to-octets string :external-format (sbcl-ext-form-from-client-encoding encoding)) #+(or cmu sbcl gcl ecl) @@ -333,8 +333,8 @@ (%sysdep "convert octet-array to string" #+(and clisp unicode) (ext:convert-string-from-bytes bytes encoding) - #+(and acl ics) - (ext:octets-to-string bytes :external-format encoding) + #+(and allegro ics) + (excl:octets-to-string bytes :external-format encoding) #+(and :sbcl :sb-unicode) (sb-ext:octets-to-string bytes :external-format encoding) ;; for implementations that have no support for character Index: pg/v3-protocol.lisp diff -u pg/v3-protocol.lisp:1.15 pg/v3-protocol.lisp:1.16 --- pg/v3-protocol.lisp:1.15 Mon Sep 20 00:32:33 2004 +++ pg/v3-protocol.lisp Sun Jul 17 15:46:50 2005 @@ -270,8 +270,6 @@ "Reads a string of LENGTH characters from the packet") (:method ((packet pg-packet) (length (eql -1))) nil) - (:method ((packet pg-packet) (length (eql 0))) - nil) (:method ((packet pg-packet) (length integer)) (when (< length 0) (error "length cannot be negative. is: ~S" From emarsden at common-lisp.net Sun Jul 17 13:49:44 2005 From: emarsden at common-lisp.net (Eric Marsden) Date: Sun, 17 Jul 2005 15:49:44 +0200 (CEST) Subject: [pg-cvs] CVS update: pg/pg-tests.lisp Message-ID: <20050717134944.4F15C8852B@common-lisp.net> Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv479 Modified Files: pg-tests.lisp Log Message: Minor fix to tests for PostgreSQL 8.0: the MONEY type is deprecated. Date: Sun Jul 17 15:49:43 2005 Author: emarsden Index: pg/pg-tests.lisp diff -u pg/pg-tests.lisp:1.9 pg/pg-tests.lisp:1.10 --- pg/pg-tests.lisp:1.9 Tue Sep 7 14:52:19 2004 +++ pg/pg-tests.lisp Sun Jul 17 15:49:43 2005 @@ -10,7 +10,8 @@ (defpackage :pg-tests (:use :cl :pg - #+cmu :fwrappers)) + #+cmu :fwrappers) + (:export #:test)) (in-package :pg-tests) (defmacro with-pg-connection/2 ((con &rest open-args) &body body) @@ -387,8 +388,8 @@ ;; client encoding supported since PostgreSQL v7.1 (format t "Client encoding is ~A~%" (pg-client-encoding conn)) (format t "Date style is ~A~%" (pg-date-style conn)) - (let ((r2 (pg-exec conn "CREATE TABLE pgltest (a int, b float, c money)")) - (r3 (pg-exec conn "INSERT INTO pgltest VALUES (3, -1234.5e67, '$123.45')")) + (let ((r2 (pg-exec conn "CREATE TABLE pgltest (a int, b float, c numeric)")) + (r3 (pg-exec conn "INSERT INTO pgltest VALUES (3, -1234.5e67, 123.45)")) (r4 (pg-exec conn "DROP TABLE pgltest"))) (format t "~%==============================================~%") (format t "status of CREATE is ~s~%" (pg-result r2 :status)) From emarsden at common-lisp.net Sun Jul 17 15:46:33 2005 From: emarsden at common-lisp.net (Eric Marsden) Date: Sun, 17 Jul 2005 17:46:33 +0200 (CEST) Subject: [pg-cvs] CVS update: pg/sysdep.lisp Message-ID: <20050717154633.388B88852B@common-lisp.net> Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv8991 Modified Files: sysdep.lisp Log Message: Use the updated MD5 code, that operates on octet arrays rather than strings. Date: Sun Jul 17 17:46:32 2005 Author: emarsden Index: pg/sysdep.lisp diff -u pg/sysdep.lisp:1.8 pg/sysdep.lisp:1.9 --- pg/sysdep.lisp:1.8 Sun Jul 17 15:46:50 2005 +++ pg/sysdep.lisp Sun Jul 17 17:46:32 2005 @@ -1,6 +1,6 @@ ;;; sysdep.lisp -- system-dependent parts of pg-dot-lisp ;;; -;;; Author: Eric Marsden +;;; Author: Eric Marsden ;;; Time-stamp: <2005-07-17 emarsden> ;; ;; @@ -11,11 +11,10 @@ #+allegro (require :socket) #+lispworks (require "comm") #+cormanlisp (require :sockets) - #+sbcl (progn (require :asdf) (require :sb-bsd-sockets) (require :sb-md5)) + #+sbcl (require :sb-bsd-sockets) #+(and mcl (not openmcl)) (require "OPENTRANSPORT")) - (defmacro %sysdep (desc &rest forms) (when (null forms) (error "No system dependent code to ~A" desc)) @@ -44,8 +43,9 @@ (defun md5-digest (string &rest strings) (declare (type simple-string string)) - (let ((vec (md5:md5sum-sequence - (apply #'concatenate 'string string strings)))) + (let ((vec (md5sum-sequence + (map '(vector (unsigned-byte 8)) #'char-code + (apply #'concatenate 'string string strings))))) (format nil "~(~{~2,'0X~}~)" (coerce vec 'list)))) (defun md5-encode-password (user password salt) From emarsden at common-lisp.net Sun Jul 17 15:48:08 2005 From: emarsden at common-lisp.net (Eric Marsden) Date: Sun, 17 Jul 2005 17:48:08 +0200 (CEST) Subject: [pg-cvs] CVS update: pg/large-object.lisp pg/v2-protocol.lisp pg/v3-protocol.lisp pg/lowlevel.lisp pg/pg.lisp Message-ID: <20050717154808.905F68852B@common-lisp.net> Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv9011 Modified Files: large-object.lisp v2-protocol.lisp v3-protocol.lisp lowlevel.lisp pg.lisp Log Message: Make PGLO-READ a generic function, with specializations on the v2 and v3 protocols. The difference is necessary because the v2 protocol reads large-object data in text, whereas the v3 protocol changed to use a binary format. Date: Sun Jul 17 17:48:06 2005 Author: emarsden Index: pg/large-object.lisp diff -u pg/large-object.lisp:1.2 pg/large-object.lisp:1.3 --- pg/large-object.lisp:1.2 Fri Aug 13 18:50:37 2004 +++ pg/large-object.lisp Sun Jul 17 17:48:06 2005 @@ -1,6 +1,6 @@ ;;; large-object.lisp -- support for BLOBs ;;; -;;; Author: Eric Marsden +;;; Author: Eric Marsden ;; ;; ;; Sir Humphrey: Who is Large and to what does he object? @@ -81,10 +81,10 @@ (defun pglo-close (connection fd) (fn connection "lo_close" t fd)) -;; note that the 3rd argument means that we are reading data in binary -;; format, not text -(defun pglo-read (connection fd bytes) - (fn connection "loread" t fd bytes)) +;; pglo-read has moved to v2-protocol.lisp and v3-protocol.lisp +;; +;; the difference between the v3 and v2 protocols is that in the former case +;; data is read in binary format, whereas in the latter data is read as text. (defun pglo-write (connection fd buf) (fn connection "lowrite" t fd buf)) Index: pg/v2-protocol.lisp diff -u pg/v2-protocol.lisp:1.4 pg/v2-protocol.lisp:1.5 --- pg/v2-protocol.lisp:1.4 Thu Apr 1 20:35:19 2004 +++ pg/v2-protocol.lisp Sun Jul 17 17:48:06 2005 @@ -1,6 +1,6 @@ ;;; v2-protocol.lisp -- frontend/backend protocol prior to PostgreSQL 7.4 ;;; -;;; Author: Eric Marsden +;;; Author: Eric Marsden (in-package :postgresql) @@ -197,6 +197,9 @@ ((stringp arg) (send-int connection (length arg) 4) (send-string connection arg)) + ((vectorp arg) + (send-int connection (length arg) 4) + (send-octets connection arg)) (t (error 'protocol-error :reason (format nil "Unknown fastpath type ~s" arg))))) (%flush connection) @@ -293,6 +296,12 @@ (defun handle-notice (connection) (push (%read-cstring (pgcon-stream connection) +MAX_MESSAGE_LEN+) (pgcon-notices connection))) + + +;; split out from large-object.lisp +(defmethod pglo-read ((connection pgcon-v2) fd bytes) + (let ((octets (fn connection "loread" nil fd bytes))) + (map '(vector (unsigned-byte 8)) #'char-code octets))) ;; EOF Index: pg/v3-protocol.lisp diff -u pg/v3-protocol.lisp:1.16 pg/v3-protocol.lisp:1.17 --- pg/v3-protocol.lisp:1.16 Sun Jul 17 15:46:50 2005 +++ pg/v3-protocol.lisp Sun Jul 17 17:48:06 2005 @@ -965,4 +965,11 @@ (defmethod pg-close-portal ((connection pgcon-v3) (portal string)) (pg-close connection portal #\P)) + +;; split out from large-object.lisp +(defmethod pglo-read ((connection pgcon-v3) fd bytes) + (fn connection "loread" t fd bytes)) + + + ;; EOF Index: pg/lowlevel.lisp diff -u pg/lowlevel.lisp:1.3 pg/lowlevel.lisp:1.4 --- pg/lowlevel.lisp:1.3 Mon Mar 8 19:12:45 2004 +++ pg/lowlevel.lisp Sun Jul 17 17:48:06 2005 @@ -1,7 +1,7 @@ ;;; lowlevel.lisp -- lowlevel network ;;; ;;; Author: Eric Marsden -;;; Time-stamp: <2004-03-08 emarsden> +;;; Time-stamp: <2005-07-17 emarsden> (in-package :postgresql) @@ -117,6 +117,10 @@ :initial-element 0 :element-type '(unsigned-byte 8)) stream)))) + +(defun send-octets (connection buffer) + (declare (type (vector (unsigned-byte 8) *) buffer)) + (write-sequence buffer (pgcon-stream connection))) ;; highest order bits first (defun send-int (connection int bytes) Index: pg/pg.lisp diff -u pg/pg.lisp:1.4 pg/pg.lisp:1.5 --- pg/pg.lisp:1.4 Mon Mar 8 16:01:53 2004 +++ pg/pg.lisp Sun Jul 17 17:48:06 2005 @@ -1,10 +1,10 @@ ;;; pg.lisp -- socket level interface to the PostgreSQL RDBMS for Common Lisp ;; -;; Author: Eric Marsden -;; Time-stamp: <2004-03-08 emarsden> -;; Version: 0.21 +;; Author: Eric Marsden +;; Time-stamp: <2005-07-17 emarsden> +;; Version: 0.22 ;; -;; Copyright (C) 1999,2000,2001,2002,2003 Eric Marsden +;; Copyright (C) 1999,2000,2001,2002,2003,2004,2005 Eric Marsden ;; ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Library General Public @@ -20,10 +20,7 @@ ;; License along with this library; if not, write to the Free ;; Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;; -;; Please send suggestions and bug reports to -;; The latest version of this package should be available from -;; -;; +;; Please send suggestions and bug reports to ;;; Overview ========================================================= @@ -42,27 +39,13 @@ ;; ;; See the README for API documentation. -;; This code has been tested or reported to work with -;; -;; * CMUCL 18d and 18e on Solaris/SPARC and Linux/x86 -;; * SBCL 0.8 on Linux/x86 and Linux/PowerPC -;; * CLISP 2.31 on Linux/PowerPC, Solaris and Linux/x86 -;; * OpenMCL 0.13.6 on Linux/PowerPC and MacOS 10.2 -;; * Armed Bear Lisp version 0.20 -;; * Lispworks 4.3 personal edition for MacOS X and win32 -;; * Allegro CL 6.1 trial Linux/x86 -;; * ECL as of 2003-10-10 -;; * PostgreSQL 6.5, 7.0, 7.1.2, 7.2, 7.3 (and equivalent "Red Hat -;; Database" versions) -;; -;; ;; Please note that your postmaster has to be started with the `-i' ;; option in order for it to accept TCP/IP connections (typically this ;; is not the default setting). See the PostgreSQL documentation at ;; for more information. ;; ;; Thanks to Marc Battyani for the LW port and for bugfixes, to -;; Johannes Gr?dem for a fix to parsing of DATE +;; Johannes Gr??dem for a fix to parsing of DATE ;; types, to Doug McNaught and Howard Ding for bugfixes, to Ernst ;; Jeschek for pointing out a bug in float parsing, to Brian Lui for ;; providing fixes for ACL6, to James Anderson for providing a fix for @@ -222,6 +205,11 @@ (defgeneric pg-close-portal (connection portal) (:documentation "Closes a prepared statement")) + +(defgeneric pglo-read (connection fd bytes) + (:documentation + "Read from a large object on file descriptor FD.")) + ;; first attempt to connect to connect using the v3 protocol; if this ;; results in an ErrorResponse we close the connection and retry using From emarsden at common-lisp.net Sun Jul 17 15:49:15 2005 From: emarsden at common-lisp.net (Eric Marsden) Date: Sun, 17 Jul 2005 17:49:15 +0200 (CEST) Subject: [pg-cvs] CVS update: pg/README Message-ID: <20050717154915.890C28852B@common-lisp.net> Update of /project/pg/cvsroot/pg In directory common-lisp.net:/tmp/cvs-serv9050 Modified Files: README Log Message: Note that the current code has been tested against PostgreSQL 8.0 (with both v2 and v3 protocol versions). Date: Sun Jul 17 17:49:15 2005 Author: emarsden Index: pg/README diff -u pg/README:1.3 pg/README:1.4 --- pg/README:1.3 Thu Apr 1 20:35:19 2004 +++ pg/README Sun Jul 17 17:49:14 2005 @@ -1,7 +1,7 @@ pg.lisp -- socket level interface to the PostgreSQL RDBMS for Common Lisp - Author: Eric Marsden - Time-stamp: <2004-04-01 emarsden> + Author: Eric Marsden + Time-stamp: <2005-07-17 emarsden> Version: 0.22 Copyright (C) 1999,2000,2001,2002,2003,2004 Eric Marsden @@ -246,13 +246,14 @@ This code has been tested or reported to work with - * CMUCL 18d and 18e on Solaris/SPARC and Linux/x86 + * CMUCL 18d, 18e, 19a on Solaris/SPARC and Linux/x86 + * SBCL 0.9.2 on Linux/x86 * CLISP 2.30 on LinuxPPC and SPARC * OpenMCL 0.13.x and 0.14.x on LinuxPPC * Armed Bear Common Lisp * ACL 6.1 trial/x86 * Lispworks 4.3 on Linux and Windows - * PostgreSQL versions 6.5, 7.0, 7.1.2, 7.2, 7.3, 7.4 + * PostgreSQL versions 6.5, 7.0, 7.1.2, 7.2, 7.3, 7.4, 8.0 You may be interested in using "pg-psql" by Harley Gorrell, which