c++ - Null pointer sqlite3 handle after passed to function call -


when use function in c++ init sqlite3, when comes out of function handle null. idea might cause this? hand pointer on parameter. if move open main function works fine. happens causes this? hidden , going out of scope?

#include <iostream> #include "sqlite3.h"  using namespace std;  int init_table(sqlite3 *dbh,  string db_name) {   if (sqlite3_open(db_name.c_str(), &dbh) != sqlite_ok)     {       cout << "failed open db : " << sqlite3_errmsg(dbh) << endl;       abort();     }   else     {       cout << "opened database: " << db_name << endl;     }    if (sqlite3_exec(dbh, "pragma synchronous = off", null, null, null) != sqlite_ok)     {       cout << "failed set synchronous: " << sqlite3_errmsg(dbh) << endl;     }    if (sqlite3_exec(dbh, "pragma journal_mode = wal", null, null, null) != sqlite_ok)     {       cout << "failed set journal mode: " << sqlite3_errmsg(dbh) << endl;     }    cout << "dbh 2: " << dbh << endl;  }  int main() {   sqlite3 * dbh;   dbh = null;   cout << "dbh 1: " << dbh << endl;   string dbname = "foo1.db";   init_table(dbh, dbname);    cout << "dbh 3: " << dbh << endl; } 

and when run

$ ./a.out dbh 1: 0 opened database: foo1.db dbh 2: 0x5baa048 dbh 3: 0 

should

int init_table(sqlite3 **dbh,  string db_name)   

and pass pointer pointer?
may has no problem sqliter handling. either pass pointer reference or pointer pointer.

ofcourse, while passing, need pass &dbh init_table after modification.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -