xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_exec.3 (revision 022f005200bc25af02826a05c8d86d0ef18232dc)
1.Dd March 11, 2017
2.Dt SQLITE3_EXEC 3
3.Os
4.Sh NAME
5.Nm sqlite3_exec
6.Nd One-Step Query Execution Interface
7.Sh SYNOPSIS
8.Ft int
9.Fo sqlite3_exec
10.Fa "sqlite3*"
11.Fa "const char *sql"
12.Fa "int (*callback)(void*,int,char**,char**)"
13.Fa "void *"
14.Fa "char **errmsg                              "
15.Fc
16.Sh DESCRIPTION
17The sqlite3_exec() interface is a convenience wrapper around sqlite3_prepare_v2(),
18sqlite3_step(), and sqlite3_finalize(),
19that allows an application to run multiple statements of SQL without
20having to use a lot of C code.
21.Pp
22The sqlite3_exec() interface runs zero or more UTF-8 encoded, semicolon-separate
23SQL statements passed into its 2nd argument, in the context of the
24database connection passed in as its 1st argument.
25If the callback function of the 3rd argument to sqlite3_exec() is not
26NULL, then it is invoked for each result row coming out of the evaluated
27SQL statements.
28The 4th argument to sqlite3_exec() is relayed through to the 1st argument
29of each callback invocation.
30If the callback pointer to sqlite3_exec() is NULL, then no callback
31is ever invoked and result rows are ignored.
32.Pp
33If an error occurs while evaluating the SQL statements passed into
34sqlite3_exec(), then execution of the current statement stops and subsequent
35statements are skipped.
36If the 5th parameter to sqlite3_exec() is not NULL then any error message
37is written into memory obtained from sqlite3_malloc()
38and passed back through the 5th parameter.
39To avoid memory leaks, the application should invoke sqlite3_free()
40on error message strings returned through the 5th parameter of sqlite3_exec()
41after the error message string is no longer needed.
42If the 5th parameter to sqlite3_exec() is not NULL and no errors occur,
43then sqlite3_exec() sets the pointer in its 5th parameter to NULL before
44returning.
45.Pp
46If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
47routine returns SQLITE_ABORT without invoking the callback again and
48without running any subsequent SQL statements.
49.Pp
50The 2nd argument to the sqlite3_exec() callback function is the number
51of columns in the result.
52The 3rd argument to the sqlite3_exec() callback is an array of pointers
53to strings obtained as if from sqlite3_column_text(),
54one for each column.
55If an element of a result row is NULL then the corresponding string
56pointer for the sqlite3_exec() callback is a NULL pointer.
57The 4th argument to the sqlite3_exec() callback is an array of pointers
58to strings where each entry represents the name of corresponding result
59column as obtained from sqlite3_column_name().
60.Pp
61If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
62to an empty string, or a pointer that contains only whitespace and/or
63SQL comments, then no SQL statements are evaluated and the database
64is not changed.
65.Pp
66Restrictions:
67.Bl -bullet
68.It
69The application must ensure that the 1st parameter to sqlite3_exec()
70is a valid and open database connection.
71.It
72The application must not close the database connection
73specified by the 1st parameter to sqlite3_exec() while sqlite3_exec()
74is running.
75.It
76The application must not modify the SQL statement text passed into
77the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
78.El
79.Pp
80.Sh SEE ALSO
81.Xr sqlite3 3 ,
82.Xr sqlite3_column_name 3 ,
83.Xr sqlite3_column_blob 3 ,
84.Xr sqlite3_finalize 3 ,
85.Xr sqlite3_malloc 3 ,
86.Xr sqlite3_prepare 3 ,
87.Xr sqlite3_step 3
88