r9088: Automated commit for Debian build of clsql upstream-version-2.8.0
[clsql.git] / db-postgresql-socket / postgresql-socket-sql.lisp
index 7df3dc7de361498165a6b717d9c2b29d7e1c1f45..50c6899afc0f8c6a4a36fefc0597fdb911967663 100644 (file)
@@ -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))