Name
sqlite3_get_table() — Get a result table
Definition
int sqlite3_get_table( sqlite3* db, const char sql, char*** result, int* num_rows, int* num_cols, char** errmsg );
-
db
A database connection.
-
sql
A null-terminated, UTF-8 encoded string that contains one or more SQL statements. If more than one SQL statement is provided, they must be separated by semicolons.
-
result
A reference to an array of strings. The results of the query are passed back using this reference. The value passed back must be freed with a call to
sqlite3_free_table()
.-
num_rows
The number of rows in the result, not including the column names.
-
num_cols
The number of columns in the result.
-
errmsg
An optional reference to a string. If an error occurs, the reference will be set to an error message. The application is responsible for freeing the message with
sqlite3_free()
. If no error occurs, the reference will be set to NULL. The reference may be NULL.- Returns
An SQLite result code.
Description
This function takes an SQL statement, executes it, and passes back the full result set. If more than one SQL statement is given in an SQL string, all the statements must have a result set with the same number of columns.
The result is an array of strings with (num_rows + 1) * num_cols
values. The first
num_cols
values are the
column names, followed by individual rows. To access the value
of a specific column and row, use the formula (
,
assuming the row
+ 1) *
num_cols + col
and row
indexes start with zero (col
0
).
See Also
Get Using SQLite now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.