Should not be the handle closed in Close and opened set to false again?
What about this fix:
bool Sqlite3Session::Open(const char* filename) {
// Only open db once.
ASSERT(NULL == db);
current_filename = filename;
// By default, sqlite3 associates the opened db with "main.*"
// However, using the ATTACH sql command, it can connect to more databases.
// I don't know how to get the list of attached databases from the API
current_dbname = "main";
if(SQLITE_OK == sqlite3_open(filename, &db))
return true;
if(db) {
sqlite3_close(db);
db = NULL;
}
return false;
}