Statement macro
Executes all SQL statements appearing in the body of the code against the database for the user.
with-database(database, user) body end [with-database]
<database>.
<user>.
sql
sql
Executes all SQL statements appearing in body against database for user.
This macro applies the connect function to its parameters, and establishes the resulting connection as the default connection within the dynamic scope of body. The connection is terminated when execution leaves the scope of body.
The result of this macro is the last expression executed in body.
This example queries the ODBC database library for a list of titles contained within the book table. The with-database macro establishes the library database as the database to execute the query against.
with-database(make(<odbc-database>, name: "library"),
make(<odbc-user>, user: "andrew",
password: "foobar"));
let query = make (<odbc-sql-statement>,
text: "select title from book"),
execute (query);
end with-database;
=> #(#("An Introduction to Database Systems",
"Transaction Processing: Concepts and Techniques",
"Fundamentals of Database Systems",
"Relational Database Writings, 1991-1994"))