1.3 Prepared Statements
(prepared-statement? x) → boolean? |
x : any |
Returns #t if x represents a MySQL prepared statement, #f otherwise.
(prepare [#:connection con] sql) → prepared-statement? |
con : connection? = (current-connection) |
sql : string? |
Prepares a single, parameterized SQL statement for execution. The SQL statement may use question marks (?) in place of SQL value expressions. Each question mark denotes a parameter that may be supplied at execution time. For example, the following:
(define stmt (prepare "UPDATE foo_tbl SET name = ? WHERE id = ?"))
... defines stmt as a prepared statement with two parameters.
(prepared-statement-parameter-count stmt) |
→ exact-nonnegative-integer? |
stmt : prepared-statement? |
Returns the number of parameters in the given stmt.
(execute stmt arguments) → query-result? |
stmt : prepared-statement? |
arguments : (listof any) |
Executes a prepared-statement, substituting the provided arguments for the parameters of stmt in positional order. The length of the arguments list must be equal to the number of parameters in stmt, otherwise exn:fail:contract is raised.
Note that not all scheme values are valid as parameter values (e.g., output ports). If such a value is encountered, exn:fail:contract is raised.