So I'm trying to use SQLite with MFC dialogues in Visual Studio 2010. I'm unclear as how to use the callback function in order for me to save result of the query, which is trying to count the number of tables in my database, into the variable m_Results. Is there anyway to do this, or is there anyway for me to access the nTables variable?
static int callback(void *data, int argc, char **argv, char **azColName){
int i;
fprintf(stderr, "%s: ", (const char*)data);
data = argv[0];
return 0;
}
BOOL CDBpracticeDlg::OnInitDialog(){
...
// TODO: Add extra initialization here
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char *sql;
const char* data = "Callback function called";
rc = sqlite3_open("structInfo_Test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
/* Create SQL statement */
sql = "Select Count(*) as nTables FROM sqlite_master where type='table';";
/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, &m_Results, &zErrMsg);
if( rc != SQLITE_OK ){
char error[200];
strcpy(error,"SQL error: ");
strcat(error,zErrMsg);
m_Results = error;
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, "Operation done successfully\n");
}
UpdateData(FALSE);
sqlite3_close(db);
return TRUE; // return TRUE unless you set the focus to a control
}