Permalink
Browse files

added dbd.mysql (Transaction isn't supported yet).

  • Loading branch information...
1 parent b3266a6 commit d31370c2f7769ec852f6dbfb2669deafe54cb0c8 @fukamachi committed Jan 30, 2012
Showing with 21 additions and 33 deletions.
  1. +1 −1 README.markdown
  2. +2 −1 dbi-test.asd
  3. +17 −5 src/dbd/mysql.lisp
  4. +1 −26 t/dbd/mysql.lisp
View
@@ -28,7 +28,7 @@ For example, your application had better to use efficient database such as MySQL
* SQLite3
* PostgreSQL (Transaction isn't supported yet)
-* MySQL (work in progress)
+* MySQL (Transaction isn't supported yet)
## Installation
View
@@ -27,5 +27,6 @@
(:module "dbd"
:components
((:file "sqlite3")
- (:file "postgres"))))))
+ (:file "postgres")
+ (:file "mysql"))))))
:perform (load-op :after (op c) (asdf:clear-system c)))
View
@@ -31,15 +31,27 @@
:socket socket
:client-flag client-flag)))
-(defmethod execute-using-connection ((conn <dbd-mysql-connection>) (query <dbd-query>) params)
+@export
+(defclass <dbd-mysql-query> (<dbd-query>)
+ ((%result :initform nil)))
+
+(defmethod prepare ((conn <dbd-mysql-connection>) (sql string) &key)
+ (call-next-method conn sql :query-class '<dbd-mysql-query>))
+
+(defmethod execute-using-connection ((conn <dbd-mysql-connection>) (query <dbd-mysql-query>) params)
(let ((result (query (apply (query-prepared query) params)
:database (connection-handle conn)
:store nil)))
+ (cl-mysql-system::return-or-close (cl-mysql-system::owner-pool result) result)
(next-result-set result)
- result))
-
-(defmethod fetch-using-connection ((conn <dbd-mysql-connection>) result)
- (next-row result))
+ (setf (slot-value query '%result) result)
+ query))
+
+(defmethod fetch-using-connection ((conn <dbd-mysql-connection>) query)
+ (loop with result = (slot-value query '%result)
+ for val in (next-row result)
+ for (name . type) in (car (result-set-fields result))
+ append (list (intern name :keyword) val)))
(defmethod escape-sql ((conn <dbd-mysql-connection>) (sql string))
(escape-string sql :database (connection-handle conn)))
View
@@ -10,29 +10,4 @@
:dbi))
(in-package :dbd-mysql-test)
-(plan nil)
-
-(defparameter *database-host* "localhost")
-(defparameter *database-name* "dbi")
-(defparameter *database-user* "root")
-
-(defparameter *db*
- (connect :mysql
- :host *database-host*
- :database-name *database-name*
- :user *database-user*))
-
-(do-sql *db* "DROP TABLE IF EXISTS user")
-
-(do-sql *db* "CREATE TABLE user ( id INTEGER PRIMARY KEY, name VARCHAR(24) NOT NULL )")
-(do-sql *db* "INSERT INTO user (id, name) VALUES (1, 'fukamachi')")
-
-(let* ((query (prepare *db* "SELECT name FROM user"))
- (result (execute query)))
- (is (fetch result) '(:|name| "fukamachi") "fetch"))
-
-(do-sql *db* "DROP TABLE user")
-
-(disconnect *db*)
-
-(finalize)
+(dbi.test:run-driver-tests :mysql :database-name "dbi" :username "root")

0 comments on commit d31370c

Please sign in to comment.