2010/11/12

CLSQL Error 2014 / Commands out of sync; you can't run this command now

loop 中に他のクエリは実行できないのかな?

大量のレコードを select して一件一件フェッチしながら update とかしたいとき、どうすればいい?

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

(eval-when (:compile-toplevel :load-toplevel :execute)
(use-package :clsql)
(series::install :implicit-map t))

(defparameter *connection-spec* '("localhost" "blog_development" "root" ""))

(defmacro with-db ((&optional (db-var '*default-database*)) &body body)
`(with-database (,db-var *connection-spec* :make-default t :pool t
:encoding :utf-8 :database-type :mysql)
;;(clsql-sys::start-sql-recording)
(execute-command "set character_set_client='utf8'")
(execute-command "set character_set_connection='utf8'")
(execute-command "set character_set_results='utf8'")
(execute-command "start transaction")
(prog1 (progn ,@body)
(execute-command "commit")
(clsql-sys::stop-sql-recording))))

(with-db ()
(loop for x being each tuple in "select 'まみむめも♪'"
do (print (query "select 'まみむめも♪'"))
do (print x)))
#| => エラーになる。。。
While accessing database #<MYSQL-DATABASE localhost/blog_development/root OPEN {1004A2AB41}>
with expression "select 'まみむめも♪'":
Error 2014 / Commands out of sync; you can't run this command now
has occurred.
[Condition of type SQL-DATABASE-DATA-ERROR]
|#

0 件のコメント: