The callback function is formatted as follows :
int Sqlite_callback (
void* PV, /* passed by The fourth parameter of sqlite3_exec () */
int argc,/ * number of columns in table * /
Char* * argv, /* pointer to the query result array , can be sqlite3_column_text () Get */
Char* */col * * an array of pointers to table header names can be used by Sqlite3_column_name () get */
);
Parameter format :
callback function passed to Sqlite3_exec to display the query results
Call the callback function once for each query result
Parameters :
PV: Initialization parameters passed by sqlite3_exec
ARGC: Number of columns of the table header
col: name array pointer to table header
ARGV: data array pointer to table header
return value :
1: Interrupt Lookup
0: continue to enumerate the queried data
Sample Table :
+-----------------------------------+
| ID | Pic | Data ( data-in-process ) |
|-----------------------------------|
| 1 | a.jpg | 00 00 00 ... |
|-----------------------------------|
| 2 | b.jpg | xx xx xx |
+-----------------------------------+
For the first row of data :
argc=3 [0] ... [2]
argv[0]= "1", argv[1]= "a.jpg", argv[2]= "00 00 00 ..." ( actual data , not in string form shown here )
col[0]= "id", col[1]= "pic", col[2]= "data"
Description :
the callback function of Sqlite3_exec () must follow this format , with the name of the formal parameter arbitrarily .
If the data type of a column is not char*, you can perform related transformations on the result , such as : using atoi () to convert the result to an integer ( Integer), in the case of binary data , you can directly enforce type conversions , such as :(void*) argv[i].
The callback function has two types of return values .
1. return 0 : sqlite3_exec () will continue to execute the query .
2. return non 0 : sqlite3_exec () will immediately break the query , and sqlite3_exec () will return Sqlite_abort.
Example :
int i;
for (i=0; i<argc; i++)
{
printf ("%s\t%s\n\n", Col[i], argv[i]);
}
Using callback functions in SQLite3