X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-postgresql-socket%2Fpostgresql-socket-api.lisp;h=e9d23f3fb33617a375ea7e0d7965ebc7a6a8a55a;hb=0e43efc5b776edd86d304e103123944a84efd9a4;hp=66b2912a9f84291e8124e612850ac7e88d972804;hpb=36509b8d390e94b2b0f8e681c09d5e89452978d8;p=clsql.git diff --git a/db-postgresql-socket/postgresql-socket-api.lisp b/db-postgresql-socket/postgresql-socket-api.lisp index 66b2912..e9d23f3 100644 --- a/db-postgresql-socket/postgresql-socket-api.lisp +++ b/db-postgresql-socket/postgresql-socket-api.lisp @@ -4,7 +4,7 @@ ;;;; ;;;; Name: postgresql-socket-api.lisp ;;;; Purpose: Low-level PostgreSQL interface using sockets -;;;; Authors: Kevin M. Rosenberg based on original code by Pierre R. Mai +;;;; Authors: Kevin M. Rosenberg based on original code by Pierre R. Mai ;;;; Created: Feb 2002 ;;;; ;;;; $Id$ @@ -236,7 +236,7 @@ socket interface" (defvar *crypt-library-loaded* nil) (unless *crypt-library-loaded* - (uffi:load-foreign-library + (uffi:load-foreign-library (uffi:find-foreign-library "libcrypt" '(#+(or 64bit x86-64) "/usr/lib64/" "/usr/lib/" "/usr/local/lib/" "/lib/")) @@ -254,7 +254,7 @@ socket interface" "Encrypt a password for transmission to a PostgreSQL server." (uffi:with-cstring (password-cstring password) (uffi:with-cstring (salt-cstring salt) - (uffi:convert-from-cstring + (uffi:convert-from-cstring (crypt password-cstring salt-cstring))))) @@ -334,18 +334,22 @@ socket interface" (etypecase host (pathname ;; Directory to unix-domain socket - (sb-bsd-sockets:socket-connect - (namestring - (make-pathname :name ".s.PGSQL" :type (princ-to-string port) - :defaults host)))) + (let ((sock (make-instance 'sb-bsd-sockets:local-socket + :type :stream))) + (sb-bsd-sockets:socket-connect + sock + (namestring + (make-pathname :name ".s.PGSQL" :type (princ-to-string port) + :defaults host))) + sock)) (string (let ((sock (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))) (sb-bsd-sockets:socket-connect - sock + sock (sb-bsd-sockets:host-ent-address - (sb-bsd-sockets:get-host-by-name host)) + (sb-bsd-sockets:get-host-by-name host)) port) sock)))) @@ -361,9 +365,9 @@ socket interface" #+sbcl (defun open-postgresql-socket-stream (host port) (sb-bsd-sockets:socket-make-stream - (open-postgresql-socket host port) :input t :output t + (open-postgresql-socket host port) :input t :output t :element-type '(unsigned-byte 8))) - + #+allegro (defun open-postgresql-socket-stream (host port) @@ -407,6 +411,19 @@ socket interface" :read-timeout *postgresql-server-socket-timeout*)) )) + +#+clisp +(defun open-postgresql-socket-stream (host port) + (etypecase host + (pathname + (error "Not supported")) + (string + (socket:socket-connect + port host + :element-type '(unsigned-byte 8) + :timeout *postgresql-server-socket-timeout*)))) + + ;;; Interface Functions (defun open-postgresql-connection (&key (host (cmucl-compat:required-argument)) @@ -451,7 +468,7 @@ troubles." connection, if it is still open." (when (postgresql-connection-open-p connection) (close-postgresql-connection connection)) - (let ((socket (open-postgresql-socket-stream + (let ((socket (open-postgresql-socket-stream (postgresql-connection-host connection) (postgresql-connection-port connection)))) (unwind-protect @@ -678,7 +695,7 @@ connection, if it is still open." ) ;; nothing to do (t (setq val (- first-char +char-code-zero+)))) - + (dotimes (i length) (declare (fixnum i)) (setq val (+ @@ -696,7 +713,7 @@ connection, if it is still open." (< ,offset 10)) ,offset nil)))) - + (defun read-double-from-socket (socket length) (declare (fixnum length)) (let ((before-decimal 0) @@ -720,13 +737,13 @@ connection, if it is still open." (setq before-decimal (ascii-digit char)) (unless before-decimal (error "Unexpected value")))) - + (block loop (dotimes (i length) (setq char (read-byte socket)) ;; (format t "~&len:~D, i:~D, char:~D, minusp:~A, decimalp:~A" length i char minusp decimalp) (let ((weight (ascii-digit char))) - (cond + (cond ((and weight (not decimalp)) ;; before decimal point (setq before-decimal (+ weight (* 10 before-decimal)))) ((and weight decimalp) ;; after decimal point @@ -739,19 +756,19 @@ connection, if it is still open." (setq exponent (read-integer-from-socket socket (- length i 1))) (setq exponent (or exponent 0)) (return-from loop)) - (t + (t (break "Unexpected value")) ) ))) (setq result (* (+ (coerce before-decimal 'double-float) - (* after-decimal + (* after-decimal (expt 10 (- decimal-count)))) (expt 10 exponent))) (if minusp (- result) result))) - - + + #+ignore (defun read-double-from-socket (socket length) (let ((result (make-string length)))