本文整理汇总了C++中Query类的典型用法代码示例。如果您正苦于以下问题:C++ Query类的具体用法?C++ Query怎么用?C++ Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: string
bool ManageSieveCommand::deleteScript()
{
if ( !d->t ) {
d->name = string();
end();
d->t = new Transaction( this );
// select first, so the no() calls below work
d->query =
new Query( "select active from scripts "
"where owner=$1 and name=$2",
this );
d->query->bind( 1, d->sieve->user()->id() );
d->query->bind( 2, d->name );
d->t->enqueue( d->query );
// then delete
Query * q = new Query( "delete from scripts where owner=$1 and "
"name=$2 and active='f'", this );
q->bind( 1, d->sieve->user()->id() );
q->bind( 2, d->name );
d->t->enqueue( q );
if ( d->no.isEmpty() )
d->t->commit();
}
if ( !d->t->done() )
return false;
if ( d->t->failed() ) {
no( "Couldn't delete script: " + d->t->error() );
}
else {
Row * r = d->query->nextRow();
if ( !r )
no( "No such script" );
else if ( r->getBoolean( "active" ) )
no( "Can't delete active script" );
else
log( "Deleted script " + d->name );
}
return true;
}
示例2: main
int main(int, char **argv)
{
// get a file to read and builds map to support queries
TextQuery file = build_textfile(argv[1]);
// iterate with the user: prompt for a word to find and print results
do {
string sought;
if (!get_word(sought)) break;
// find all the occurrences of the requested string
Query name(sought);
Query notq = ~name;
const set<TextQuery::line_no> locs = notq.eval(file);
cout << "\nExecuted Query for: " << notq << endl;
// report no matches
print_results(locs, file);
} while (true); // loop indefinitely; the exit is inside the loop
return 0;
}
示例3: computeValue
bool computeValue(const Query& query, ref<Expr> &result)
{
startQuery(query.withFalse(), "Value");
bool success = solver->impl->computeValue(query, result);
finishQuery(success);
if (success)
os << "; Result: " << result << "\n";
os << "\n";
return success;
}
示例4: Java_io_realm_internal_TableQuery_nativeFind
JNIEXPORT jlong JNICALL Java_io_realm_internal_TableQuery_nativeFind(
JNIEnv* env, jobject, jlong nativeQueryPtr, jlong fromTableRow)
{
Query* pQuery = Q(nativeQueryPtr);
Table* pTable = Ref2Ptr(pQuery->get_table());
if (!QUERY_VALID(env, pQuery))
return -1;
// It's valid to go 1 past the end index
if ((fromTableRow < 0) || (S(fromTableRow) > pTable->size())) {
// below check will fail with appropriate exception
(void) ROW_INDEX_VALID(env, pTable, fromTableRow);
return -1;
}
try {
size_t r = pQuery->find( S(fromTableRow) );
return (r == not_found) ? jlong(-1) : jlong(r);
} CATCH_STD()
return -1;
}
示例5: main
int main(int argc, char **argv)
{
// gets file to read and builds map to support queries
TextQuery file = get_file(argc, argv);
// iterate with the user: prompt for a word to find and print results
while (true) {
string sought1, sought2, sought3;
if (!get_words(sought1, sought2)) break;
cout << "\nenter third word: ";
cin >> sought3;
// find all the occurrences of the requested string
Query q = Query(sought1) & Query(sought2) | Query(sought3);
cout << "\nExecuting Query for: " << q << endl;
const auto results = q.eval(file);
// report matches
print(cout, results);
}
return 0;
}
示例6: queryTile
void TileNode::queryTile(const SpatialDimension* hashing, const Query& query, Response& response, ulong level) const {
const ulong d = level % hashing->key().size();
if (query.evalTile(d)) {
if (query.getTile(d) == _pivot.value() || (last() && util::intersects(_pivot.value(), query.getTile(d)))) {
aggregateTile(hashing, query, response, level);
} else if (_pivot.value().z < query.zoom) {
if (_container[0] != nullptr) _container[0]->queryTile(hashing, query, response, level + 1);
if (_container[1] != nullptr) _container[1]->queryTile(hashing, query, response, level + 1);
if (_container[2] != nullptr) _container[2]->queryTile(hashing, query, response, level + 1);
if (_container[3] != nullptr) _container[3]->queryTile(hashing, query, response, level + 1);
}
} else {
if (_container[0] != nullptr) _container[0]->queryTile(hashing, query, response, level + 1);
if (_container[1] != nullptr) _container[1]->queryTile(hashing, query, response, level + 1);
if (_container[2] != nullptr) _container[2]->queryTile(hashing, query, response, level + 1);
if (_container[3] != nullptr) _container[3]->queryTile(hashing, query, response, level + 1);
}
}
示例7: BooleanQuery
// static
Query* MultiFieldQueryParser::parse(const TCHAR* query, const TCHAR** _fields, const uint8_t* flags, Analyzer* analyzer) {
BooleanQuery* bQuery = _CLNEW BooleanQuery();
for (size_t i = 0; _fields[i]!=NULL; i++) {
//TODO: this is really confusing... why not refactor _fields and flags to use a array object.
//flags can be NULL since NULL == 0...
/*if (flags[i] == NULL) {
_CLLDELETE(bQuery);
_CLTHROWA(CL_ERR_IllegalArgument, "_fields.length != flags.length");
}*/
QueryParser* qp = _CLNEW QueryParser(_fields[i], analyzer);
Query* q = qp->parse(query);
if (q!=NULL && // q never null, just being defensive
(!(q->instanceOf(BooleanQuery::getClassName())) || ((BooleanQuery*)q)->getClauseCount()>0)) {
bQuery->add(q, true, (BooleanClause::Occur)flags[i]);
} else
_CLLDELETE(q);
_CLLDELETE(qp);
}
return bQuery;
}
示例8: add_query
void DNS::add_query(const Query &query) {
string new_str = encode_domain_name(query.dname());
// Type (2 bytes) + Class (2 Bytes)
new_str.insert(new_str.end(), sizeof(uint16_t) * 2, ' ');
*(uint16_t*)&new_str[new_str.size() - 4] = Endian::host_to_be<uint16_t>(query.type());
*(uint16_t*)&new_str[new_str.size() - 2] = Endian::host_to_be<uint16_t>(query.query_class());
uint32_t offset = new_str.size(), threshold = answers_idx;
update_records(answers_idx, answers_count(), threshold, offset);
update_records(authority_idx, authority_count(), threshold, offset);
update_records(additional_idx, additional_count(), threshold, offset);
records_data.insert(
records_data.begin() + threshold,
new_str.begin(),
new_str.end()
);
dns.questions = Endian::host_to_be<uint16_t>(
questions_count() + 1
);
}
示例9: snprintf
bool MasterServer::get_fileinfo(const string &fid, FileInfo &fileinfo)
{
//查找cache
map<string, FileInfo>::iterator it = m_fileinfo_cache.find(fid);
if(it != m_fileinfo_cache.end())
{
fileinfo = it->second;
return true;
}
//查找数据库
if(m_db_connection == NULL)
return false;
char sql_str[1024];
snprintf(sql_str, 1024, "select fid,name,size,chunkid,chunkip,chunkport,findex,foffset from SFS.fileinfo_%s where fid='%s'"
,fid.substr(0,2).c_str(), fid.c_str());
Query query = m_db_connection->query(sql_str);
StoreQueryResult res = query.store();
if (!res || res.empty())
return false;
size_t i;
for(i=0; i<res.num_rows(); ++i)
{
ChunkPath chunk_path;
fileinfo.fid = res[i]["fid"].c_str();
fileinfo.name = res[i]["name"].c_str();
fileinfo.size = atoi(res[i]["size"].c_str());
chunk_path.id = res[i]["chunkid"].c_str();
chunk_path.ip = res[i]["chunkip"].c_str();
chunk_path.port = atoi(res[i]["chunkport"].c_str());
chunk_path.index = atoi(res[i]["findex"].c_str());
chunk_path.offset = atoi(res[i]["foffset"].c_str());
fileinfo.add_chunkpath(chunk_path);
}
//添加到cache
m_fileinfo_cache.insert(std::make_pair(fileinfo.fid, fileinfo));
return true;
}
示例10: die
void GobDefender::calculate()
{
STACKTRACE;
SpaceObject::calculate();
if (!ship) {
die();
return;
}
if (!(random(3))) {
if (next_shoot_time < gobgame->game_time) {
SpaceObject *target = NULL;
Query q;
if (advanced)
q.begin(this, OBJECT_LAYERS, 330 );
else
q.begin(this, OBJECT_LAYERS &~ bit(LAYER_SHIPS), 290 );
while (q.currento && !target) {
if (!q.currento->sameTeam(ship) && (q.currento->get_team() != gobgame->station_team) && !q.currento->isPlanet()) {
SpaceLine *l = new PointLaser (
this, palette_color[7], 2 + advanced, 40,
this, q.currento
);
add(l);
if (l->exists()) target = q.currento;
}
q.next();
}
q.end();
if (target) {
if (advanced)
next_shoot_time = gobgame->game_time + 360;
else
next_shoot_time = gobgame->game_time + 560;
}
}
}
double a = base_phase + (gobgame->game_time % 120000) * ( PI2 / 1000.0) / 6;
angle = normalize(a,PI2);
pos = normalize(ship->normal_pos() + 270 * unit_vector ( angle ));
return;
}
示例11: updateError
int updateError(int id, int error)
{
Connection con(use_exceptions);
try
{
ostringstream strbuf;
unsigned int i = 0;
con.connect(DATABASE, HOST, USER, PASSWORD);
Query query = con.query();
strbuf << "UPDATE tasks SET error="<<error<<" WHERE id=" << id;
query.exec(strbuf.str());
strbuf.str("");
strbuf << "UPDATE tasks SET done=0 WHERE id=" << id;
query.exec(strbuf.str());
strbuf.str("");
strbuf << "UPDATE tasks SET started=-1 WHERE id=" << id;
query.exec(strbuf.str());
}
catch (const BadQuery& er)
{
// Handle any query errors
cerr << "updateDone - Query error: " << er.what() << endl;
return -1;
}
catch (const BadConversion& er)
{
// Handle bad conversions
cerr << "updateDone - Conversion error: " << er.what() << endl <<
"\tretrieved data size: " << er.retrieved <<
", actual size: " << er.actual_size << endl;
return -1;
}
catch (const Exception& er)
{
// Catch-all for any other MySQL++ exceptions
cerr << "updateDone - Error: " << er.what() << endl;
return -1;
}
return 0;
}
示例12: LOG
auto_ptr<DBClientCursor> SyncClusterConnection::_queryOnActive(const string &ns, Query query, int nToReturn, int nToSkip,
const BSONObj *fieldsToReturn, int queryOptions, int batchSize ) {
if ( _customQueryHandler && _customQueryHandler->canHandleQuery( ns, query ) ) {
LOG( 2 ) << "custom query handler used for query on " << ns << ": "
<< query.toString() << endl;
return _customQueryHandler->handleQuery( _connAddresses,
ns,
query,
nToReturn,
nToSkip,
fieldsToReturn,
queryOptions,
batchSize );
}
for ( size_t i=0; i<_conns.size(); i++ ) {
try {
auto_ptr<DBClientCursor> cursor =
_conns[i]->query( ns , query , nToReturn , nToSkip , fieldsToReturn , queryOptions , batchSize );
if ( cursor.get() )
return cursor;
log() << "query on " << ns << ": " << query.toString() << " failed to: "
<< _conns[i]->toString() << " no data" << endl;
}
catch ( std::exception& e ) {
log() << "query on " << ns << ": " << query.toString() << " failed to: "
<< _conns[i]->toString() << " exception: " << e.what() << endl;
}
catch ( ... ) {
log() << "query on " << ns << ": " << query.toString() << " failed to: "
<< _conns[i]->toString() << " exception" << endl;
}
}
throw UserException( 8002 , str::stream() << "all servers down/unreachable when querying: " << _address );
}
示例13:
TriStateTree::TriStateTree(const Query& query)
{
m_state = Unknown;
m_nodeCount = query.count();
m_nodes = new Node[m_nodeCount];
m_leafCount = 0;
m_leafs = new Node*[m_nodeCount];
Node** nodeStack = new Node*[m_nodeCount];
int stackTop = -1;
for (int element = 0; element < m_nodeCount; element++) {
if (query.isElementSearch(element)) {
/* search == leaf node, add to stack & add to list of leaf nodes */
m_nodes[element].m_state = Unknown;
m_nodes[element].m_operator = Search::NullOperator;
m_nodes[element].m_parent = 0;
m_nodes[element].m_leftChild = m_nodes[element].m_rightChild = 0;
nodeStack[++stackTop] = &m_nodes[element];
m_leafs[m_leafCount++] = &m_nodes[element];
} else {
/* operator == branch node, pop children off stack & add to stack */
m_nodes[element].m_state = Unknown;
m_nodes[element].m_operator = query.searchOperator(element);
m_nodes[element].m_parent = 0;
if (m_nodes[element].m_operator == Search::Not) {
m_nodes[element].m_rightChild = 0;
} else {
m_nodes[element].m_rightChild = nodeStack[stackTop--];
m_nodes[element].m_rightChild->m_parent = &m_nodes[element];
}
m_nodes[element].m_leftChild = nodeStack[stackTop--];
m_nodes[element].m_leftChild->m_parent = &m_nodes[element];
nodeStack[++stackTop] = &m_nodes[element];
}
}
delete[] nodeStack;
//stack should now be empty
Q_ASSERT(stackTop == 0);
}
示例14: generateSummary
static void generateSummary( Summary &summary, char *htmlInput, const char *queryStr, const char *urlStr ) {
Xml xml;
ASSERT_TRUE(xml.set(htmlInput, strlen(htmlInput), 0, CT_HTML));
Words words;
ASSERT_TRUE(words.set(&xml, true));
Bits bits;
ASSERT_TRUE(bits.set(&words));
Url url;
url.set(urlStr);
Sections sections;
ASSERT_TRUE(sections.set(&words, &bits, &url, "", CT_HTML));
Query query;
ASSERT_TRUE(query.set2(queryStr, langEnglish, true));
LinkInfo linkInfo;
memset ( &linkInfo , 0 , sizeof(LinkInfo) );
linkInfo.m_lisize = sizeof(LinkInfo);
Title title;
ASSERT_TRUE(title.setTitle(&xml, &words, 80, &query, &linkInfo, &url, NULL, 0, CT_HTML, langEnglish));
Pos pos;
ASSERT_TRUE(pos.set(&words));
Bits bitsForSummary;
ASSERT_TRUE(bitsForSummary.setForSummary(&words));
Phrases phrases;
ASSERT_TRUE(phrases.set(&words, &bits));
Matches matches;
matches.setQuery(&query);
ASSERT_TRUE(matches.set(&words, &phrases, §ions, &bitsForSummary, &pos, &xml, &title, &url, &linkInfo));
summary.setSummary(&xml, &words, §ions, &pos, &query, 180, 3, 3, 180, &url, &matches, title.getTitle(), title.getTitleLen());
}
示例15: SpaceObject
NaroolPoison::NaroolPoison(NaroolGas *gas, int nduration, float poison, Ship *nship, SpaceSprite *osprite) :
SpaceObject (gas, nship->normal_pos(), 0.0, osprite),
oship(nship),
poison(poison),
duration(nduration)
{
STACKTRACE;
target = oship;
id |= NAROOL_POISON_ID;
layer = LAYER_HOTSPOTS;
start = TRUE;
collide_flag_anyone = 0;
Query q;
for (q.begin(oship, bit(LAYER_HOTSPOTS), 10); q.current; q.next()) {
if ((q.current->getID() == getID()) && (((NaroolPoison*)q.current)->oship == oship)) {
((NaroolPoison*)q.current)->duration = duration;
state = 0;
}
}
q.end();
}