DO-QUERY — Iterate over all the tuples of a query
Macro
A list of variable names.
An sql expression that represents an SQL query which is expected to return a (possibly empty) result set, where each tuple has as many attributes as function takes arguments.
A database object. This will default to *default-database*.
A field type specififier. The default is NIL. See query for the semantics of this argument.
A body of Lisp code, like in a destructuring-bind form.
Executes the body of code repeatedly with the variable names in args bound to the attributes of each tuple in the result set returned by executing the SQL query-expression on the database specified.
The body of code is executed in a block named nil which may be returned from prematurely via return or return-from. In this case the result of evaluating the do-query form will be the one supplied to return or return-from. Otherwise the result will be nil.
The body of code appears also is if wrapped in a destructuring-bind form, thus allowing declarations at the start of the body, especially those pertaining to the bindings of the variables named in args.
(do-query ((salary name) "select salary,name from simple") (format t "~30A gets $~2,5$~%" name (read-from-string salary))) >> Mai, Pierre gets $10000.00 >> Hacker, Random J. gets $08000.50 => NIL (do-query ((salary name) "select salary,name from simple") (return (cons salary name))) => ("10000.00" . "Mai, Pierre")