All Manuals > LispWorks® User Guide and Reference Manual > 45 The SQL Package

prepared-statement-set-and-execute

prepared-statement-set-and-execute*

prepared-statement-set-and-query

prepared-statement-set-and-query* Functions

Summary

Set the values of the variables in a prepared-statement and execute or query it.

Package

sql

Signatures

prepared-statement-set-and-execute prepared-statement &rest values

prepared-statement-set-and-execute* prepared-statement values &key database

prepared-statement-set-and-query prepared-statement &rest values => result-list, field-names

prepared-statement-set-and-query* prepared-statement values &key database => result-list, field-names

Arguments
prepared-statement
values
A list.
database
A database or nil.
Values
result-list, field-names
The results of query.
Description

The functions prepared-statement-set-and-execute, prepared-statement-set-and-execute*, prepared-statement-set-and-query and prepared-statement-set-and-query* set the variables of a prepared-statement and then execute or query using it. They first call set-prepared-statement-variables, passing it prepared-statement and values, and for prepared-statement-set-and-execute* and prepared-statement-set-and-query* also database, and then call either execute-command (prepared-statement-set-and-execute and prepared-statement-set-and-execute*) or query (prepared-statement-set-and-query and prepared-statement-set-and-query*). The latter two return the result of the call to query.

Examples

The following code shows insertion of multiple records using a prepared statement and prepared-statement-set-and-execute.

(progn
  (when (sql:table-exists-p "a_table_of_squares")
    (sql:drop-table "a_table_of_squares"))
  (sql:execute-command "create table a_table_of_squares (num integer, square_of_num integer)")
 
  (sql:with-prepared-statement (ps "insert into a_table_of_squares values (:1, :2)")
    (dotimes (x 10)
      (sql:prepared-statement-set-and-execute ps x (* x x))))
 
  ;; check it
  (pprint (sql:query "select * from a_table_of_squares")))
See also

prepare-statement
set-prepared-statement-variables
with-prepared-statement
execute-command
query


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:56