r8963: pre 2.6.4
[clsql.git] / db-postgresql-socket / postgresql-socket-sql.lisp
index 9a2f02d04b60d843defdbae8ba9b298c8bc3c8e7..1e29c070d6749dfac59dcc88dde53898c397aff0 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,16 +431,20 @@ 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)))
   (destructuring-bind (host name user password) connection-spec
@@ -453,5 +458,17 @@ doesn't depend on UFFI."
            t)
        (database-disconnect database)))))
 
+(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))