Repeatedly binds a set of variables to the results of a query, and executes a body of code using the bound variables.
do-query ((&rest args ) query &key database not-inside-transaction get-all ) &body body =>
A set of variables.
A database query.
A database.
A generalized boolean.
A Lisp code body.
The macro
do-query
repeatedly executes
body
within a binding of
args
on the attributes of each record resulting from
query
.
do-query
returns no values.
The default value of database is *default-database*.
not-inside-transaction
and
get-all
may be useful when fetching many records through a connection with
database-type
:mysql
. Both of these arguments have default value
nil
. See the section Special considerations for iteration functions and macros for details.
The following code repeatedly binds the result of selecting an entry in
ename
from the table
emp
to the variable
name
, and then prints
name
using the Lisp function
print
.
(do-query ((name) [select [ename] :from [emp]])
(print name))