/* Function to initialize the book DB */ book_db *NewBookDB(int depth){ book_db *newBookDB; newBookDB=malloc(sizeof(book_db)); newBookDB->books=CreateDB(depth); return newBookDB; }
/** * @brief Initializes database. * @param filename Filename of database to load. * @return int DB_OK if database is opened, DB_MISSING if file is missing or database could not be opened. */ int InitDB(char* filename) { //if(!FileExists(filename)) { CreateDB(filename); } int rc = sqlite3_open(filename, &database); if( rc ) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(database)); sqlite3_close(database); return(DB_EMISSING); } return DB_OK; }
BOOL CheckDBExists(CString csDBPath) { //If this is the first time running this version then convert the old database to the new db if(csDBPath.IsEmpty() && g_Opt.m_bU3 == false) { csDBPath = GetDefaultDBName(); if(FileExists(csDBPath) == FALSE && CGetSetOptions::GetIsPortableDitto() == FALSE) { CString csOldDB = CGetSetOptions::GetDBPathOld(); if(csOldDB.IsEmpty()) { csOldDB = GetOLDDefaultDBName(); } if(FileExists(csOldDB)) { //create the new sqlite db CreateDB(csDBPath); CAccessToSqlite Convert; Convert.ConvertDatabase(csDBPath, csOldDB); } } } BOOL bRet = FALSE; if(FileExists(csDBPath) == FALSE) { csDBPath = GetDefaultDBName(); nsPath::CPath FullPath(csDBPath); CString csPath = FullPath.GetPath().GetStr(); if(csPath.IsEmpty() == false && FileExists(csDBPath) == FALSE) { CreateDirectory(csPath, NULL); } // -- create a new one bRet = CreateDB(csDBPath); } else { if(ValidDB(csDBPath) == FALSE) { //Db existed but was bad CString csMarkAsBad; csMarkAsBad = csDBPath; csMarkAsBad.Replace(_T("."), _T("_BAD.")); CString csPath = GetDefaultDBName(); CString cs; cs.Format(_T("%s \"%s\",\n") _T("%s \"%s\",\n") _T("%s,\n") _T("\"%s\""), theApp.m_Language.GetString("Database_Format", "Unrecognized Database Format"), csDBPath, theApp.m_Language.GetString("File_Renamed", "the file will be renamed"), csMarkAsBad, theApp.m_Language.GetString("New_Database", "and a new database will be created"), csPath); AfxMessageBox(cs); CFile::Rename(csDBPath, csMarkAsBad); csDBPath = csPath; bRet = CreateDB(csDBPath); } else { bRet = TRUE; } } if(bRet) { bRet = OpenDatabase(csDBPath); } return bRet; }