X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-mysql%2Fmysql-sql.lisp;h=87b78f3f4f5757414c76976d1a0bcc5d0fcef7b4;hb=2ae9ee745ff9e17806178e1999b880acc64ab894;hp=12279c35a41fd9116efa80e4ca0ae49b57eca53f;hpb=c4da3cfcbb955395d8a556e1f89aadad696302b7;p=clsql.git diff --git a/db-mysql/mysql-sql.lisp b/db-mysql/mysql-sql.lisp index 12279c3..87b78f3 100644 --- a/db-mysql/mysql-sql.lisp +++ b/db-mysql/mysql-sql.lisp @@ -114,6 +114,7 @@ (make-instance 'mysql-database :name (database-name-from-spec connection-spec database-type) + :database-type :mysql :connection-spec connection-spec :mysql-ptr mysql-ptr)) (when error-occurred (mysql-close mysql-ptr))))))))) @@ -397,47 +398,47 @@ (defmethod database-create (connection-spec (type (eql :mysql))) (destructuring-bind (host name user password) connection-spec - (let ((asdf::*verbose-out* (make-string-output-stream))) - (unwind-protect - (let* ((status (asdf:run-shell-command - "mysqladmin create -u~A -p~A -h~A ~A" - user password - (if host host "localhost") - name)) - (result (get-output-stream-string asdf::*verbose-out*))) - - (if (search "CREATE DATABASE failed;" result) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error - (format nil "database-create failed: ~s" result)) - t)) - (close asdf::*verbose-out*))))) + (multiple-value-bind (output status) + (clsql-base-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 'clsql-access-error + :connection-spec connection-spec + :database-type type + :error + (format nil "database-create failed: ~A" output)) + t)))) (defmethod database-destory (connection-spec (type (eql :mysql))) (destructuring-bind (host name user password) connection-spec - (let ((asdf::*verbose-out* (make-string-output-stream))) - (unwind-protect - (let* ((status (asdf:run-shell-command - "mysqladmin drop -f -u~A -p~A -h~A ~A" - user password - (if host host "localhost") - name)) - (result (get-output-stream-string asdf::*verbose-out*))) - - (if (search "DROP DATABASE failed;" result) - (error 'clsql-access-error - :connection-spec connection-spec - :database-type type - :error - (format nil "database-destory failed: ~s" result)) - t)) - (close asdf::*verbose-out*))))) + (multiple-value-bind (output status) + (clsql-base-sys:command-output "mysqladmin drop -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 'clsql-access-error + :connection-spec connection-spec + :database-type type + :error + (format nil "database-destroy failed: ~A" output)) + t)))) (defmethod database-probe (connection-spec (type (eql :mysql))) - (destructuring-bind (name user password) connection-spec - (error "not-yet-implemented"))) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "mysql" user password) type))) + (unwind-protect + (when + (find name (database-query "select db from db" + database :auto) + :key #'car :test #'string-equal) + t) + (database-disconnect database))))) + (when (clsql-base-sys:database-type-library-loaded :mysql) (clsql-base-sys:initialize-database-type :database-type :mysql))