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.
sql
simple-do-query (values-list query &key names-list database not-inside-transaction get-all) &body body
values-list⇩ |
A variable. |
query⇩ |
A database query or a prepared-statement containing a query. |
names-list⇩ |
A variable, or nil . |
database⇩ |
A database. |
not-inside-transaction⇩ | |
A generalized boolean. | |
get-all⇩ |
A generalized boolean. |
body⇩ |
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 23.9.6 Special considerations for iteration functions and macros 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
do-query
Loop Extensions in Common SQL
map-query
prepare-statement
query
select
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:56