X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=db-postgresql%2Fpostgresql-sql.lisp;h=aad11a0c2aeb1d764be584c50cb551b9e00e13d3;hp=2ab36e0adb524cd526529be2c6af3d8ba6d72e94;hb=d2d49ab13c98bc7a1819a0fd3968268a5567bdc3;hpb=e567409d9fff3f7231c2a0bb69b345e19de2b246 diff --git a/db-postgresql/postgresql-sql.lisp b/db-postgresql/postgresql-sql.lisp index 2ab36e0..aad11a0 100644 --- a/db-postgresql/postgresql-sql.lisp +++ b/db-postgresql/postgresql-sql.lisp @@ -6,8 +6,6 @@ ;;;; Purpose: High-level PostgreSQL interface using UFFI ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id$ -;;;; ;;;; CLSQL users are granted the rights to distribute and use this software ;;;; as governed by the terms of the Lisp Lesser GNU Public License ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. @@ -187,7 +185,7 @@ (error 'sql-database-data-error :database database :expression query-expression - :error-id (PQresultStatus result) + :error-id (PQresultErrorField result +PG-DIAG-SQLSTATE+) :message (tidy-error-message (PQresultErrorMessage result))))) (PQclear result)))))) @@ -269,7 +267,7 @@ (error 'sql-database-data-error :database database :expression query-expression - :error-id (PQresultStatus result) + :error-id (PQresultErrorField result +PG-DIAG-SQLSTATE+) :message (tidy-error-message (PQresultErrorMessage result))) (PQclear result)))))))) @@ -383,33 +381,21 @@ (defmethod database-create (connection-spec (type (eql :postgresql))) (destructuring-bind (host name user password) connection-spec - (declare (ignore user password)) - (multiple-value-bind (output status) - (clsql-sys:command-output "createdb -h~A ~A" - (if host host "localhost") - name) - (if (or (not (zerop status)) - (search "database creation failed: ERROR:" output)) - (error 'sql-database-error - :message - (format nil "createdb failed for postgresql backend with connection spec ~A." - connection-spec)) - t)))) + (let ((database (database-connect (list host "postgres" user password) + type))) + (setf (slot-value database 'clsql-sys::state) :open) + (unwind-protect + (database-execute-command (format nil "create database ~A" name) database) + (database-disconnect database))))) (defmethod database-destroy (connection-spec (type (eql :postgresql))) (destructuring-bind (host name user password) connection-spec - (declare (ignore user password)) - (multiple-value-bind (output status) - (clsql-sys:command-output "dropdb -h~A ~A" - (if host host "localhost") - name) - (if (or (not (zerop status)) - (search "database removal failed: ERROR:" output)) - (error 'sql-database-error - :message - (format nil "dropdb failed for postgresql backend with connection spec ~A." - connection-spec)) - t)))) + (let ((database (database-connect (list host "postgres" user password) + type))) + (setf (slot-value database 'clsql-sys::state) :open) + (unwind-protect + (database-execute-command (format nil "drop database ~A" name) database) + (database-disconnect database))))) (defmethod database-probe (connection-spec (type (eql :postgresql)))