本文整理汇总了C++中doQuery函数的典型用法代码示例。如果您正苦于以下问题:C++ doQuery函数的具体用法?C++ doQuery怎么用?C++ doQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了doQuery函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BOOSTER_NOTICE
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;
}
示例2: stmt
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;
}
}
示例3: sqlQuery
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;
}
示例4: queryOp
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;
}
}
示例5: LOGV
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;
}
}
示例6: doQuery
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";
}
}
示例7: doQuery
ResultSet* MySQLPreparedStatement::executeQuery()
{
//mysql_stmt_store_result(stmt);
doQuery();
return new MySQLPreparedResultSet(this, stmt);
}
示例8: sigQueryStatus
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"));
}
示例9: log
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();
}
示例10:
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;
}
}
示例11: connect
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()));
}
示例12: queryOp
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() );
}
示例13: doQuery
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));
}
示例14: switch
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);
}
示例15: getCells
//距离查询
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);
}