Repeatedly binds a variable to the results of a query, optionally binds another variable to the column names, and executes a body of code within the scope of these bindings.
simple-do-query ( values-list query &key names-list database not-inside-transaction get-all ) &body body =>
A variable.
A database query.
A variable, or
nil
.
A database.
A generalized boolean.
A Lisp code body.
The macro
simple-do-query
repeatedly executes
body
within a binding of
values-list
to the attributes of each record resulting from
query
.
If a variable
names-list
is supplied, then it is bound to a list of the column names for the query during the execution of
body
. The default value of
names-list
is
nil
.
simple-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" in the
LispWorks User Guide
for details.
(sql:simple-do-query
(person-details [select [Surname][ID] :from [person]]
:names-list xx)
(format t "~&~A: ~A, ~A: ~A~%"
(first xx)
(first person-details)
(second xx)
(second person-details)))
=>
SURNAME: Brown, ID: 2
SURNAME: Jones, ID: 3
SURNAME: Smith, ID: 4