Prepare the SQL statement contained in the sql-statement parameter. The syntax and requirements for
box.prepareare the same as for box.execute().
prepared_table, with id and methods and metadata
box.preparecompiles an SQL statement into byte code and saves the byte code in a cache. Since compiling takes a significant amount of time, preparing a statement will enhance performance if the statement is executed many times.
box.preparesucceeds, prepared_table contains:
stmt_id: integer – an identifier generated by a hash of the statement string
params: map [name : string, type : string] – parameter descriptions
metadata: map [name : string, type : string] (This is present only for SELECT or PRAGMA statements and has the same contents as the result set metadata for
param_count: integer – number of parameters
The prepared statement cache (which is also called the prepared statement holder) is «shared», that is, there is one cache for all sessions. However, session X cannot execute a statement prepared by session Y.
For monitoring the cache, see box.info().sql.
For changing the cache, see (Configuration reference) sql_cache_size.
Prepared statements will «expire» (become invalid) if any database object is dropped or created or altered – even if the object is not mentioned in the SQL statement, even if the create or drop or alter is rolled back, even if the create or drop or alter is done in a different session.