X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=db-postgresql%2Fpostgresql-sql.lisp;h=a3f9b885f442c41b6296ebc1740afeb5d2567127;hp=9b4e2503f0b5ac415a64147cad594385c20b6283;hb=ab37892bfa71e0d66021cc73f28cd189be30c81c;hpb=fc58e4fb7d908985389c86adf57ddee6c1dde5d2 diff --git a/db-postgresql/postgresql-sql.lisp b/db-postgresql/postgresql-sql.lisp index 9b4e250..a3f9b88 100644 --- a/db-postgresql/postgresql-sql.lisp +++ b/db-postgresql/postgresql-sql.lisp @@ -16,7 +16,7 @@ (in-package #:cl-user) (defpackage #:clsql-postgresql - (:use #:common-lisp #:clsql-sys #:postgresql #:clsql-uffi) + (:use #:common-lisp #:clsql-sys #:pgsql #:clsql-uffi) (:export #:postgresql-database) (:documentation "This is the CLSQL interface to PostgreSQL.")) @@ -127,12 +127,14 @@ (declare (type pgsql-conn-def connection)) (when (not (eq (PQstatus connection) pgsql-conn-status-type#connection-ok)) - (error 'sql-connection-error - :database-type database-type - :connection-spec connection-spec - :error-id (PQstatus connection) - :message (tidy-error-message - (PQerrorMessage connection)))) + (let ((pqstatus (PQstatus connection)) + (pqmessage (tidy-error-message (PQerrorMessage connection)))) + (PQfinish connection) + (error 'sql-connection-error + :database-type database-type + :connection-spec connection-spec + :error-id pqstatus + :message pqmessage))) (make-instance 'postgresql-database :name (database-name-from-spec connection-spec database-type) @@ -220,7 +222,7 @@ (error 'sql-database-data-error :database database :expression sql-expression - :error-id (PQresultStatus result) + :error-id (PQresultErrorField result +PG-DIAG-SQLSTATE+) :message (tidy-error-message (PQresultErrorMessage result))))) (PQclear result)))))) @@ -304,7 +306,7 @@ (defmethod database-create-large-object ((database postgresql-database)) (lo-create (database-conn-ptr database) - (logior postgresql::+INV_WRITE+ postgresql::+INV_READ+))) + (logior pgsql::+INV_WRITE+ pgsql::+INV_READ+))) #+mb-original @@ -316,7 +318,7 @@ (with-transaction (:database database) (unwind-protect (progn - (setf fd (lo-open ptr object-id postgresql::+INV_WRITE+)) + (setf fd (lo-open ptr object-id pgsql::+INV_WRITE+)) (when (>= fd 0) (when (= (lo-write ptr fd data length) length) (setf result t)))) @@ -334,7 +336,7 @@ (database-execute-command "begin" database) (unwind-protect (progn - (setf fd (lo-open ptr object-id postgresql::+INV_WRITE+)) + (setf fd (lo-open ptr object-id pgsql::+INV_WRITE+)) (when (>= fd 0) (when (= (lo-write ptr fd data length) length) (setf result t)))) @@ -355,7 +357,7 @@ (unwind-protect (progn (database-execute-command "begin" database) - (setf fd (lo-open ptr object-id postgresql::+INV_READ+)) + (setf fd (lo-open ptr object-id pgsql::+INV_READ+)) (when (>= fd 0) (setf length (lo-lseek ptr fd 0 2)) (lo-lseek ptr fd 0 0) @@ -427,7 +429,7 @@ (coerce-string db) (coerce-string user) (let ((connection (PQsetdbLogin host port options tty db user password))) - (declare (type postgresql::pgsql-conn-ptr connection)) + (declare (type pgsql::pgsql-conn-ptr connection)) (unless (eq (PQstatus connection) pgsql-conn-status-type#connection-ok) ;; Connect failed