void MetadataUpdater::processPendingIndices() { Q_ASSERT(thread() == this); if (hasTermChanged()) runQuery(); if (areThereResultsToProcess()) { const int i = nextIndexToProcess(); fetchValuesForResult(i, resultForRow(i)); QTimer::singleShot(10, this, SLOT(processPendingIndices())); } }
Resource MySQLConnector::getResource(int ID) { QString stmt = QString("SELECT * FROM resource WHERE ID='%1'").arg(ID); Resource tmpResource; tmpResource.ID = -1; QSqlQuery query; if(runQuery(stmt, &query, true)) { if(query.next()) tmpResource = fillResourceData(query); } return tmpResource; }
/** * get category_ID from category table and get items form Items table * that has the retrieved cat_ID */ QList<Item> MySQLConnector::getItemsof(QString category) { QList<Item> itemList; QSqlQuery query; QString stmt = QString("SELECT item.ID, category_ID, Formula_ID, Reference_No, Description, Unit, " "Date_Created FROM category join item WHERE category.name='%1' and " "category.ID = item.Category_ID").arg(category); if(runQuery(stmt, &query, true)) itemList = processItems(query); foreach(Item itm, itemList) itm.category = category; return itemList; }
// ---------------------------------------------------------------------------| void NCBaseQueryTestEngine::setLogLevel( shared_ptr<AbstractNCSession> session, const string& logLevel ) { vector<string> expPresent = { "ok" }; vector<string> expNotPresent = { "error", "rpc-error" }; // build a load module message for test.yang string queryStr = messageBuilder_->buildSetLogLevelMessage( logLevel, session->allocateMessageId() ); StringsPresentNotPresentChecker checker( expPresent, expNotPresent ); runQuery( session, queryStr, checker ); }
QSqlQuery damagecalculatordialog::createAndRunSpecificQuery(const QString& selectSQL) { QString sql = "SELECT "; QSqlQuery result; sql.append(selectSQL); sql.append(" FROM "); sql.append(this->weaponType); sql.append(" WHERE name=\""); sql.append(this->weapon); sql.append("\""); result = runQuery(sql); result.next(); return result; }
TaskList SqlStorage::getAllTasks() { TaskList tasks; QSqlQuery query(database()); query.prepare(QStringLiteral("select * from Tasks left join Subscriptions on Tasks.task_id = Subscriptions.task;")); // FIXME merge record retrieval with getTask: if (runQuery(query)) { while (query.next()) { Task task = makeTaskFromRecord( query.record() ); tasks.append(task); } } return tasks; }
bool SqlStorage::verifyDatabase() { // if the database is empty, it is not ok :-) if( database().tables().isEmpty() ) return false; // check database metadata, throw an exception in case the version does not match: int version = 1; QString versionString = getMetaData(CHARM_DATABASE_VERSION_DESCRIPTOR); if (versionString != QString::null ) { int value; bool ok; value = versionString.toInt( &ok ); if( ok) { version = value; } } if ( version == CHARM_DATABASE_VERSION ) return true; if( version > CHARM_DATABASE_VERSION ) throw UnsupportedDatabaseVersionException( QObject::tr( "Database version is too new." ) ); if ( version == CHARM_DATABASE_VERSION_BEFORE_TRACKABLE ) { SqlRaiiTransactor transactor( database() ); QSqlQuery query( database() ); query.prepare( QLatin1String("ALTER TABLE Tasks ADD trackable INTEGER") ); if ( !runQuery( query ) ) throw UnsupportedDatabaseVersionException( QObject::tr("Could not upgrade database from version %1 to version %2: %3").arg( QString::number( CHARM_DATABASE_VERSION_BEFORE_TRACKABLE ), QString::number( CHARM_DATABASE_VERSION ), query.lastError().text() ) ); version = CHARM_DATABASE_VERSION; setMetaData( CHARM_DATABASE_VERSION_DESCRIPTOR, QString::number ( version ), transactor ); transactor.commit(); return true; } throw UnsupportedDatabaseVersionException( QObject::tr( "Database version is not supported." ) ); return true; }
Result AsyncHTTPLookup::lookup ( const QString & hostName, uint port, const TrackOffsetList & trackOffsetList ) { trackOffsetList_ = trackOffsetList; connect( this, SIGNAL(queryReady()), SLOT(slotQueryReady()) ); connect( this, SIGNAL(readReady()), SLOT(requestCDInfoForMatch()) ); initURL( hostName, port ); // Run a query. result_ = runQuery(); return result_; }
bool MySqlStorage::createDatabaseTables() { Q_ASSERT_X(database().open(), Q_FUNC_INFO, "Connection to database must be established first"); bool error = false; // create tables: for (int i = 0; i < NumberOfTables; ++i) { if (!database().tables().contains(Tables[i])) { QString statement; QTextStream stream(&statement, QIODevice::WriteOnly); stream << "CREATE table `" << Tables[i] << "` ("; const Field* field = Database_Fields[i]; while (field->name != QString::null ) { stream << " `" << field->name << "` " << field->type; ++field; if ( field->name != QString::null ) stream << ", "; } stream << ");"; QSqlQuery query( database() ); qDebug() << statement; query.prepare( statement ); if ( ! runQuery( query ) ) { error = true; } } } error = error || ! setMetaData(CHARM_DATABASE_VERSION_DESCRIPTOR, QString().setNum( CHARM_DATABASE_VERSION) ); return ! error; }
void damagecalculatordialog::on_weapon_type_list_widget_clicked(const QModelIndex &index) { QSqlQuery query; QString sql = "SELECT name FROM "; // Find out if the weapon_list_widget is empty, and if not empty it if (ui->weapon_list_widget->count() > 0) ui->weapon_list_widget->clear(); // Find out if motionValueListWidget is empty, and if not empty it if (ui->motionValueListWidget->count() > 0) ui->motionValueListWidget->clear(); // Update the contents of the weapon_list_widget this->weaponType = index.data(Qt::DisplayRole).toString(); sql.append(this->weaponType); query = runQuery(sql); while(query.next()) ui->weapon_list_widget->addItem(query.value(0).toString()); // Update the contents of the motionValueListWidget // TODO: Finish this if (this->weaponType == "ChargeBlades") { QString attacks[] = {"Draw (Sword) [22]", "Upward Slash [12]", "Back Slash [17]", "Round Slash [30]", "Charge [16]", "Charge 1 [30]", "Charge 2 [20]", "Jump (Sword) [22]", "Draw (Axe) [41]", "Forward Slam [44]", "Upward Swipe [28]", "Downward Chop [41]", "Jump (Axe) [44]", "Burst 1 [14/23]", "Burst 2 [61/78]", "Burst 3 [40/80]", "Ultra Burst [maxInt]"}; int attacksSize = 17; for (int i = 0; i < attacksSize; ++i) { ui->motionValueListWidget->addItem(attacks[i]); } } }
Result SyncHTTPLookup::lookup ( const QString & hostName, uint port, const TrackOffsetList & trackOffsetList ) { trackOffsetList_ = trackOffsetList; initURL( hostName, port ); // Run a query. result_ = runQuery(); if ( Success != result_ ) return result_; kDebug(60010) << matchList_.count() << " matches found."; if (matchList_.isEmpty()) return NoRecordFound; // For each match, read the cd info from the server and save it to // cdInfoList. CDDBMatchList::ConstIterator matchIt = matchList_.constBegin(); while ( matchIt != matchList_.constEnd() ) { CDDBMatch match( *matchIt ); result_ = matchToCDInfo( match ); ++matchIt; } return result_; }
void QTrackerDirectSyncResult::run() { runQuery(); terminate(); }
/** * search for similar items with the keyword */ void MySQLConnector::searchItem(QString description) { QSqlQuery query; if(runQuery(QString("SELECT * FROM item WHERE Description LIKE '%1'").arg(description),&query , true)) processItems(query); }
void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss, bool logit) { MSGID responseTo = m.data->id; DbMessage d(m); QueryMessage q(d); QueryResult* msgdata; try { if (q.fields.get() && q.fields->errmsg) uassert(q.fields->errmsg, false); /* note these are logged BEFORE authentication -- which is sort of ok */ if ( _diaglog.level && logit ) { if ( strstr(q.ns, ".$cmd") ) { /* $cmd queries are "commands" and usually best treated as write operations */ OPWRITE; } else { OPREAD; } } setClient( q.ns ); Client& client = cc(); client.top.setRead(); strncpy(client.curop()->ns, q.ns, Namespace::MaxNsLen); msgdata = runQuery(m, ss ).release(); } catch ( AssertionException& e ) { ss << " exception "; LOGSOME problem() << " Caught Assertion in runQuery ns:" << q.ns << ' ' << e.toString() << '\n'; log() << " ntoskip:" << q.ntoskip << " ntoreturn:" << q.ntoreturn << '\n'; if ( q.query.valid() ) log() << " query:" << q.query.toString() << endl; else log() << " query object is not valid!" << endl; BSONObjBuilder err; err.append("$err", e.msg.empty() ? "assertion during query" : e.msg); BSONObj errObj = err.done(); BufBuilder b; b.skip(sizeof(QueryResult)); b.append((void*) errObj.objdata(), errObj.objsize()); // todo: call replyToQuery() from here instead of this!!! see dbmessage.h msgdata = (QueryResult *) b.buf(); b.decouple(); QueryResult *qr = msgdata; qr->resultFlags() = QueryResult::ResultFlag_ErrSet; qr->len = b.len(); qr->setOperation(opReply); qr->cursorId = 0; qr->startingFrom = 0; qr->nReturned = 1; } Message *resp = new Message(); resp->setData(msgdata, true); // transport will free dbresponse.response = resp; dbresponse.responseTo = responseTo; Database *database = cc().database(); if ( database ) { if ( database->profile ) ss << " bytes:" << resp->data->dataLen(); } else { if ( strstr(q.ns, "$cmd") == 0 ) // (this condition is normal for $cmd dropDatabase) log() << "ERROR: receiveQuery: database is null; ns=" << q.ns << endl; } }
void DatabaseQuery::start() { emit resultsReady(DataStore()); while (m_requests.count() > 0) { runQuery(); } }
static bool receivedQuery(Client& c, DbResponse& dbresponse, Message& m ) { bool ok = true; MSGID responseTo = m.header()->id; DbMessage d(m); QueryMessage q(d); auto_ptr< Message > resp( new Message() ); CurOp& op = *(c.curop()); shared_ptr<AssertionException> ex; try { if (!NamespaceString(d.getns()).isCommand()) { // Auth checking for Commands happens later. Status status = cc().getAuthorizationManager()->checkAuthForQuery(d.getns()); uassert(16550, status.reason(), status.isOK()); } dbresponse.exhaustNS = runQuery(m, q, op, *resp); verify( !resp->empty() ); } catch ( SendStaleConfigException& e ){ ex.reset( new SendStaleConfigException( e.getns(), e.getInfo().msg, e.getVersionReceived(), e.getVersionWanted() ) ); ok = false; } catch ( AssertionException& e ) { ex.reset( new AssertionException( e.getInfo().msg, e.getCode() ) ); ok = false; } if( ex ){ op.debug().exceptionInfo = ex->getInfo(); LOGWITHRATELIMIT { log() << "assertion " << ex->toString() << " ns:" << q.ns << " query:" << (q.query.valid() ? q.query.toString() : "query object is corrupt") << endl; if( q.ntoskip || q.ntoreturn ) log() << " ntoskip:" << q.ntoskip << " ntoreturn:" << q.ntoreturn << endl; } SendStaleConfigException* scex = NULL; if ( ex->getCode() == SendStaleConfigCode ) scex = static_cast<SendStaleConfigException*>( ex.get() ); BSONObjBuilder err; ex->getInfo().append( err ); if( scex ){ err.append( "ns", scex->getns() ); scex->getVersionReceived().addToBSON( err, "vReceived" ); scex->getVersionWanted().addToBSON( err, "vWanted" ); } BSONObj errObj = err.done(); if( scex ){ log() << "stale version detected during query over " << q.ns << " : " << errObj << endl; } else{ log() << "problem detected during query over " << q.ns << " : " << errObj << endl; } BufBuilder b; b.skip(sizeof(QueryResult)); b.appendBuf((void*) errObj.objdata(), errObj.objsize()); // todo: call replyToQuery() from here instead of this!!! see dbmessage.h QueryResult * msgdata = (QueryResult *) b.buf(); b.decouple(); QueryResult *qr = msgdata; qr->_resultFlags() = ResultFlag_ErrSet; if( scex ) qr->_resultFlags() |= ResultFlag_ShardConfigStale; qr->len = b.len(); qr->setOperation(opReply); qr->cursorId = 0; qr->startingFrom = 0; qr->nReturned = 1; resp.reset( new Message() ); resp->setData( msgdata, true ); } op.debug().responseLength = resp->header()->dataLen(); dbresponse.response = resp.release(); dbresponse.responseTo = responseTo; return ok; }
static bool receivedQuery(Client& c, DbResponse& dbresponse, Message& m ) { bool ok = true; MSGID responseTo = m.header()->id; DbMessage d(m); QueryMessage q(d); auto_ptr< Message > resp( new Message() ); CurOp& op = *(c.curop()); shared_ptr<AssertionException> ex; try { dbresponse.exhaust = runQuery(m, q, op, *resp); assert( !resp->empty() ); } catch ( SendStaleConfigException& e ){ ex.reset( new SendStaleConfigException( e.getns(), e.getInfo().msg ) ); ok = false; } catch ( AssertionException& e ) { ex.reset( new AssertionException( e.getInfo().msg, e.getCode() ) ); ok = false; } if( ex ){ op.debug().exceptionInfo = ex->getInfo(); LOGWITHRATELIMIT { log() << "assertion " << ex->toString() << " ns:" << q.ns << " query:" << (q.query.valid() ? q.query.toString() : "query object is corrupt") << endl; if( q.ntoskip || q.ntoreturn ) log() << " ntoskip:" << q.ntoskip << " ntoreturn:" << q.ntoreturn << endl; } SendStaleConfigException* scex = NULL; if ( ex->getCode() == SendStaleConfigCode ) scex = static_cast<SendStaleConfigException*>( ex.get() ); BSONObjBuilder err; ex->getInfo().append( err ); if( scex ) err.append( "ns", scex->getns() ); BSONObj errObj = err.done(); log() << errObj << endl; BufBuilder b; b.skip(sizeof(QueryResult)); b.appendBuf((void*) errObj.objdata(), errObj.objsize()); // todo: call replyToQuery() from here instead of this!!! see dbmessage.h QueryResult * msgdata = (QueryResult *) b.buf(); b.decouple(); QueryResult *qr = msgdata; qr->_resultFlags() = ResultFlag_ErrSet; if( scex ) qr->_resultFlags() |= ResultFlag_ShardConfigStale; qr->len = b.len(); qr->setOperation(opReply); qr->cursorId = 0; qr->startingFrom = 0; qr->nReturned = 1; resp.reset( new Message() ); resp->setData( msgdata, true ); } op.debug().responseLength = resp->header()->dataLen(); dbresponse.response = resp.release(); dbresponse.responseTo = responseTo; return ok; }
void QueryHolder::update() { runQuery(m_mode); }