re-create DB if its file is corrupted or encrypted with an unknown key
@@ -241,8 +241,15 @@ void CDBAdapter::open (String strDbPath, String strVer, boolean bTemp, boolean c
boolean bExist = CRhoFile::isFileExist(strDbPath.c_str());
int nRes = sqlite3_open(strDbPath.c_str(),&m_dbHandle);
- if ( !checkDbError(nRes) )
+ if ( nRes==SQLITE_NOTADB ) {//kill db and try again
+ LOG(INFO) + "Open DB: DB file exists, but it is either corrupted or encrypted with an unknown key - no way to recover, kill the DB and create it from scratch.";
+ CRhoFile::deleteFile(strDbPath.c_str());
+ nRes = sqlite3_open(strDbPath.c_str(),&m_dbHandle);
+ }
+
+ if ( !checkDbError(nRes) ) {
return;
+ }
//TODO: raise exception if error
//if (RHOCONF().getBool("encrypt_database"))
