bool LocalStorageDatabase::tryToOpenDatabase(DatabaseOpeningStrategy openingStrategy) { if (!fileExists(m_databasePath) && openingStrategy == SkipIfNonExistent) return true; if (m_databasePath.isEmpty()) { LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage"); return false; } if (!m_database.open(m_databasePath)) { LOG_ERROR("Failed to open database file %s for local storage", m_databasePath.utf8().data()); return false; } // Since a WorkQueue isn't bound to a specific thread, we have to disable threading checks // even though we never access the database from different threads simultaneously. m_database.disableThreadingChecks(); if (!migrateItemTableIfNeeded()) { // We failed to migrate the item table. In order to avoid trying to migrate the table over and over, // just delete it and start from scratch. if (!m_database.executeCommand("DROP TABLE ItemTable")) LOG_ERROR("Failed to delete table ItemTable for local storage"); } if (!m_database.executeCommand("CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL)")) { LOG_ERROR("Failed to create table ItemTable for local storage"); return false; } return true; }
bool LocalStorageDatabase::tryToOpenDatabase(DatabaseOpeningStrategy openingStrategy) { if (!fileExists(m_databaseFilename) && openingStrategy == SkipIfNonExistent) return true; if (m_databaseFilename.isEmpty()) { LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage"); return false; } // FIXME: // A StorageTracker thread may have been scheduled to delete the db we're // reopening, so cancel possible deletion. if (!m_database.open(m_databaseFilename)) { LOG_ERROR("Failed to open database file %s for local storage", m_databaseFilename.utf8().data()); return false; } if (!migrateItemTableIfNeeded()) { // We failed to migrate the item table. In order to avoid trying to migrate the table over and over, // just delete it and start from scratch. if (!m_database.executeCommand("DROP TABLE ItemTable")) LOG_ERROR("Failed to delete table ItemTable for local storage"); } if (!m_database.executeCommand("CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL)")) { LOG_ERROR("Failed to create table ItemTable for local storage"); return false; } return true; }
void StorageAreaSync::openDatabase(OpenDatabaseParamType openingStrategy) { ASSERT(!isMainThread()); ASSERT(!m_database.isOpen()); ASSERT(!m_databaseOpenFailed); SQLiteTransactionInProgressAutoCounter transactionCounter; String databaseFilename = m_syncManager->fullDatabaseFilename(m_databaseIdentifier); if (!fileExists(databaseFilename) && openingStrategy == SkipIfNonExistent) return; if (databaseFilename.isEmpty()) { LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage"); markImported(); m_databaseOpenFailed = true; return; } // A StorageTracker thread may have been scheduled to delete the db we're // reopening, so cancel possible deletion. StorageTracker::tracker().cancelDeletingOrigin(m_databaseIdentifier); if (!m_database.open(databaseFilename)) { LOG_ERROR("Failed to open database file %s for local storage", databaseFilename.utf8().data()); markImported(); m_databaseOpenFailed = true; return; } migrateItemTableIfNeeded(); if (!m_database.executeCommand("CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL)")) { LOG_ERROR("Failed to create table ItemTable for local storage"); markImported(); m_databaseOpenFailed = true; return; } StorageTracker::tracker().setOriginDetails(m_databaseIdentifier, databaseFilename); }