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