int sqlite3_prepare( sqlite3* db, const char* sql, int sql_len, sqlite3_stmt** stmt_ref, const char** tail ); int sqlite3_prepare16( sqlite3* db, const void* sql, int sql_len, sqlite3_stmt** stmt_ref, const char** tail ); int sqlite3_prepare_v2( sqlite3* db, const char* sql, int sql_len, sqlite3_stmt** stmt_ref, const char** tail ); int sqlite3_prepare16_v2( sqlite3* db, const void* sql, int sql_len, sqlite3_stmt** stmt_ref, const char** tail );
db
A database connection.
sql
One or more SQL statements in a UTF-8 or UTF-16 encoded string. If the string contains more than one SQL statement, the statements must be separated by a semicolon. If the string contains only one SQL statement, no trailing semicolon is required.
sql_len
The length of the sql
buffer in bytes. If the sql
string is
null-terminated, the length should include the
termination character. If the sql
string is
null-terminated but the length is not known, a
negative value will cause SQLite to compute the
buffer length.
stmt_ref
A reference to a prepared statement. SQLite will allocate and pass back the prepared statement.
tail
If the sql
buffer contains more than one SQL statement, only
the first complete statement is used. If
additional statements exist, this reference will
be used to pass back a pointer to the next SQL
statement in the sql
buffer. This reference may be set
to NULL.
An SQLite result code.
These functions take an SQL statement string and build a
prepared statement. The prepared statement can be executed using
sqlite3_step()
. All
prepared statements must eventually be finalized with sqlite3_finalize()
.
Both the original and the _v2
versions of prepare take the exact same parameters. The _v2
versions produce a slightly
different statement, however. The newer statements are able to
automatically recover from some errors and provide better error
handling. For a more in-depth discussion of the differences, see
Prepare v2.
The original versions are considered legacy APIs, and their use in new development is not recommended.