Heyall. I'm trying to use the sqlite3_exec function and am having trouble with the callback feature.
I've placed my code below. I realise the callback function provides and argument void *data and the
sqlite3_exec function provides a const char *data variable.
That is where I'm getting the error. I've searched the web for a similar example but I think this is occuring because I haven't cast the address of 'const char data' to the 'void data variable'. I'm just not sure where to put it.
I've provided all my code below. The error message (from the build log) is also below. This error occurs when compiling.
ERROR MESSAGE FROM BUILD LOG.
C:\Documents and Settings\xxxx\My Documents\codeblock files\SQLITE_EXEC\main.cpp:38: error: invalid conversion from 'const void*' to 'void*'
C:\Documents and Settings\xxxx\My Documents\codeblock files\SQLITE_EXEC\main.cpp:38: error: initializing argument 4 of 'int sqlite3_exec(sqlite3*, const char*, int (*)(void*, int, char**, char**), void*, char**)'
C:\Documents and Settings\xxxx\My Documents\codeblock files\SQLITE_EXEC\main.cpp: At global scope:
C:\Documents and Settings\xxxx\My Documents\codeblock files\SQLITE_EXEC\main.cpp:63: error: expected constructor,
CALLBACK FUNCTION
int callback(void *data, int ncols, char** values, char** headers);
int main()
{
sqlite3 *db;
int rc, kt;
char *err;
const char *sql;
rc = sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE, NULL); //this works fine
if(SQLITE_OK == sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE, NULL));
{
cout << "Database Opened Fine" << endl;
}
sql = "select * from foods";
const char* data ="Callback Function called";
kt = sqlite3_exec(db,sql, callback,data,&err);
if( kt!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", err);
/* This will free err if assigned */
if (err)
free(err);
}
system("pause>nul");
}
// callback function below
int callback(void *data, int ncols, char** values, char** headers)
{
data = 0;
cout << "start of callback" << endl;
return 0;
}