NextPrevUpTopContentsIndex

simple-do-query

Macro
Summary

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.

Package

sql

Signature

simple-do-query ( values-list query &key names-list database not-inside-transaction get-all ) &body body =>

Arguments

values-list

A variable.

query

A database 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.

Values

None.

Description

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.

Example
(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
See also

do-query
loop
map-query
query
select


LispWorks Reference Manual - 12 Mar 2008

NextPrevUpTopContentsIndex