c++ - sqlite3_exec callback is not called -


i have check if table exists before created, reading how check in sqlite whether table exists?, use sqlite3_exec 1 step query

select name sqlite_master type = 'table' , name ='table1';

and use callback set flag identify table exists or not. unfortunately, callback not called, if table not yet created.

why callback not being called? know callback not called queries without output results, e.g. "create table" etc, , called "select" queries. not aware may not called "select".

the following code sample reproduce problem.

#include <stdio.h> #include <sqlite3.h>  bool isexist=false; static int callback(void *notused, int argc, char **argv, char **azcolname){         printf("i being called\n");   if (argc>0) isexist = true;   return 0; }  int main(int argc, char **argv){   sqlite3 *db;   char *zerrmsg = 0;   int rc;    rc = sqlite3_open("test.db", &db);   if( rc ){     fprintf(stderr, "can't open database: %s\n", sqlite3_errmsg(db));     sqlite3_close(db);     return(1);   }    //char* sqlcreatetable = "create table table1(name text);";   //rc = sqlite3_exec(db, sqlcreatetable, callback, 0, &zerrmsg);    // callback not called if table not yet created   char* sql_hastable = "select name sqlite_master type = 'table' , name ='table1';";   rc = sqlite3_exec(db, sql_hastable, callback, 0, &zerrmsg);   if( rc!=sqlite_ok ){     fprintf(stderr, "sql error: %s\n", zerrmsg);     sqlite3_free(zerrmsg);   }   sqlite3_close(db);   return 0; } 


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -