-;; Functions depending upon high-level CommonSQL classes/functions
-#|
-(defmethod database-output-sql ((expr clsql-sys::sql-typecast-exp)
- (database mysql-database))
- (with-slots (clsql-sys::modifier clsql-sys::components)
- expr
- (if clsql-sys::modifier
- (progn
- (clsql-sys::output-sql clsql-sys::components database)
- (write-char #\: sql-sys::*sql-stream*)
- (write-char #\: sql-sys::*sql-stream*)
- (write-string (symbol-name clsql-sys::modifier)
- clsql-sys::*sql-stream*)))))
-
-(defmethod database-output-sql-as-type ((type (eql 'integer)) val
- (database mysql-database))
- ;; typecast it so it uses the indexes
- (when val
- (make-instance 'clsql-sys::sql-typecast-exp
- :modifier 'int8
- :components val)))
-|#
-
-(when (clsql-base-sys:database-type-library-loaded :mysql)
- (clsql-base-sys:initialize-database-type :database-type :mysql))
+(defmethod database-create (connection-spec (type (eql :mysql)))
+ (destructuring-bind (host name user password) connection-spec
+ (multiple-value-bind (output status)
+ (clsql-sys:command-output "mysqladmin create -u~A -p~A -h~A ~A"
+ user password
+ (if host host "localhost")
+ name)
+ (if (or (not (eql 0 status))
+ (and (search "failed" output) (search "error" output)))
+ (error 'sql-database-error
+ :message
+ (format nil "mysql database creation failed with connection-spec ~A."
+ connection-spec))
+ t))))
+
+(defmethod database-destroy (connection-spec (type (eql :mysql)))
+ (destructuring-bind (host name user password) connection-spec
+ (multiple-value-bind (output status)
+ (clsql-sys:command-output "mysqladmin drop -f -u~A -p~A -h~A ~A"
+ user password
+ (if host host "localhost")
+ name)
+ (if (or (not (eql 0 status))
+ (and (search "failed" output) (search "error" output)))
+ (error 'sql-database-error
+ :message
+ (format nil "mysql database deletion failed with connection-spec ~A."
+ connection-spec))
+ t))))
+
+(defmethod database-probe (connection-spec (type (eql :mysql)))
+ (when (find (second connection-spec) (database-list connection-spec type)
+ :key #'car :test #'string-equal)
+ t))
+
+(defmethod database-list (connection-spec (type (eql :mysql)))
+ (destructuring-bind (host name user password) connection-spec
+ (declare (ignore name))
+ (let ((database (database-connect (list host "mysql" user password) type)))
+ (unwind-protect
+ (progn
+ (setf (slot-value database 'clsql-sys::state) :open)
+ (mapcar #'car (database-query "show databases" database :auto nil)))
+ (progn
+ (database-disconnect database)
+ (setf (slot-value database 'clsql-sys::state) :closed))))))
+
+;;; Database capabilities
+
+(defmethod db-type-use-column-on-drop-index? ((db-type (eql :mysql)))
+ t)
+
+(defmethod db-type-has-views? ((db-type (eql :mysql)))
+ ;; MySQL 4.1 will apparently have views, need to check *mysql-client-info*
+ nil)
+
+(defmethod db-type-has-subqueries? ((db-type (eql :mysql)))
+ ;; MySQL 4.1 will apparently have subqueries, need to check *mysql-client-info*
+ nil)
+
+(defmethod db-type-has-boolean-where? ((db-type (eql :mysql)))
+ nil)
+
+(defmethod db-type-has-union? ((db-type (eql :mysql)))
+ (not (eql (schar mysql::*mysql-client-info* 0) #\3)))
+
+(defmethod db-type-transaction-capable? ((db-type (eql :mysql)) database)
+ (let ((tuple (car (database-query "SHOW VARIABLES LIKE 'HAVE_INNODB'" database :auto nil))))
+ (and tuple (string-equal "YES" (second tuple)))))
+
+(when (clsql-sys:database-type-library-loaded :mysql)
+ (clsql-sys:initialize-database-type :database-type :mysql))
+