Murdock L
Murdock L

Reputation: 3

C: Define own function instead of callback in SQLite

As shown from the SQLite site, sqlite3_exec calls callback at every record returned for some action:

int sqlite3_exec(
sqlite3*,                                  /* An open database */
const char *sql,                           /* SQL to be evaluated */
int (*callback)(void*,int,char**,char**),  /* Callback function */
void *,                                    /* 1st argument to callback */
char **errmsg                              /* Error msg written here */

);

Is it possible to invoke another self defined function to do a different set of actions on every record instead of editing the callback function?

For example, sqlite3_exec(db, sql, display, 0, &zErrMsg);, where display is a function to display all records in the terminal.

EDIT: I thought about overloading the function, but I don't think C supports overloading.

Upvotes: 0

Views: 85

Answers (1)

CL.
CL.

Reputation: 180030

It is possible to use another function, like this:

sqlite3_exec(db, sql, display, 0, &zErrMsg);

The name "callback" is just the name of the parameter as used internally by the sqlite3_exec function; your own functions can be named whatever you like.

Upvotes: 1

Related Questions