X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-postgresql-socket%2Fpostgresql-socket-sql.lisp;h=50c6899afc0f8c6a4a36fefc0597fdb911967663;hb=a3e1cd20eec3903790c6e8f126345558904488f4;hp=7df3dc7de361498165a6b717d9c2b29d7e1c1f45;hpb=c4da3cfcbb955395d8a556e1f89aadad696302b7;p=clsql.git diff --git a/db-postgresql-socket/postgresql-socket-sql.lisp b/db-postgresql-socket/postgresql-socket-sql.lisp index 7df3dc7..50c6899 100644 --- a/db-postgresql-socket/postgresql-socket-sql.lisp +++ b/db-postgresql-socket/postgresql-socket-sql.lisp @@ -194,6 +194,7 @@ doesn't depend on UFFI." (make-instance 'postgresql-socket-database :name (database-name-from-spec connection-spec database-type) + :database-type :postgresql-socket :connection-spec connection-spec :connection connection))))) @@ -430,26 +431,52 @@ doesn't depend on UFFI." (defmethod database-create (connection-spec (type (eql :postgresql-socket))) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error "Unable to create databases on a socket connection.")) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "template1" user password) + type))) + (unwind-protect + (execute-command (format nil "create database ~A" name)) + (database-disconnect database))))) (defmethod database-destroy (connection-spec (type (eql :postgresql-socket))) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error "Unable to create databases on a socket connection.")) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "template1" user password) + type))) + (unwind-protect + (execute-command (format nil "drop database ~A" name)) + (database-disconnect database))))) + (defmethod database-probe (connection-spec (type (eql :postgresql-socket))) + (when (find (second connection-spec) (database-list connection-spec type) + :key #'car :test #'string-equal) + t)) + +(defmethod database-list (connection-spec (type (eql :postgresql-socket))) (destructuring-bind (host name user password) connection-spec + (declare (ignore name)) (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) - (database-disconnect database))))) + (progn + (setf (slot-value database 'clsql-base-sys::state) :open) + (mapcar #'car (database-query "select datname from pg_database" + database :auto))) + (progn + (database-disconnect database) + (setf (slot-value database 'clsql-base-sys::state) :closed)))))) + +(defmethod database-describe-table ((database postgresql-socket-database) + table) + (database-query + (format nil "select a.attname, t.typname + from pg_class c, pg_attribute a, pg_type t + where c.relname = '~a' + and a.attnum > 0 + and a.attrelid = c.oid + and a.atttypid = t.oid" + (sql-escape (string-downcase table))) + database :auto)) (when (clsql-base-sys:database-type-library-loaded :postgresql-socket) (clsql-base-sys:initialize-database-type :database-type :postgresql-socket))