void CookieDatabaseBackingStore::invokeRemoveAll() { ASSERT(isCurrentThread()); if (!m_db.isOpen()) return; CookieLog("CookieBackingStore - remove All cookies from backingstore"); { MutexLocker lock(m_mutex); m_changedCookies.clear(); } String deleteQuery("DELETE FROM "); deleteQuery += m_tableName; deleteQuery += ";"; SQLiteStatement deleteStatement(m_db, deleteQuery); if (deleteStatement.prepare()) { LOG_ERROR("Could not prepare DELETE * statement"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Cannot delete cookie from database"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } }
void LocalStorageDatabaseTracker::removeDatabaseWithOriginIdentifier(const String& originIdentifier) { openTrackerDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; String path = pathForDatabaseWithOriginIdentifier(originIdentifier); if (path.isEmpty()) return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data()); return; } deleteStatement.bindText(1, originIdentifier); if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of origin '%s'", originIdentifier.ascii().data()); return; } SQLiteFileSystem::deleteDatabaseFile(path); m_origins.remove(originIdentifier); if (m_origins.isEmpty()) { // There are no origins left; delete the tracker database. m_database.close(); SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath()); deleteEmptyDirectory(m_localStorageDirectory); } // FIXME: Tell clients that the origin was removed. }
void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems) { if (!m_database.isOpen()) openDatabase(CreateIfNonExistent); if (!m_database.isOpen()) return; if (m_shouldClearItems) { m_shouldClearItems = false; SQLiteStatement clearStatement(m_database, "DELETE FROM ItemTable"); if (clearStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare clear statement - cannot write to local storage database"); return; } int result = clearStatement.step(); if (result != SQLITE_DONE) { LOG_ERROR("Failed to clear all items in the local storage database - %i", result); return; } } SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)"); if (insertStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database"); return; } SQLiteStatement deleteStatement(m_database, "DELETE FROM ItemTable WHERE key=?"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare delete statement - cannot write to local storage database"); return; } SQLiteTransaction transaction(m_database); transaction.begin(); for (auto it = changedItems.begin(), end = changedItems.end(); it != end; ++it) { // A null value means that the key/value pair should be deleted. SQLiteStatement& statement = it->value.isNull() ? deleteStatement : insertStatement; statement.bindText(1, it->key); // If we're inserting a key/value pair, bind the value as well. if (!it->value.isNull()) statement.bindBlob(2, it->value); int result = statement.step(); if (result != SQLITE_DONE) { LOG_ERROR("Failed to update item in the local storage database - %i", result); break; } statement.reset(); } transaction.commit(); }
bool QgsOSMXmlImport::closeDatabase() { if ( !mDatabase ) return false; deleteStatement( mStmtInsertNode ); deleteStatement( mStmtInsertNodeTag ); deleteStatement( mStmtInsertWay ); deleteStatement( mStmtInsertWayNode ); deleteStatement( mStmtInsertWayTag ); Q_ASSERT( mStmtInsertNode == 0 ); QgsSLConnect::sqlite3_close( mDatabase ); mDatabase = 0; return true; }
void StorageTracker::syncDeleteOrigin(const String& originIdentifier) { ASSERT(!isMainThread()); MutexLocker locker(m_databaseMutex); if (!canDeleteOrigin(originIdentifier)) { LOG_ERROR("Attempted to delete origin '%s' while it was being created\n", originIdentifier.ascii().data()); return; } openTrackerDatabase(false); if (!m_database.isOpen()) return; String path = databasePathForOrigin(originIdentifier); if (path.isEmpty()) { // It is possible to get a request from the API to delete the storage for an origin that // has no such storage. return; } SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?"); if (deleteStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data()); return; } deleteStatement.bindText(1, originIdentifier); if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of origin '%s'", originIdentifier.ascii().data()); return; } SQLiteFileSystem::deleteDatabaseFile(path); bool shouldDeleteTrackerFiles = false; { MutexLocker locker(m_originSetMutex); m_originSet.remove(originIdentifier); shouldDeleteTrackerFiles = m_originSet.isEmpty(); } if (shouldDeleteTrackerFiles) { m_database.close(); SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath()); SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_storageDirectoryPath); } { MutexLocker locker(m_clientMutex); if (m_client) m_client->dispatchDidModifyOrigin(originIdentifier); } }
void StorageTracker::syncDeleteAllOrigins() { ASSERT(!isMainThread()); MutexLocker locker(m_databaseMutex); openTrackerDatabase(false); if (!m_database.isOpen()) return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); if (statement.prepare() != SQLResultOk) { LOG_ERROR("Failed to prepare statement."); return; } int result; while ((result = statement.step()) == SQLResultRow) { if (!canDeleteOrigin(statement.getColumnText(0))) continue; SQLiteFileSystem::deleteDatabaseFile(statement.getColumnText(1)); { MutexLocker locker(m_clientMutex); if (m_client) m_client->dispatchDidModifyOrigin(statement.getColumnText(0)); } } if (result != SQLResultDone) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) m_database.close(); if (!SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath())) { // In the case where it is not possible to delete the database file (e.g some other program // like a virus scanner is accessing it), make sure to remove all entries. openTrackerDatabase(false); if (!m_database.isOpen()) return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); if (deleteStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of all origins"); return; } } SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_storageDirectoryPath); }
void LocalStorageDatabaseTracker::deleteAllDatabases() { m_origins.clear(); openTrackerDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare statement."); return; } int result; while ((result = statement.step()) == SQLITE_ROW) { deleteFile(statement.getColumnText(1)); // FIXME: Call out to the client. } if (result != SQLITE_DONE) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) m_database.close(); if (!deleteFile(trackerDatabasePath())) { // In the case where it is not possible to delete the database file (e.g some other program // like a virus scanner is accessing it), make sure to remove all entries. openTrackerDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of all origins"); return; } } deleteEmptyDirectory(m_localStorageDirectory); }
void CookieDatabaseBackingStore::removeLastAccessedCookies() { if (!m_db.isOpen()) return; SQLiteStatement deleteStatement(m_db, "DELETE FROM cookies WHERE (name, value, host, path) lastAccessed IN (SELECT name, value, host, path FROM cookies ORDER BY lastAccessed ASC LIMIT ?1);"); deleteStatement.bindInt64(1, s_cookiesToDeleteWhenLimitReached); if (deleteStatement.prepare()) { LOG_ERROR("Could not prepare DELETE * statement"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Cannot delete cookie from database"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } }
void CookieDatabaseBackingStore::removeAll() { if (!m_db.isOpen()) return; { MutexLocker lock(m_mutex); m_changedCookies.clear(); } SQLiteStatement deleteStatement(m_db, "DELETE FROM cookies;"); if (deleteStatement.prepare()) { LOG_ERROR("Could not prepare DELETE * statement"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Cannot delete cookie from database"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } }
bool QgsOSMDatabase::close() { deleteStatement( mStmtNode ); deleteStatement( mStmtNodeTags ); deleteStatement( mStmtWay ); deleteStatement( mStmtWayNode ); deleteStatement( mStmtWayNodePoints ); deleteStatement( mStmtWayTags ); Q_ASSERT( !mStmtNode ); // close database if ( QgsSLConnect::sqlite3_close( mDatabase ) != SQLITE_OK ) { //mError = ( char * ) "Closing SQLite3 database failed."; //return false; } mDatabase = nullptr; return true; }
void LessStylesheet::deleteLessRuleset(LessRuleset &ruleset) { lessrulesets.remove(&ruleset); deleteStatement(ruleset); }
void StorageTracker::syncDeleteOrigin(const String& originIdentifier) { ASSERT(!isMainThread()); MutexLocker lockDatabase(m_databaseGuard); if (!canDeleteOrigin(originIdentifier)) { LOG_ERROR("Attempted to delete origin '%s' while it was being created\n", originIdentifier.ascii().data()); return; } openTrackerDatabase(false); if (!m_database.isOpen()) return; // Get origin's db file path, delete entry in tracker's db, then delete db file. SQLiteStatement pathStatement(m_database, "SELECT path FROM Origins WHERE origin=?"); if (pathStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare selection of path for origin '%s'", originIdentifier.ascii().data()); return; } pathStatement.bindText(1, originIdentifier); int result = pathStatement.step(); if (result != SQLResultRow) { LOG_ERROR("Unable to find origin '%s' in Origins table", originIdentifier.ascii().data()); return; } String path = pathStatement.getColumnText(0); ASSERT(!path.isEmpty()); SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?"); if (deleteStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data()); return; } deleteStatement.bindText(1, originIdentifier); if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of origin '%s'", originIdentifier.ascii().data()); return; } SQLiteFileSystem::deleteDatabaseFile(path); bool shouldDeleteTrackerFiles = false; { MutexLocker originLock(m_originSetGuard); m_originSet.remove(originIdentifier); shouldDeleteTrackerFiles = m_originSet.isEmpty(); } if (shouldDeleteTrackerFiles) { m_database.close(); SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath()); SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_storageDirectoryPath); } { MutexLocker lockClient(m_clientGuard); if (m_client) m_client->dispatchDidModifyOrigin(originIdentifier); } }
void Stylesheet::deleteMediaQuery(MediaQuery& query) { deleteStatement(query); }
void Stylesheet::deleteAtRule(AtRule& atrule) { atrules.remove(&atrule); deleteStatement(atrule); }
void Stylesheet::deleteRuleset(Ruleset& ruleset) { rulesets.remove(&ruleset); deleteStatement(ruleset); }
void LessStylesheet::deleteMixin(Mixin &mixin) { deleteStatement(mixin); }
void StorageTracker::syncDeleteAllOrigins() { ASSERT(!isMainThread()); SQLiteTransactionInProgressAutoCounter transactionCounter; LockHolder locker(m_databaseMutex); openTrackerDatabase(false); if (!m_database.isOpen()) return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); if (statement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare statement."); return; } int result; while ((result = statement.step()) == SQLITE_ROW) { if (!canDeleteOrigin(statement.getColumnText(0))) continue; deleteFile(statement.getColumnText(1)); { LockHolder locker(m_clientMutex); if (m_client) m_client->dispatchDidModifyOrigin(statement.getColumnText(0)); } } if (result != SQLITE_DONE) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) { #if PLATFORM(IOS) truncateDatabaseFile(m_database); #endif m_database.close(); } #if !PLATFORM(IOS) if (!deleteFile(trackerDatabasePath())) { // In the case where it is not possible to delete the database file (e.g some other program // like a virus scanner is accessing it), make sure to remove all entries. openTrackerDatabase(false); if (!m_database.isOpen()) return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } if (!deleteStatement.executeCommand()) { LOG_ERROR("Unable to execute deletion of all origins"); return; } } deleteEmptyDirectory(m_storageDirectoryPath); #endif }