(make-instance 'postgresql-socket-database
:name (database-name-from-spec connection-spec
database-type)
+ :database-type :postgresql-socket
:connection-spec connection-spec
:connection connection)))))
(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
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))