void dbcontroller::logIP(int teamid) { std::stringstream ss; ss.str(""); ss << "teamip_" << teamid; teamip ti; std::string IP = cur_ctx->request().remote_addr(); BOOSTER_NOTICE("scoreboard") << "team " << teamid << " has IP " << IP; if (cur_ctx->cache().fetch_data(ss.str(), ti)) { for (std::vector<std::string>::iterator it = ti.seenip.begin(); it != ti.seenip.end(); ++it) { if (IP.compare(*it) == 0) { //already known IP for this team BOOSTER_DEBUG("scoreboard") << "found in cache."; return; } } } //Still not known. :( std::shared_ptr<QSqlQuery> stmt(new QSqlQuery(this->db)); bool ok = doQuery(stmt, [&](std::shared_ptr<QSqlQuery> stmt) { if (!stmt->prepare("INSERT IGNORE INTO ipteams set idteam=:team, ip=:ip;")) return false; stmt->bindValue("team", teamid); stmt->bindValue("ip", QString::fromStdString(IP)); return true; }); if (!ok) { BOOSTER_ERROR("scoreboard") << "Could not add IP to teams IPs, aborting"; return; } ok = doQuery(stmt, [&](std::shared_ptr<QSqlQuery> stmt) { if (!stmt->prepare("SELECT ip FROM ipteams WHERE idteam=:team;")) return false; stmt->bindValue("team", teamid); return true; }); if (!ok) { BOOSTER_ERROR("scoreboard") << "Could not fetch team IP, aborting"; return; } if (!ok) return; ti.id = teamid; ti.seenip.clear(); while (stmt->next()) { ti.seenip.push_back(stmt->record().value(0).toString().toStdString()); BOOSTER_DEBUG("scoreboard") << "Pushing in cache for team " << teamid << " value " << stmt->record().value(0).toString().toStdString(); } cur_ctx->cache().store_data(ss.str(), ti, -1); return; }
int dbcontroller::setChallengeSolved(int id) { int team = cur_ctx->session().get<int>("teamid"); std::shared_ptr<QSqlQuery> stmt(new QSqlQuery(this->db)); bool ok = doQuery(stmt, [&](std::shared_ptr<QSqlQuery> stmt) { if (!stmt->prepare("call SolvedChallenge(:team,:idchallenge,@points);")) return false; stmt->bindValue("team", team); stmt->bindValue("idchallenge", id); return true; }); if (!ok) { BOOSTER_ERROR("scoreboard") << "SolvedChallenge() failed, aborting"; return 0; } stmt->exec("select @points as points from dual;"); std::stringstream trigger; trigger.str(""); trigger << "teamsolved_" << team; cur_ctx->cache().rise(trigger.str()); if ((stmt->size()) == 1) { stmt->next(); return stmt->record().value("points").toInt(); } else { BOOSTER_ERROR("scoreboard") << "Something went very wrong. SP SolvedChallenge returned " << stmt->size() << " records. Team " << team << " just solved challenge " << id; return 0; } }
teamInfo dbcontroller::fetchTeamInfo(int teamId) { std::stringstream cacheKey; std::stringstream trigger; teamInfo teamInfo; cacheKey.str(""); cacheKey << "teaminfo_" << teamId; trigger.str(""); trigger << "teamsolved_" << teamId; std::shared_ptr<QSqlQuery> sqlQuery(new QSqlQuery(this->db)); bool ok = doQuery(sqlQuery, [&](std::shared_ptr<QSqlQuery> stmt) { if (!stmt->prepare("SELECT id, name, points from team where id=:id")) return false; stmt->bindValue("id", teamId); return true; }); if (!ok) { BOOSTER_ERROR("scoreboard") << "Could not fetch info for team, aborting"; return teamInfo; } if (sqlQuery->size() != 1) { //WTF? return teamInfo; } sqlQuery->next(); teamInfo.name = sqlQuery->record().value("name").toString().toStdString(); teamInfo.points = sqlQuery->record().value("points").toUInt(); cur_ctx->cache().store_data( cacheKey.str(), teamInfo, this->makeStringSet(trigger.str()), srv->settings().get<int>("cache.timeout.teaminfo") ); return teamInfo; }
virtual void queryOp( Request& r ){ QueryMessage q( r.d() ); bool lateAssert = false; log(3) << "single query: " << q.ns << " " << q.query << " ntoreturn: " << q.ntoreturn << endl; try { if ( ( q.ntoreturn == -1 || q.ntoreturn == 1 ) && strstr(q.ns, ".$cmd") ) { BSONObjBuilder builder; bool ok = Command::runAgainstRegistered(q.ns, q.query, builder); if ( ok ) { BSONObj x = builder.done(); replyToQuery(0, r.p(), r.m(), x); return; } string commandName = q.query.firstElement().fieldName(); if ( ! _commandsSafeToPass.count( commandName ) ) log() << "passing through unknown command: " << commandName << " " << q.query << endl; } lateAssert = true; doQuery( r , r.singleServerName() ); } catch ( AssertionException& e ) { assert( !lateAssert ); BSONObjBuilder err; err.append("$err", string("mongos: ") + (e.msg.empty() ? "assertion during query" : e.msg)); BSONObj errObj = err.done(); replyToQuery(QueryResult::ResultFlag_ErrSet, r.p() , r.m() , errObj); return; } }
status_t FactoryQemuClient::listCameras(char** list) { LOGV("%s", __FUNCTION__); QemuQuery query(mQueryList); if (doQuery(&query) || !query.isQuerySucceeded()) { LOGE("%s: List cameras query failed: %s", __FUNCTION__, query.mReplyData ? query.mReplyData : "No error message"); return query.getCompletionStatus(); } /* Make sure there is a list returned. */ if (query.mReplyDataSize == 0) { LOGE("%s: No camera list is returned.", __FUNCTION__); return EINVAL; } /* Copy the list over. */ *list = (char*)malloc(query.mReplyDataSize); if (*list != NULL) { memcpy(*list, query.mReplyData, query.mReplyDataSize); LOGD("Emulated camera list: %s", *list); return NO_ERROR; } else { LOGE("%s: Unable to allocate %d bytes", __FUNCTION__, query.mReplyDataSize); return ENOMEM; } }
challengesol dbcontroller::fetchSolution(std::string const& flag) { std::string cachekey = "challenge_sol_" + flag; challengesol data; if (cur_ctx->cache().fetch_data(cachekey, data)) { return data; } data.valid = false; std::shared_ptr<QSqlQuery> stmt(new QSqlQuery(this->db)); bool ok = doQuery(stmt, [&](std::shared_ptr<QSqlQuery> stmt) { if (!stmt->prepare("SELECT idchallenge, points from challenges where flaghash=sha2(:flag, 512) and opentime < NOW()")) return false; stmt->bindValue("flag", flag.c_str()); return true; }); if (!ok) { BOOSTER_ERROR("scoreboard") << "fetch solution failed, aborting"; return data; } if ((stmt->size()) == 1) { stmt->next(); data.valid = true; data.id = stmt->record().value("idchallenge").toInt(); data.points = stmt->record().value("points").toInt(); } cur_ctx->cache().store_data( cachekey, data, srv->settings().get<int>("cache.timeout.challengesol")); return data; }
const char* Format::getField() { doQuery(); switch(format.fmt.pix.field) { case V4L2_FIELD_ANY: return "Any"; case V4L2_FIELD_NONE: return "None (progressive or undetermined)"; case V4L2_FIELD_TOP: return "Top"; case V4L2_FIELD_BOTTOM: return "Bottom"; case V4L2_FIELD_INTERLACED: return "Interlaced"; case V4L2_FIELD_SEQ_TB: return "Seq TB"; case V4L2_FIELD_SEQ_BT: return "Seq BT"; case V4L2_FIELD_ALTERNATE: return "Alternate"; case V4L2_FIELD_INTERLACED_TB: return "Interlaced TB"; case V4L2_FIELD_INTERLACED_BT: return "Interlaced BT"; default: return "Unknown field code...\n"; } }
ResultSet* MySQLPreparedStatement::executeQuery() { //mysql_stmt_store_result(stmt); doQuery(); return new MySQLPreparedResultSet(this, stmt); }
void KAQuery::slotProcessQueryNow() { /* used to link a timer event to this slot * needed for asynchronous query */ if ( !doQuery() && 5==perrno && current_try<=max_retries ) { errno2str(); emit sigQueryStatus( sError ); current_try++; QTimer::singleShot( 300, this, SLOT(slotProcessQueryNow()) ); return; } // check the result errno2str(); //sError = p_err_string; // debug( p_err_string ); nError = perrno; // QString tmp; // debug( (const char*)tmp.setNum(nError) ); // sWarning = p_warn_string; // debug( p_warn_string ); nWarning = pwarn; //debug( tmp.setNum(nWarning) ); emit sigQueryFinished(); emit sigQueryStatus(i18n("Query finished")); }
point_count_t RialtoReader::read(PointViewPtr view, point_count_t /*not used*/) { // TODO: okay to ignore point count parameter? log()->get(LogLevel::Debug) << "RialtoReader::read()" << std::endl; const TileMath tmm(m_matrixSet->getTmsetMinX(), m_matrixSet->getTmsetMinY(), m_matrixSet->getTmsetMaxX(), m_matrixSet->getTmsetMaxY(), m_matrixSet->getNumColsAtL0(), m_matrixSet->getNumRowsAtL0()); setQueryParams(); const double qMinX = m_queryBox.minx; const double qMinY = m_queryBox.miny; const double qMaxX = m_queryBox.maxx; const double qMaxY = m_queryBox.maxy; const uint32_t level = m_queryLevel; m_gpkg->queryForTiles_begin(m_dataset, qMinX, qMinY, qMaxX, qMaxY, level); GpkgTile info; do { bool ok = m_gpkg->queryForTiles_step(info); if (!ok) break; doQuery(tmm, info, view, qMinX, qMinY, qMaxX, qMaxY); log()->get(LogLevel::Debug) << " resulting view now has " << view->size() << " points" << std::endl; } while (m_gpkg->queryForTiles_next()); return view->size(); }
int DbUtil::createDb(BaseString& m_db) { BaseString stm; { if(mysql_select_db(m_mysql, m_db.c_str()) == DBU_OK) { stm.assfmt("DROP DATABASE %s", m_db.c_str()); if(doQuery(m_db.c_str()) == DBU_FAILED) return DBU_FAILED; } stm.assfmt("CREATE DATABASE %s", m_db.c_str()); if(doQuery(m_db.c_str()) == DBU_FAILED) return DBU_FAILED; return DBU_OK; } }
void Connection::doQuery(sqlite3 *connection, const String &sql, DataTable &table) { table.clear(); shared_ptr<Result> result = doQuery(connection, sql); if(result != nullptr) result->bind(table); }
// ============================= TRY PARAMETERS ============================= // void Format::setWidth(int w) { if(state == FORMAT_IS_NULL || state == FORMAT_FAILED_UPDATE) { doQuery(); } format.fmt.pix.width = w; state = FORMAT_IS_DIRTY; }
bool MySQLPreparedStatement::execute() { doQuery(); my_bool bool_tmp=1; mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &bool_tmp); //mysql_stmt_store_result(stmt); return (mysql_stmt_field_count(stmt) > 0); }
void K3bCddbQuery::query( const K3bDevice::Toc& toc ) { m_bQueryFinishedEmited = false; m_toc = toc; m_inexactMatches.clear(); QTimer::singleShot( 0, this, SLOT(doQuery()) ); }
void Format::setHeight(int h) { if(state == FORMAT_IS_NULL || state == FORMAT_FAILED_UPDATE) { doQuery(); } format.fmt.pix.height = h; state = FORMAT_IS_DIRTY; }
void ImageViewer::connectWidgets(){ connect(startBtn, SIGNAL(clicked()), model, SLOT(doRegistration())); connect(model, SIGNAL(processingDone()), this, SLOT(enableQuery())); connect(queryBtn, SIGNAL(clicked()), model, SLOT(doQuery())); connect(model, SIGNAL(queryDone()), this, SLOT(showCorrespondingPoints())); connect(matchingBtn, SIGNAL(clicked()), model, SLOT(doMatching())); connect(model, SIGNAL(matchingDone()), this, SLOT(showMatchingResult())); }
virtual void queryOp( Request& r ) { QueryMessage q( r.d() ); MONGO_LOG(3) << "single query: " << q.ns << " " << q.query << " ntoreturn: " << q.ntoreturn << " options : " << q.queryOptions << endl; if ( r.isCommand() ) { if ( handleSpecialNamespaces( r , q ) ) return; int loops = 5; while ( true ) { BSONObjBuilder builder; try { BSONObj cmdObj = q.query; { BSONElement e = cmdObj.firstElement(); if ( e.type() == Object && (e.fieldName()[0] == '$' ? str::equals("query", e.fieldName()+1) : str::equals("query", e.fieldName()))) cmdObj = e.embeddedObject(); } bool ok = Command::runAgainstRegistered(q.ns, cmdObj, builder, q.queryOptions); if ( ok ) { BSONObj x = builder.done(); replyToQuery(0, r.p(), r.m(), x); return; } break; } catch ( StaleConfigException& e ) { if ( loops <= 0 ) throw e; loops--; log() << "retrying command: " << q.query << endl; ShardConnection::checkMyConnectionVersions( e.getns() ); if( loops < 4 ) versionManager.forceRemoteCheckShardVersionCB( e.getns() ); } catch ( AssertionException& e ) { e.getInfo().append( builder , "assertion" , "assertionCode" ); builder.append( "errmsg" , "db assertion failure" ); builder.append( "ok" , 0 ); BSONObj x = builder.done(); replyToQuery(0, r.p(), r.m(), x); return; } } string commandName = q.query.firstElementFieldName(); uassert(13390, "unrecognized command: " + commandName, _commandsSafeToPass.count(commandName) != 0); } doQuery( r , r.primaryShard() ); }
int MySQLStatement::executeUpdate(const std::string& sql) { doQuery(sql.c_str(), sql.length()); MYSQL* mysql = mysqlConn->getMySQLHandle(); if (mysql_field_count(mysql) > 0) { // check if the query return something throw MySQLException("MySQLStatement::executeUpdate, error the return something",mysql); } return static_cast<int>(mysql_affected_rows(mysql)); }
TablaTextAlignCenter* dbHelper::query(int op, QString what, QString where){ QString queryString; switch (op) { case 15: queryString = "select * from Visitante, ListaVisitantes where DNI like '"+what+ "' and Visitante.IDVisitante=ListaVisitantes.IDVisitante and Activo='1' and ListaVisitantes.IDEvento='"+where+ "';"; break; } return doQuery(queryString,op); }
bool DbUtil::createDb(BaseString& m_db) { BaseString stm; setDbName(m_db.c_str()); { if(selectDb()) { stm.assfmt("DROP DATABASE %s", m_db.c_str()); if(!doQuery(m_db.c_str())) return false; } stm.assfmt("CREATE DATABASE %s", m_db.c_str()); if(!doQuery(m_db.c_str())) return false; return true; } }
//距离查询 void GlobalMap::doQueryByDistance(LocationDetailPtrList& list,const QueryCase_SpatialRelation& qc){ MapCellPtrList cells; GeoRect rc; rc.x = qc.circle.center.lon - qc.circle.radius; rc.y = qc.circle.center.lat - qc.circle.radius; rc.width = qc.circle.radius * 2; rc.height = rc.width; cells = getCells(rc); doQuery(list,cells,qc); }
VsbRawInfo VsbDevice::getRawInfo() { ByteString data = doQuery(VSB_CMD_GETDEVINFO); VsbRawInfo rawInfo = { .singlekeyNumKeys = data[0], .keyseqNumKeys = data[1], .keyseqPageSize = data[2], .keyseqNumPages = data[3] }; return rawInfo; }
int main(int argc, char **argv){ // Interpret the command-lin arguments and decide if they make sense int status = parseArgs(argc, argv, &prefs); printf(COPYRIGHT); setLogLevel(LOG_INFO); if (status == FAIL){ // The command-line was duff... if (prefs.errorMsg != NULL){ // ...and we have a specific error to show the user printf("Error: %s\n", prefs.errorMsg); } else { // ...and we have no specific error message, so show a vague one printf("BitMeter did not understand. "); } printf("Use the '-h' option to display help.\n"); } else if (prefs.help){ // Dump the help info and stop doHelp(); } else if (prefs.version){ // Show the version and stop doVersion(); } else { // We will need to go to the database if we end up here openDb(); dbVersionCheck(); switch(prefs.mode){ case PREF_MODE_DUMP: doDump(); break; case PREF_MODE_SUMMARY: doSummary(); break; case PREF_MODE_MONITOR: doMonitor(); break; case PREF_MODE_QUERY: doQuery(); break; default: assert(FALSE); // Any other mode value should cause parseArgs to fail break; } closeDb(); } return 0; }
status_t CameraQemuClient::queryStop() { LOGV("%s", __FUNCTION__); QemuQuery query(mQueryStop); doQuery(&query); const status_t res = query.getCompletionStatus(); LOGE_IF(res != NO_ERROR, "%s: Query failed: %s", __FUNCTION__, query.mReplyData ? query.mReplyData : "No error message"); return res; }
bool AtrtClient::getConnectString(int cluster_id, SqlResultSet& result){ Properties args; args.put("0", cluster_id); return doQuery("SELECT value as connectstring " \ "FROM cluster c, process p, host h, options o " \ "WHERE c.id=p.cluster_id AND p.host_id=h.id AND " \ "p.id=o.process_id AND c.id=? AND " \ "o.name='--ndb-connectstring=' AND type='ndb_mgmd'", args, result); }
void leagueOverSeer::URLDone(const char* /*URL*/, const void* data, unsigned int /*size*/, bool /*complete*/) //Everything went fine with the report { std::string siteData = (const char*)(data); //Convert the data to a std::string bz_debugMessagef(1, "URL Job Successful! Data returned: %s", siteData.c_str()); if (strcmp(siteData.substr(0, 6).c_str(), "INSERT") == 0 || strcmp(siteData.substr(0, 6).c_str(), "DELETE") == 0) doQuery(siteData); else if (strcmp(siteData.c_str(), "<html>") < 0) { bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s", siteData.c_str()); bz_debugMessagef(DEBUG, "%s", siteData.c_str()); } }
unsigned long long DbUtil::selectCountTable(const char * table) { BaseString query; SqlResultSet result; query.assfmt("select count(*) as count from %s", table); if (!doQuery(query, result)) { printError("select count(*) failed"); return -1; } return result.columnAsLong("count"); }
VsbRawConfig VsbDevice::getRawConfig() { ByteString data = doQuery(VSB_CMD_GETCFG); VsbRawConfig rawConfig = { .mode = data[0], .mods = data[1], .keycodes = ByteString(data, 2, getInfo().singlekeyNumKeys), .keyseqLen = data[8] }; return rawConfig; } void VsbDevice::setRawConfig(const VsbRawConfig& rawCfg) { ByteString cmdData(3+info->singlekeyNumKeys, 0); cmdData[0] = rawCfg.mode; cmdData[1] = rawCfg.mods; cmdData[cmdData.size()-1] = rawCfg.keyseqLen; for(int i=0; (i<rawCfg.keycodes.size()) && (i < cmdData.size()-1); ++i) cmdData[i+2] = rawCfg.keycodes[i]; doQuery(VSB_CMD_SETCFG, cmdData); }
status_t CameraQemuClient::queryFrame(void* vframe, void* pframe, size_t vframe_size, size_t pframe_size) { LOGV("%s", __FUNCTION__); char query_str[256]; snprintf(query_str, sizeof(query_str), "%s video=%d preview=%d", mQueryFrame, (vframe && vframe_size) ? vframe_size : 0, (pframe && pframe_size) ? pframe_size : 0); QemuQuery query(query_str); doQuery(&query); const status_t res = query.getCompletionStatus(); if( res != NO_ERROR) { LOGE("%s: Query failed: %s", __FUNCTION__, query.mReplyData ? query.mReplyData : "No error message"); return res; } /* Copy requested frames. */ size_t cur_offset = 0; const uint8_t* frame = reinterpret_cast<const uint8_t*>(query.mReplyData); /* Video frame is always first. */ if (vframe != NULL && vframe_size != 0) { /* Make sure that video frame is in. */ if ((query.mReplyDataSize - cur_offset) >= vframe_size) { memcpy(vframe, frame, vframe_size); cur_offset += vframe_size; } else { LOGE("%s: Reply %d bytes is to small to contain %d bytes video frame", __FUNCTION__, query.mReplyDataSize - cur_offset, vframe_size); return EINVAL; } } if (pframe != NULL && pframe_size != 0) { /* Make sure that preview frame is in. */ if ((query.mReplyDataSize - cur_offset) >= pframe_size) { memcpy(pframe, frame + cur_offset, pframe_size); cur_offset += pframe_size; } else { LOGE("%s: Reply %d bytes is to small to contain %d bytes preview frame", __FUNCTION__, query.mReplyDataSize - cur_offset, pframe_size); return EINVAL; } } return NO_ERROR; }