xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_sql.3 (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1.Dd March 11, 2017
2.Dt SQLITE3_SQL 3
3.Os
4.Sh NAME
5.Nm sqlite3_sql ,
6.Nm sqlite3_expanded_sql
7.Nd Retrieving Statement SQL
8.Sh SYNOPSIS
9.Ft const char *
10.Fo sqlite3_sql
11.Fa "sqlite3_stmt *pStmt"
12.Fc
13.Ft char *
14.Fo sqlite3_expanded_sql
15.Fa "sqlite3_stmt *pStmt"
16.Fc
17.Sh DESCRIPTION
18The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
19SQL text used to create prepared statement P if P
20was created by either sqlite3_prepare_v2() or sqlite3_prepare16_v2().
21The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
22string containing the SQL text of prepared statement P with bound parameters
23expanded.
24.Pp
25For example, if a prepared statement is created using the SQL text
26"SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 and
27parameter :xyz is unbound, then sqlite3_sql() will return the original
28string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() will return "SELECT
292345,NULL".
30.Pp
31The sqlite3_expanded_sql() interface returns NULL if insufficient memory
32is available to hold the result, or if the result would exceed the
33the maximum string length determined by the SQLITE_LIMIT_LENGTH.
34.Pp
35The SQLITE_TRACE_SIZE_LIMIT compile-time option
36limits the size of bound parameter expansions.
37The SQLITE_OMIT_TRACE compile-time option causes sqlite3_expanded_sql()
38to always return NULL.
39.Pp
40The string returned by sqlite3_sql(P) is managed by SQLite and is automatically
41freed when the prepared statement is finalized.
42The string returned by sqlite3_expanded_sql(P), on the other hand,
43is obtained from sqlite3_malloc() and must be free
44by the application by passing it to sqlite3_free().
45.Sh SEE ALSO
46.Xr sqlite3_stmt 3 ,
47.Xr sqlite3_malloc 3 ,
48.Xr sqlite3_prepare 3 ,
49.Xr SQLITE_LIMIT_LENGTH 3
50