2010/10/07

CLSQL で MySQL につなぐ

いつも忘れるのでメモ。

#|
cffi ではなく uffi を使うこと。
|#

(eval-when (:compile-toplevel :load-toplevel :execute)
(require :clsql))

(defpackage :clsqlを使う
(:use :cl :clsql :clsql-sys))

(in-package :clsqlを使う)

(defun test ()
(connect '("localhost" "blog_development" "root" "") :database-type :mysql)
(execute-command "set character_set_client='utf8'")
(execute-command "set character_set_connection='utf8'")
(execute-command "set character_set_results='utf8'")
(print (query "show variables like 'char%'"))
(print (query "select * from posts"))
(disconnect))

#|
disconnect でエラーになったので

diff --git a/db-mysql/mysql-sql.lisp b/db-mysql/mysql-sql.lisp
index eef9f42..76803e9 100644
--- a/db-mysql/mysql-sql.lisp
+++ b/db-mysql/mysql-sql.lisp
@@ -219,7 +219,8 @@

(defmethod database-disconnect ((database mysql-database))
(mysql-close (database-mysql-ptr database))
- (setf (database-mysql-ptr database) nil)
+ ;;(setf (database-mysql-ptr database) nil)
+ (setf (database-mysql-ptr database) (uffi:make-null-pointer 'mysql-mysql))
t)

(defmethod database-execute-command (sql-expression (database mysql-database))
|#

0 件のコメント: