X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=sidebyside;f=db-postgresql%2Fpostgresql-sql.lisp;h=5355972a63fc26fca77e33c9213f51df30c28ea3;hb=e5744a78271044484b3399d4fc1d55b3e8808784;hp=76cab66a214f27e70cf4ec8d18cacb7609561945;hpb=c4da3cfcbb955395d8a556e1f89aadad696302b7;p=clsql.git diff --git a/db-postgresql/postgresql-sql.lisp b/db-postgresql/postgresql-sql.lisp index 76cab66..5355972 100644 --- a/db-postgresql/postgresql-sql.lisp +++ b/db-postgresql/postgresql-sql.lisp @@ -479,45 +479,37 @@ (defmethod database-create (connection-spec (type (eql :postgresql))) (destructuring-bind (host name user password) connection-spec - (declare (ignore password)) - (let ((asdf::*verbose-out* (make-string-output-stream))) - (unwind-protect - (let* ((status (asdf:run-shell-command - "su -c ~A createdb -h~A ~A" - user - (if host host "localhost") - name)) - (result (get-output-stream-string asdf::*verbose-out*))) - - (if (search "database creation failed: ERROR:" result) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error - (format nil "database-create failed: ~s" result)) - t)) - (close asdf::*verbose-out*))))) + (declare (ignore user password)) + (multiple-value-bind (output status) + (clsql-base-sys:command-output "createdb -h~A ~A" + (if host host "localhost") + name) + (if (or (not (zerop status)) + (search "database creation failed: ERROR:" output)) + (error 'clsql-access-error + :connection-spec connection-spec + :database-type type + :error + (format nil "database-create failed: ~A" + output)) + t)))) (defmethod database-destroy (connection-spec (type (eql :postgresql))) (destructuring-bind (host name user password) connection-spec - (declare (ignore password)) - (let ((asdf::*verbose-out* (make-string-output-stream))) - (unwind-protect - (let* ((status (asdf:run-shell-command - "su -c ~A dropdb -h~A ~A" - user - (if host host "localhost") - name)) - (result (get-output-stream-string asdf::*verbose-out*))) - - (if (search "database removal failed: ERROR:" result) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error - (format nil "database-destroy failed: ~s" result)) - t)) - (close asdf::*verbose-out*))))) + (declare (ignore user password)) + (multiple-value-bind (output status) + (clsql-base-sys:command-output "dropdb -h~A ~A" + (if host host "localhost") + name) + (if (or (not (zerop status)) + (search "database removal failed: ERROR:" output)) + (error 'clsql-access-error + :connection-spec connection-spec + :database-type type + :error + (format nil "database-destory failed: ~A" + output)) + t)))) (defmethod database-probe (connection-spec (type (eql :postgresql))) @@ -525,9 +517,11 @@ (let ((database (database-connect (list host "template1" user password) type))) (unwind-protect - (find name (database-query "select datname from pg_database" - database :auto) - :key #'car :test #'string-equal) + (when + (find name (database-query "select datname from pg_database" + database :auto) + :key #'car :test #'string-equal) + t) (database-disconnect database)))))