X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=db-mysql%2Fmysql-sql.lisp;h=155b59732ffd1de487d0a7e6c4c7af9a0a814814;hb=9f2b1f47684151e0706d51540ab5424c005f3184;hp=00430a340176f10cfdee7b215fe2b808bf4ba4b0;hpb=e567409d9fff3f7231c2a0bb69b345e19de2b246;p=clsql.git diff --git a/db-mysql/mysql-sql.lisp b/db-mysql/mysql-sql.lisp index 00430a3..155b597 100644 --- a/db-mysql/mysql-sql.lisp +++ b/db-mysql/mysql-sql.lisp @@ -156,14 +156,22 @@ :connection-spec connection-spec :error-id (mysql-errno mysql-ptr) :message (mysql-error-string mysql-ptr))) - (make-instance 'mysql-database - :name (database-name-from-spec connection-spec - database-type) - :database-type :mysql - :connection-spec connection-spec - :server-info (uffi:convert-from-cstring - (mysql:mysql-get-server-info mysql-ptr)) - :mysql-ptr mysql-ptr)) + (let* ((db + (make-instance 'mysql-database + :name (database-name-from-spec connection-spec + database-type) + :database-type :mysql + :connection-spec connection-spec + :server-info (uffi:convert-from-cstring + (mysql:mysql-get-server-info mysql-ptr)) + :mysql-ptr mysql-ptr)) + (cmd "SET SESSION sql_mode='ANSI'")) + (uffi:with-cstring (cmd-cs cmd) + (if (zerop (mysql-real-query mysql-ptr cmd-cs (expression-length cmd))) + db + (progn + (warn "Error setting ANSI mode for MySQL.") + db))))) (when error-occurred (mysql-close mysql-ptr))))))))) @@ -346,7 +354,7 @@ (declare (ignore owner)) (do ((results nil) (rows (database-query - (format nil "SHOW INDEX FROM ~A" (string-upcase table)) + (format nil "SHOW INDEX FROM ~A" table) database nil nil) (cdr rows))) ((null rows) (nreverse results)) @@ -443,35 +451,22 @@ database :auto nil)))) (defmethod database-create (connection-spec (type (eql :mysql))) - (destructuring-bind (host name user password &optional port) connection-spec - (multiple-value-bind (output status) - (clsql-sys:command-output "mysqladmin create -u~A -p~A -h~A~@[ -P~A~] ~A" - user password - (if host host "localhost") - port name - 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)))) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "" user password) + type))) + (setf (slot-value database 'clsql-sys::state) :open) + (unwind-protect + (database-execute-command (format nil "create database ~A" name) database) + (database-disconnect database))))) (defmethod database-destroy (connection-spec (type (eql :mysql))) - (destructuring-bind (host name user password &optional port) connection-spec - (multiple-value-bind (output status) - (clsql-sys:command-output "mysqladmin drop -f -u~A -p~A -h~A~@[ -P~A~] ~A" - user password - (if host host "localhost") - port 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)))) + (destructuring-bind (host name user password) connection-spec + (let ((database (database-connect (list host "" user password) + type))) + (setf (slot-value database 'clsql-sys::state) :open) + (unwind-protect + (database-execute-command (format nil "drop database ~A" name) database) + (database-disconnect database))))) (defmethod database-probe (connection-spec (type (eql :mysql))) (when (find (second connection-spec) (database-list connection-spec type) @@ -480,8 +475,7 @@ (defmethod database-list (connection-spec (type (eql :mysql))) (destructuring-bind (host name user password &optional port) connection-spec - (declare (ignore name)) - (let ((database (database-connect (list host "mysql" user password port) type))) + (let ((database (database-connect (list host (or name "mysql") user password port) type))) (unwind-protect (progn (setf (slot-value database 'clsql-sys::state) :open)