void DataStore::removeSongsFromLibrary(const QSet<library_song_id_t>& toRemove, QProgressDialog* progress) { bool isTransacting = database.transaction(); QSqlQuery deleteQuery(database); deleteQuery.prepare("UPDATE " + getLibraryTableName() + " " "SET " + getLibIsDeletedColName() + "=1, "+ getLibSyncStatusColName() + "=" + QString::number(getLibNeedsDeleteSyncStatus()) + " " "WHERE " + getLibIdColName() + "= ?"); int i=0; Q_FOREACH(library_song_id_t id, toRemove){ deleteQuery.bindValue(0, QVariant::fromValue<library_song_id_t>(id)); EXEC_SQL( "Error setting song sync status", deleteQuery.exec(), deleteQuery) if(progress != NULL){ progress->setValue(i); if(progress->wasCanceled()){ if(isTransacting){ database.rollback(); } break; } } ++i; }
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 IDBCursorBackendImpl::removeInternal(ScriptExecutionContext*, PassRefPtr<IDBCursorBackendImpl> cursor, PassRefPtr<IDBCallbacks> callbacks) { // FIXME: This method doesn't update indexes. It's dangerous to call in its current state. callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Not implemented.")); return; if (!cursor->m_query || cursor->m_currentId == InvalidId) { // FIXME: Use the proper error code when it's specced. callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Operation not possible.")); return; } String sql = "DELETE FROM ObjectStoreData WHERE id = ?"; SQLiteStatement deleteQuery(cursor->database(), sql); bool ok = deleteQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. deleteQuery.bindInt64(1, cursor->m_currentId); ok = deleteQuery.step() == SQLResultDone; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. cursor->m_currentId = InvalidId; cursor->m_currentSerializedScriptValue = 0; cursor->m_currentIDBKeyValue = 0; callbacks->onSuccess(); }
string OAuthClient::getSignedUrl(string url, bool post, bool remove, bool put){ // cout << "Get URL signed" << endl; string urlSigned=""; string parameter; size_t pos = url.find(questionMark); string query; if(remove) query = deleteQuery(url, true); else if(post) query = postQuery(url, true); else if(put) query = putQuery(url, true); else query = getQuery(url, true); if(pos!=string::npos){ // if '?' found parameter = url.substr(pos+1, url.size()-1); url = url.substr(0,pos); } urlSigned = url + questionMark + query; return urlSigned; }
// Takes care of all the choices the user can // make with the menu. void LogIn::menuChoices() { switch(choice) { case 1: createAccount(); cout << endl; mainMenu(); break; case 2: getUserInfo(); cout << endl; mainMenu(); break; case 3: deleteQuery(); deleteAccount(); break; case 4: displayContents(); mainMenu(); break; case 9: cout << "You have exitted the program.\n"; exit(EXIT_SUCCESS); } }
static void doDelete(SQLiteDatabase& db, const char* sql, int64_t id) { SQLiteStatement deleteQuery(db, sql); bool ok = deleteQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. deleteQuery.bindInt64(1, id); ok = deleteQuery.step() == SQLResultDone; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. }
static bool deleteIndexData(SQLiteDatabase& db, int64_t objectStoreDataId) { SQLiteStatement deleteQuery(db, "DELETE FROM IndexData WHERE objectStoreDataId = ?"); if (deleteQuery.prepare() != SQLResultOk) return false; deleteQuery.bindInt64(1, objectStoreDataId); return deleteQuery.step() == SQLResultDone; }
void ScreenshotManager::clearHistory() { if (!mHistoryInitialized) { initHistory(); } QSqlQuery deleteQuery("DELETE FROM history"); deleteQuery.exec(); QSqlQuery vacQuery("VACUUM"); vacQuery.exec(); }
PlayCountsDatabase::PlayCountsDatabase( const QString& path ) : m_path( path ) { qDebug() << path; m_db = QSqlDatabase::addDatabase( "QSQLITE", path /*connection-name*/ ); m_db.setDatabaseName( path ); m_db.open(); if ( !m_db.isValid() ) throw "Could not open " + path; // rename the old table name if it exists if ( m_db.tables().contains(TABLE_NAME_OLD) ) { QSqlQuery deleteQuery( m_db ); deleteQuery.exec( QString( "ALTER TABLE itunes_db RENAME TO itunes_db_%1" ).arg( QDateTime::currentDateTimeUtc().toString( "yyyyMMddhhmmsszzz" ) ) ); } // create the playcounts table if it doesn't already exist if ( !m_db.tables().contains( TABLE_NAME ) ) { QSqlQuery query( m_db ); query.exec( "CREATE TABLE " TABLE_NAME " ( " SCHEMA " );" ); query.exec( "CREATE INDEX " INDEX "_idx ON " TABLE_NAME " ( " INDEX " );" ); } m_query = new QSqlQuery( m_db ); m_query->prepare( "SELECT play_count FROM " TABLE_NAME " WHERE persistent_id = :pid LIMIT 1" ); QSqlQuery snapshotQuery( m_db ); snapshotQuery.exec( "SELECT persistent_id, play_count FROM " TABLE_NAME " ORDER BY persistent_id ASC" ); if ( snapshotQuery.first() ) { do { bool ok; int count = snapshotQuery.value( 1 ).toInt( &ok ); if ( ok ) m_snapshot[snapshotQuery.value(0).toString()] = count; } while ( snapshotQuery.next() ); } }
Context::~Context() { mState.reset(); while (!mFramebufferMap.empty()) { // Delete the framebuffer in reverse order to destroy the framebuffer zero last. deleteFramebuffer(mFramebufferMap.rbegin()->first); } while (!mFenceNVMap.empty()) { deleteFenceNV(mFenceNVMap.begin()->first); } while (!mQueryMap.empty()) { deleteQuery(mQueryMap.begin()->first); } while (!mVertexArrayMap.empty()) { deleteVertexArray(mVertexArrayMap.begin()->first); } mTransformFeedbackZero.set(NULL); while (!mTransformFeedbackMap.empty()) { deleteTransformFeedback(mTransformFeedbackMap.begin()->first); } for (auto &zeroTexture : mZeroTextures) { zeroTexture.second.set(NULL); } mZeroTextures.clear(); if (mResourceManager) { mResourceManager->release(); } SafeDelete(mCompiler); }
void IDBObjectStoreBackendImpl::removeIndex(const String& name, PassRefPtr<IDBCallbacks> callbacks) { if (!m_indexes.contains(name)) { callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::NOT_FOUND_ERR, "Index name does not exist.")); return; } SQLiteStatement deleteQuery(sqliteDatabase(), "DELETE FROM Indexes WHERE name = ? AND objectStoreId = ?"); bool ok = deleteQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. deleteQuery.bindText(1, name); deleteQuery.bindInt64(2, m_id); ok = deleteQuery.step() == SQLResultDone; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. // FIXME: Delete index data as well. m_indexes.remove(name); callbacks->onSuccess(); }
void CleanupTask::CleanupOrphanedLiveTV(void) { QDateTime fourHoursAgo = MythDate::current().addSecs(-4 * 60 * 60); MSqlQuery query(MSqlQuery::InitCon()); MSqlQuery deleteQuery(MSqlQuery::InitCon()); // Keep these tvchains, they may be in use. query.prepare("SELECT DISTINCT chainid FROM tvchain " "WHERE endtime > :FOURHOURSAGO ;"); query.bindValue(":FOURHOURSAGO", fourHoursAgo); if (!query.exec() || !query.isActive()) { MythDB::DBError("HouseKeeper Cleaning TVChain Table", query); return; } QString msg, keepChains; while (query.next()) if (keepChains.isEmpty()) keepChains = "'" + query.value(0).toString() + "'"; else keepChains += ", '" + query.value(0).toString() + "'"; if (keepChains.isEmpty()) msg = "DELETE FROM tvchain WHERE endtime < now();"; else { msg = QString("DELETE FROM tvchain " "WHERE chainid NOT IN ( %1 ) AND endtime < now();") .arg(keepChains); } deleteQuery.prepare(msg); if (!deleteQuery.exec()) MythDB::DBError("CleanupTask::CleanupOrphanedLiveTV", deleteQuery); }
void CookieDatabaseBackingStore::invokeOpen(const String& cookieJar) { ASSERT(isCurrentThread()); if (m_db.isOpen()) close(); if (!m_db.open(cookieJar)) { LOG_ERROR("Could not open the cookie database. No cookie will be stored!"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); return; } m_db.executeCommand("PRAGMA locking_mode=EXCLUSIVE;"); m_db.executeCommand("PRAGMA journal_mode=TRUNCATE;"); const String primaryKeyFields("PRIMARY KEY (protocol, host, path, name)"); const String databaseFields("name TEXT, value TEXT, host TEXT, path TEXT, expiry DOUBLE, lastAccessed DOUBLE, isSecure INTEGER, isHttpOnly INTEGER, creationTime DOUBLE, protocol TEXT"); // Update table to add the new column creationTime and protocol for backwards compatability. upgradeTableIfNeeded(databaseFields, primaryKeyFields); // Create table if not exsist in case that the upgradeTableIfNeeded() failed accidentally. String createTableQuery("CREATE TABLE IF NOT EXISTS "); createTableQuery += m_tableName; // This table schema is compliant with Mozilla's. createTableQuery += " (" + databaseFields + ", " + primaryKeyFields+");"; if (!m_db.executeCommand(createTableQuery)) { LOG_ERROR("Could not create the table to store the cookies into. No cookie will be stored!"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); close(); return; } String insertQuery("INSERT OR REPLACE INTO "); insertQuery += m_tableName; insertQuery += " (name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly, creationTime, protocol) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10);"; m_insertStatement = new SQLiteStatement(m_db, insertQuery); if (m_insertStatement->prepare()) { LOG_ERROR("Cannot save cookies"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); } String updateQuery("UPDATE "); updateQuery += m_tableName; // The where statement is chosen to match CookieMap key. updateQuery += " SET name = ?1, value = ?2, host = ?3, path = ?4, expiry = ?5, lastAccessed = ?6, isSecure = ?7, isHttpOnly = ?8, creationTime = ?9, protocol = ?10 where protocol = ?10 and name = ?1 and host = ?3 and path = ?4;"; m_updateStatement = new SQLiteStatement(m_db, updateQuery); if (m_updateStatement->prepare()) { LOG_ERROR("Cannot update cookies"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); } String deleteQuery("DELETE FROM "); deleteQuery += m_tableName; // The where statement is chosen to match CookieMap key. deleteQuery += " WHERE name=?1 and host=?2 and path=?3 and protocol=?4;"; m_deleteStatement = new SQLiteStatement(m_db, deleteQuery); if (m_deleteStatement->prepare()) { LOG_ERROR("Cannot delete cookies"); LOG_ERROR("SQLite Error Message: %s", m_db.lastErrorMsg()); } }
void CleanupTask::CleanupRecordedTables(void) { MSqlQuery query(MSqlQuery::InitCon()); MSqlQuery deleteQuery(MSqlQuery::InitCon()); int tableIndex = 0; // tables[tableIndex][0] is the table name // tables[tableIndex][1] is the name of the column on which the join is // performed QString tables[][2] = { { "recordedprogram", "progstart" }, { "recordedrating", "progstart" }, { "recordedcredits", "progstart" }, { "recordedmarkup", "starttime" }, { "recordedseek", "starttime" }, { "", "" } }; // This blank entry must exist, do not remove. QString table = tables[tableIndex][0]; QString column = tables[tableIndex][1]; // Because recordedseek can have millions of rows, we don't want to JOIN it // with recorded. Instead, pull out DISTINCT chanid and starttime into a // temporary table (resulting in tens, hundreds, or--at most--a few // thousand rows) for the JOIN QString querystr; querystr = "CREATE TEMPORARY TABLE IF NOT EXISTS temprecordedcleanup ( " "chanid int(10) unsigned NOT NULL default '0', " "starttime datetime NOT NULL default '0000-00-00 00:00:00' " ");"; if (!query.exec(querystr)) { MythDB::DBError("CleanupTask::CleanupRecordedTables" "(creating temporary table)", query); return; } while (!table.isEmpty()) { query.prepare(QString("TRUNCATE TABLE temprecordedcleanup;")); if (!query.exec() || !query.isActive()) { MythDB::DBError("CleanupTask::CleanupRecordedTables" "(truncating temporary table)", query); return; } query.prepare(QString("INSERT INTO temprecordedcleanup " "( chanid, starttime ) " "SELECT DISTINCT chanid, starttime " "FROM %1;") .arg(table)); if (!query.exec() || !query.isActive()) { MythDB::DBError("CleanupTask::CleanupRecordedTables" "(cleaning recorded tables)", query); return; } query.prepare(QString("SELECT DISTINCT p.chanid, p.starttime " "FROM temprecordedcleanup p " "LEFT JOIN recorded r " "ON p.chanid = r.chanid " "AND p.starttime = r.%1 " "WHERE r.chanid IS NULL;").arg(column)); if (!query.exec() || !query.isActive()) { MythDB::DBError("CleanupTask::CleanupRecordedTables" "(cleaning recorded tables)", query); return; } deleteQuery.prepare(QString("DELETE FROM %1 " "WHERE chanid = :CHANID " "AND starttime = :STARTTIME;") .arg(table)); while (query.next()) { deleteQuery.bindValue(":CHANID", query.value(0).toString()); deleteQuery.bindValue(":STARTTIME", query.value(1)); if (!deleteQuery.exec()) { MythDB::DBError("CleanupTask::CleanupRecordedTables" "(cleaning recorded tables)", deleteQuery); return; } } tableIndex++; table = tables[tableIndex][0]; column = tables[tableIndex][1]; } if (!query.exec("DROP TABLE temprecordedcleanup;")) MythDB::DBError("CleanupTask::CleanupRecordedTables" "(deleting temporary table)", query); }
Packet db::recivePacket(void) { Packet packet = parsePacket(); deleteQuery(id); return packet; }