Next Previous Up Top Contents Index

1.3.3 The SQL statement class

execute

Generic function

Summary

Prepares an SQL statement for execution on the specified connection and then executes the statement.

Signature

execute sql-statement #key connection parameters result-set-policy liaison => result-set 

Arguments

sql-statement
An instance of <sql-statement>.

connection
An instance of <connection>.

parameters
An instance of false-or(<sequence>).

result-set-policy
An instance of false-or(<result-set-policy>).

liaison
An instance of false-or(<function>) whose signature is liaison(<record>) => <object>. Default value: default-liaison.

Values

result-set
An instance of false-or(<result-set>).

Library

sql

Module

sql

Description

Prepares the SQL statement represented by sql-statement for execution on the connection, then sends it to the DBMS for execution.

If connection is not supplied, execute uses the connection returned by default-connection instead.

The liaison function is invoked on each record as it is retrieved from the database. If a liaison function is not provided, a default value of default-liaison is used; each result-set class has its own default-liaison.

In the SQL-ODBC library, the database-statement will be an instance of <sql-statement>. If anonymous host variables--that is, question marks (?)--appear in database-statement, pass suitable substitution values in the call to this function.

Example:

This example executes two SQL statements against the database represented by the-connection. The first SQL statement inserts a new book record into the book table. The second SQL statement queries for the list of titles and their ISBN published by Addison Wesley.

with-connection(the-connection)
  let insert-stmt :: <sql-statement> =
  make(<sql-statement>,
    text: "insert into book (title, publisher, isbn) 
               values (?, ?, ?)",
    input-indicator: $null-value);
  execute(insert-stmt,
          parameters: #("Large Databases", "Addison-Wesley",
                        $null-value));

let query-stmt :: <sql-statement> = make(<sql-statement>, text: "select title, isbn from book where publisher = ?", output-indicator: $null-value); execute(query-stmt, parameters: #("Addison-Wesley")); end with-connection;

=> #(#("An Introduction to Database Systems", "0-201-14201-5"), #("Relational Database Writings, 1991-1994", "0-8053-1748-1), #("Large Databases", $null-value))


OLE, COM, ActiveX and DBMS Reference - 31 MAR 2000

Next Previous Up Top Contents Index