[pg-cvs] CVS pg
emarsden
emarsden at common-lisp.net
Sat Sep 23 12:24:29 UTC 2006
Update of /project/pg/cvsroot/pg
In directory clnet:/tmp/cvs-serv3433
Modified Files:
README NEWS TODO sysdep.lisp
Log Message:
- on CL implementations that support Unix sockets, the HOST argument
to PG-CONNECT may designate the directory containing the local
PostgreSQL unix socket (often "/var/run/postgresql/"). The HOST
argument is assumed to designate a local directory rather than a
hostname when its first character is #\/. You may need to modify
authentication options in the PostgreSQL configuration file
pg_hba.conf to allow connections over a unix-domain socket where
the databse username is not equal to your ident tokens. This is an
incompatible change to previous support for unix-domain sockets
with CMUCL (previously a HOST of NIL told pg-dot-lisp to connect
to a unix-domain socket whose name was hardwired into the library).
This support currently exists for SBCL, CMUCL and OpenMCL.
--- /project/pg/cvsroot/pg/README 2006/09/18 19:09:25 1.8
+++ /project/pg/cvsroot/pg/README 2006/09/23 12:24:28 1.9
@@ -1,8 +1,7 @@
pg.lisp -- socket level interface to the PostgreSQL RDBMS for Common Lisp
Author: Eric Marsden <eric.marsden at free.fr>
- Time-stamp: <2006-09-18 emarsden>
- Version: 0.23
+ Version: 0.24
Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006 Eric Marsden
@@ -54,12 +53,16 @@
(pg-connect dbname user &key password host port) -> connection
Connect to the database DBNAME on HOST (defaults to localhost) at
- PORT (defaults to 5432), and log in as USER. If HOST is nil,
- attempt to connect to the localhost using a Unix domain socket;
- otherwise the connection is established using TCP/IP. If the
- database requires a password, send PASSWORD (as clear text unless
- the backend demands crypt() authentication). Set the output date
- type to 'ISO', and initialize our type parser tables.
+ PORT (defaults to 5432), and log in as USER. If HOST designates
+ an absolute pathname (its first character is #\/), attempt to
+ connect to the localhost using a Unix domain socket that resides
+ in that directory (for example "/var/run/postgresql/"); otherwise
+ HOST designates a hostname and the connection is established
+ using TCP/IP. Connections to unix sockets are not supported on
+ all implementations. If the database requires a password, send
+ PASSWORD (as clear text unless the backend demands crypt()
+ authentication). Set the output date type to 'ISO', and
+ initialize our type parser tables.
(pg-exec connection &rest sql) -> pgresult
Concatenate the SQL strings and send to the backend. Retrieve
--- /project/pg/cvsroot/pg/NEWS 2004/08/11 13:26:41 1.3
+++ /project/pg/cvsroot/pg/NEWS 2006/09/23 12:24:28 1.4
@@ -1,5 +1,30 @@
+=== Version 0.22, 2006-09-23 ===========================================
-=== Version 0.21, 2003-xxxx ============================================
+ - improved support for character encodings; see variable
+ *PG-CLIENT-ENCODING* (UTF8 encoding tested with SBCL and CLISP
+ with PostgreSQL 8.1).
+
+ - fixes to the support for prepared statements (or "execution plans";
+ see the README for details of the API) on the v3 frontend/backend
+ protocol.
+
+ - on CL implementations that support Unix sockets, the HOST argument
+ to PG-CONNECT may designate the directory containing the local
+ PostgreSQL unix socket (often "/var/run/postgresql/"). The HOST
+ argument is assumed to designate a local directory rather than a
+ hostname when its first character is #\/. You may need to modify
+ authentication options in the PostgreSQL configuration file
+ pg_hba.conf to allow connections over a unix-domain socket where
+ the databse username is not equal to your ident tokens. This is an
+ incompatible change to previous support for unix-domain sockets
+ with CMUCL (previously a HOST of NIL told pg-dot-lisp to connect
+ to a unix-domain socket whose name was hardwired into the library).
+ This support currently exists for SBCL, CMUCL and OpenMCL.
+
+ - many other bugfixes
+
+
+=== Version 0.21, 2003-05-05 ===========================================
- added support for the v3 frontend/backend protocol, used by
PostgreSQL version 7.4 and up (thanks for Peter Van Eynde).
--- /project/pg/cvsroot/pg/TODO 2004/08/11 13:26:41 1.2
+++ /project/pg/cvsroot/pg/TODO 2006/09/23 12:24:28 1.3
@@ -13,9 +13,6 @@
- in PG-CONNECT, use getaddrinfo_all() to try connecting to each
possible address for a hostname
-
- - the whole bind saga
-
- maybe use CancelRequest to back out of error with grace?
- we should return the oid of the object on inserts
--- /project/pg/cvsroot/pg/sysdep.lisp 2006/09/18 21:33:10 1.14
+++ /project/pg/cvsroot/pg/sysdep.lisp 2006/09/23 12:24:28 1.15
@@ -1,16 +1,17 @@
;;; sysdep.lisp -- system-dependent parts of pg-dot-lisp
;;;
;;; Author: Eric Marsden <eric.marsden at free.fr>
-;;; Time-stamp: <2006-09-18 emarsden>
+;;; Time-stamp: <2006-09-20 emarsden>
;;
;;
(in-package :postgresql)
-#+allegro (require :socket)
-#+lispworks (require "comm")
-#+cormanlisp (require :sockets)
-#+armedbear (require :socket)
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ #+allegro (require :socket)
+ #+lispworks (require "comm")
+ #+cormanlisp (require :sockets)
+ #+armedbear (require :socket))
(defmacro %sysdep (desc &rest forms)
@@ -88,18 +89,21 @@
#+cmu
(defun socket-connect (port host)
(declare (type integer port))
- (handler-case
- (let ((fd (if host
- (ext:connect-to-inet-socket host port)
- (ext:connect-to-unix-socket
- (format nil "/var/run/postgresql/.s.PGSQL.~D" port)))))
- (sys:make-fd-stream fd :input t :output t
- :element-type '(unsigned-byte 8)))
- (error (e)
- (error 'connection-failure
- :host host
- :port port
- :transport-error e))))
+ (let ((host (if (typep host 'pathname)
+ (namestring host)
+ host)))
+ (handler-case
+ (let ((fd (if (eql #\/ (char host 0))
+ (ext:connect-to-unix-socket
+ (format nil "~A.s.PGSQL.~D" (string host) port))
+ (ext:connect-to-inet-socket host port))))
+ (sys:make-fd-stream fd :input t :output t
+ :element-type '(unsigned-byte 8)))
+ (error (e)
+ (error 'connection-failure
+ :host host
+ :port port
+ :transport-error e)))))
;; this doesn't currently work, because WRITE-SEQUENCE is not
;; implemented
@@ -129,22 +133,6 @@
(error 'connection-failure :host host :port port))))
-#+(and db-sockets broken)
-(defun socket-connect (port host)
- (declare (type integer port))
- (handler-case
- (let ((s (sockets:make-inet-socket :stream :tcp))
- (num (car (sockets:host-ent-addresses
- (sockets:get-host-by-name host)))))
- (sockets:socket-connect s num port)
- (sockets:socket-make-stream s :element-type '(unsigned-byte 8)
- :input t :output t :buffering :none))
- (error (e)
- (error 'connection-failure
- :host host
- :port port
- :transport-error e))))
-
#+sbcl
(defun socket-connect (port host-name)
(declare (type integer port))
@@ -193,6 +181,8 @@
(comm:open-tcp-stream host port
:element-type '(unsigned-byte 8)
:direction :io)
+ ;; note that Lispworks (at least 4.3) does not signal an error if
+ ;; the hostname cannot be resolved; it simply returns NIL
(error (e)
(error 'connection-failure
:host host
@@ -218,24 +208,27 @@
#+openmcl
(defun socket-connect (port host)
(declare (type integer port))
- (handler-case
- (if host
- (make-socket :address-family :internet
- :type :stream
- :connect :active
- :format :binary
- :remote-host host
- :remote-port port)
- (make-socket :address-family :file
- :type :stream
- :connect :active
- :format :binary
- :remote-filename (format nil "/var/run/postgresql/.s.PGSQL.~D" port)))
- (error (e)
- (error 'connection-failure
- :host host
- :port port
- :transport-error e))))
+ (let ((host (if (typep host 'pathname)
+ (namestring host)
+ host)))
+ (handler-case
+ (if (eql #\/ (char host 0))
+ (make-socket :address-family :file
+ :type :stream
+ :connect :active
+ :format :binary
+ :remote-filename (format nil "~A.s.PGSQL.~D" (string host) port))
+ (make-socket :address-family :internet
+ :type :stream
+ :connect :active
+ :format :binary
+ :remote-host host
+ :remote-port port))
+ (error (e)
+ (error 'connection-failure
+ :host host
+ :port port
+ :transport-error e)))))
;; from John DeSoi
#+(and mcl (not openmcl))
@@ -325,7 +318,7 @@
(defvar *pg-client-encoding*)
(defun implementation-name-for-encoding (encoding)
- (%sysdep "client encoding to external format name"
+ (%sysdep "convert from client encoding to external format name"
#+(and clisp unicode)
(cond ((string-equal encoding "SQL_ASCII") charset:ascii)
((string-equal encoding "LATIN1") charset:iso-8859-1)
@@ -344,12 +337,12 @@
((string-equal encoding "LATIN9") :latin9)
((string-equal encoding "UTF8") :utf8)
(t (error "unknown encoding ~A" encoding)))
- #+(or cmu gcl ecl abcl openmcl)
+ #+(or cmu gcl ecl abcl openmcl lispworks)
nil))
(defun convert-string-to-bytes (string &optional (encoding *pg-client-encoding*))
(declare (type string string))
- (%sysdep "convert string to bytes"
+ (%sysdep "convert string to octet-array"
#+(and clisp unicode)
(ext:convert-string-to-bytes string (implementation-name-for-encoding encoding))
#+(and allegro ics)
@@ -358,7 +351,7 @@
#+(and :sbcl :sb-unicode)
(sb-ext:string-to-octets string
:external-format (implementation-name-for-encoding encoding))
- #+(or cmu gcl ecl abcl openmcl)
+ #+(or cmu gcl ecl abcl openmcl lispworks)
(if (member encoding '("SQL_ASCII" "LATIN1" "LATIN9") :test #'string-equal)
(let ((octets (make-array (length string) :element-type '(unsigned-byte 8))))
(map-into octets #'char-code string))
@@ -376,7 +369,7 @@
;; for implementations that have no support for character
;; encoding, we assume that the encoding is an octet-for-octet
;; encoding, and convert directly
- #+(or cmu (and sbcl (not :sb-unicode)) gcl ecl abcl openmcl)
+ #+(or cmu (and sbcl (not :sb-unicode)) gcl ecl abcl openmcl lispworks)
(let ((string (make-string (length bytes))))
(map-into string #'code-char bytes))))
More information about the Pg-cvs
mailing list