void Document::connectModels() { LOG("Establishing internal connections in document"); connect(people, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), people_with_photos, SLOT(updateQuery())); connect(people, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), people_with_photos_query, SLOT(updateQuery())); // Using updateQuery and not reload in the following connections since they use special queries and not directly displaying a database table. connect(photo_import, SIGNAL(modelChanged()), people_with_photos, SLOT(updateQuery())); connect(photo_import, SIGNAL(modelChanged()), people_with_photos_query, SLOT(updateQuery())); connect(photo_import, SIGNAL(modelChanged()), person_photos, SLOT(reload())); }
void IDBCursorBackendImpl::updateInternal(ScriptExecutionContext*, PassRefPtr<IDBCursorBackendImpl> cursor, PassRefPtr<SerializedScriptValue> prpValue, 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; RefPtr<SerializedScriptValue> value = prpValue; 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 = "UPDATE ObjectStoreData SET value = ? WHERE id = ?"; SQLiteStatement updateQuery(cursor->database(), sql); bool ok = updateQuery.prepare() == SQLResultOk; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. updateQuery.bindText(1, value->toWireString()); updateQuery.bindInt64(2, cursor->m_currentId); ok = updateQuery.step() == SQLResultDone; ASSERT_UNUSED(ok, ok); // FIXME: Better error handling. if (cursor->m_isSerializedScriptValueCursor) cursor->m_currentSerializedScriptValue = value.release(); callbacks->onSuccess(); }
/*! * \brief Functions::getSequence returns the next available sequence of specified table from database. * \param className refers to the class name, which is the table name in database. * \param db refers to the database connection. * \return next available sequence of specified table. */ qlonglong Functions::getSequence(const QString &className, QSqlDatabase *db) { qlonglong result = -1; try { SqlQuery query(db); query.prepare("select nextvalue from sequences where name = :name"); query.bindValue(":name", className); query.exec(); if(query.next()){ // If sequence exists, update the table with the new available sequence. result = query.value(0).toLongLong(); SqlQuery updateQuery(db); updateQuery.prepare("update sequences set nextvalue = :value where name = :name"); qlonglong nextValue = result + 1; updateQuery.bindValue(":value", nextValue); updateQuery.bindValue(":name", className); updateQuery.exec(); }else{ // If sequence does not exists, the system creates one and returns its next value SqlQuery query(db); query.prepare("insert into sequences(name, initialvalue, nextvalue)" "values(:name, :initialvalue, :nextvalue)"); query.bindValue(":name", className); query.bindValue(":initialvalue", 1); query.bindValue(":nextvalue", 1); query.exec(); return getSequence(className, db); } }catch(SqlException &ex){ Logger::instance()->writeRecord(Logger::severity_level::critical, "PersistenceModule", Q_FUNC_INFO, QString("Transaction Error: %1").arg(ex.what())); return -1; } return result; }
void DBHTMLFileLetterDAO::update(Letter::Ptr item) { qCDebug(lcPersistence) << "Entering DBHTMLFileLetterDAO::update with param " + item->toString(); try { m_validator->validateForUpdate(item); } catch (ValidationException *e) { throw new PersistenceException(e); } updateHtmlFile(item); QSqlQuery updateQuery(m_database); updateQuery.prepare("UPDATE LETTER SET DATE = ?, CUSTOMER = ? WHERE ID = ?;"); updateQuery.addBindValue(item->date()); updateQuery.addBindValue(item->customer()->id()); updateQuery.addBindValue(item->id()); if (!updateQuery.exec()) { qCCritical(lcPersistence) << "DBHTMLFileLetterDAO::update failed:" + updateQuery.lastError().text(); throw new PersistenceException("DBHTMLFileLetterDAO::update failed:" + updateQuery.lastError().text()); } if (updateQuery.numRowsAffected() == 0) { qCDebug(lcPersistence) << "DBHTMLFileLetterDAO::update dataset not found"; throw new PersistenceException("DBHTMLFileLetterDAO::update dataset not found"); } }
void PeopleWithPhotosQuery::setAlbum(RelationalObjectRef album_ref) { setAlbumId(album_ref.id()); if (album_ref.isValid()) updateQuery(); else clear(); }
void QTrackerDirectSyncResult::runQuery() { if (statementType() == QSparqlQuery::AskStatement || statementType() == QSparqlQuery::SelectStatement) { selectQuery(); } else if (statementType() == QSparqlQuery::InsertStatement || statementType() == QSparqlQuery::DeleteStatement) { updateQuery(); } }
bool ProfileDB::changeDescription(int profileID, QString description) { QSqlQuery updateQuery(QSqlDatabase::database(connectionName)); updateQuery.prepare("UPDATE Profiles SET Description = :desc WHERE ProfileID = :id"); updateQuery.bindValue(":desc", description); updateQuery.bindValue(":id", profileID); return updateQuery.exec(); }
bool ProfileDB::changePhoto(int profileID, QString path) { QSqlQuery updateQuery(QSqlDatabase::database(connectionName)); updateQuery.prepare("UPDATE Profiles SET Photo = :photo WHERE ProfileID = :id"); updateQuery.bindValue(":photo", path); updateQuery.bindValue(":id", profileID); return updateQuery.exec(); }
Status SessionsCollection::doRefresh(const NamespaceString& ns, const LogicalSessionRecordSet& sessions, SendBatchFn send) { auto init = [ns](BSONObjBuilder* batch) { batch->append("update", ns.coll()); batch->append("ordered", false); batch->append("allowImplicitCollectionCreation", false); }; auto add = [](BSONArrayBuilder* entries, const LogicalSessionRecord& record) { entries->append( BSON("q" << lsidQuery(record) << "u" << updateQuery(record) << "upsert" << true)); }; return runBulkCmd("updates", init, add, send, sessions); }
void DBItemDAO::update(BillItem::Ptr item) { qCDebug(lcPersistence) << "Entering DBItemDAO::update with param " + item->toString(); try { m_validator->validateForUpdate(item); } catch (ValidationException *e) { throw new PersistenceException(e); } QSqlQuery updateQuery(m_database); updateQuery.prepare("UPDATE ITEM SET DESC = ?, " "WORK_HOURS = ?, WAGE = ?, " "MATERIAL_NETCOST = ?, MATERIAL_COST = ?, MATERIAL_OVERHEAD = ?, " "FACTORY_OVERHEAD = ?, PROFIT = ?, " "CASHBACK = ?, TAX = ?, " "PRICE = ?, UNIT = ?, " "QUANTITY = ? WHERE ID = ?;" ); updateQuery.addBindValue(item->description()); updateQuery.addBindValue(item->workingHours()); updateQuery.addBindValue(item->wagePerHour().cents()); updateQuery.addBindValue(item->materialNetCost().cents()); updateQuery.addBindValue(item->materialCost().cents()); updateQuery.addBindValue(item->materialOverhead()); updateQuery.addBindValue(item->factoryOverhead()); updateQuery.addBindValue(item->profit()); updateQuery.addBindValue(item->cashback()); updateQuery.addBindValue(item->taxRate()); updateQuery.addBindValue(item->price().cents()); updateQuery.addBindValue(item->unit()); updateQuery.addBindValue(item->quantity()); updateQuery.addBindValue(item->id()); if (!updateQuery.exec()) { qCCritical(lcPersistence) << "DBItemDAO::update failed:" + updateQuery.lastError().text(); throw new PersistenceException("DBItemDAO::update failed:" + updateQuery.lastError().text()); } if (updateQuery.numRowsAffected() == 0) { qCDebug(lcPersistence) << "DBItemDAO::update failed: dataset not found"; throw new PersistenceException("DBItemDAO::update failed: dataset not found"); } updateAssocTable(item); }
void CCassandraLogAgent::queryTransactionSeed(const char* appName, StringBuffer& seed) { CriticalBlock b(transactionSeedCrit); unsigned seedInt = 0; VStringBuffer st("SELECT id FROM %s WHERE application = '%s'", transactionTable.str(), appName); setSessionOptions(defaultDB.str()); //Switch to defaultDB since it may not be the current keyspace. cassSession->connect(); executeSimpleSelectStatement(st.str(), seedInt); seed.setf("%d", seedInt); //update transactions for the next seed VStringBuffer updateQuery("UPDATE %s SET id=%d WHERE application = '%s'", transactionTable.str(), ++seedInt, appName); executeSimpleStatement(updateQuery.str()); cassSession->disconnect(); }
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()); } }
bool LogBook::createDatabaseStructures() { bool result = true; QSqlDatabase db = QSqlDatabase::database("LogBook"); // See if the tables alreadt exist. QStringList tableList = db.tables(); bool systemTableExists = tableList.contains("logbook_system"); // Get the last record, if it exists QSqlQuery query(db); if (!systemTableExists || query.exec("SELECT last_script_run FROM logbook_system")) { int lastFile = 0; if (systemTableExists) { while (query.next()) { lastFile = query.value(0).toInt(); } } QString path = ":/logbook/"; QDir dir(path); QStringList entries = dir.entryList(QDir::Files, QDir::Name); QListIterator<QString> entriesIterator(entries); QSqlQuery updateQuery(db); updateQuery.prepare("UPDATE logbook_system SET last_script_run = :new WHERE last_script_run = :old"); while (entriesIterator.hasNext() && result) { QString fileName = entriesIterator.next(); int currentFile = fileName.section(".", 0, 0).toInt(); if (fileName.endsWith("sql") && currentFile > lastFile) { if (!processSqlFile(QString(path).append(fileName))) { result = false; } else { //If this is the first file, it MUST create logbook_system if (!systemTableExists) { if(query.exec("SELECT last_script_run FROM logbook_system")){ if(query.exec("INSERT INTO logbook_system (last_script_run) VALUES (0)")) { systemTableExists = true; } else { result = false; qDebug() << "LogBook: Error updateing system table 1. Error is: " << query.lastError(); } } else { result = false; qDebug() << "LogBook: Error reading system table 1. Error is: " << query.lastError(); } } // update the record updateQuery.bindValue(":new", currentFile); updateQuery.bindValue(":old", lastFile); QString sql("UPDATE logbook_system SET last_script_run = "); sql.append(QVariant(currentFile).toString()).append(" WHERE last_script_run = ").append(QVariant(lastFile).toString()); if (query.exec(sql)) { lastFile = currentFile; } else { result = false; qDebug() << "LogBook: Error updateing system table; bind values are (" << updateQuery.boundValues() << "). \n\tError is: " << query.lastError() << "\n\tThe query was: " << query.lastQuery() ; } } } } } else { result = false; qDebug() << "LogBook: Error reading system table 2. Error is: " << query.lastError(); } return result; }