I try to new a ODB dataBase, however, sometimes, if xxx.db
is not exist even I new
db success. With the code under, it cant catch exception however,it can enter if(!_file)
string dbFile = getPalBundle()->getFileStorageProvider()->getDocumentsPath(userId + "/xxx.db");
auto db = std::shared_ptr<odb::sqlite::database>(new odb::sqlite::database(dbFile, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_FULLMUTEX, false));
if(db == nullptr)
{
ret = false;
}
// check database avalible
try {
db->schema_version();
} catch (...) {
DLOG(kTagDaoFactory, "Datase file damaged, logout");
ret = false;
}
fstream _file;
_file.open(dbFile, ios::in);
if (!_file) {
ret = false;
DLOG(kTagDaoFactory, "Data base file no exist, logout");
}
I have no idea what happens, could anyone help me? Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire