本文整理汇总了C++中MojDbCursor::visit方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbCursor::visit方法的具体用法?C++ MojDbCursor::visit怎么用?C++ MojDbCursor::visit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDbCursor
的用法示例。
在下文中一共展示了MojDbCursor::visit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check
MojErr MojDbDistinctTest::check(MojDb& db, const MojDbQuery& query, MojDbCursor& cursor, const MojChar* queryString, const MojChar* expectedIdsJson)
{
MojErr err = db.find(query, cursor);
MojTestErrCheck(err);
MojObjectBuilder builder;
err = builder.beginArray();
MojTestErrCheck(err);
err = cursor.visit(builder);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = builder.endArray();
MojTestErrCheck(err);
MojObject results = builder.object();
MojString json;
err = results.toJson(json);
MojTestErrCheck(err);
MojObject expected;
err = expected.fromJson(expectedIdsJson);
MojTestErrCheck(err);
// size check
MojTestAssert(expected.size() == results.size());
// value check
MojObject::ConstArrayIterator j = results.arrayBegin();
for (MojObject::ConstArrayIterator i = expected.arrayBegin();
i != expected.arrayEnd(); ++i, ++j) {
MojObject value;
err = j->getRequired(queryString, value);
MojTestErrCheck(err);
MojTestAssert(*i == value);
}
return MojErrNone;
}
示例2: findImpl
MojErr MojDbServiceHandler::findImpl(MojServiceMessage* msg, MojObject& payload, MojDbReq& req, MojDbCursor& cursor, bool doCount)
{
MojAssert(msg);
MojLogTrace(s_log);
MojObject queryObj;
MojErr err = payload.getRequired(MojDbServiceDefs::QueryKey, queryObj);
MojErrCheck(err);
bool doWatch = false;
payload.get(MojDbServiceDefs::WatchKey, doWatch);
MojDbQuery query;
err = query.fromObject(queryObj);
MojErrCheck(err);
MojUInt32 limit = query.limit();
if (limit == MojDbQuery::LimitDefault){
query.limit(MaxQueryLimit);
} else if (limit > MaxQueryLimit) {
MojErrThrowMsg(MojErrDbInvalidQuery, _T("db: limit greater than %d not allowed"), MaxQueryLimit);
}
if (doWatch) {
MojRefCountedPtr<Watcher> watcher(new Watcher(msg));
MojAllocCheck(watcher.get());
err = m_db.find(query, cursor, watcher->m_watchSlot, req);
MojErrCheck(err);
} else {
err = m_db.find(query, cursor, req);
MojErrCheck(err);
}
// append results
MojObjectVisitor& writer = msg->writer();
err = writer.beginObject();
MojErrCheck(err);
err = writer.boolProp(MojServiceMessage::ReturnValueKey, true);
MojErrCheck(err);
err = writer.propName(MojDbServiceDefs::ResultsKey);
MojErrCheck(err);
err = writer.beginArray();
MojErrCheck(err);
err = cursor.visit(writer);
MojErrCheck(err);
err = writer.endArray();
MojErrCheck(err);
// append next page
MojDbQuery::Page page;
err = cursor.nextPage(page);
MojErrCheck(err);
if (!page.empty()) {
MojObject pageObj;
err = page.toObject(pageObj);
MojErrCheck(err);
err = writer.objectProp(MojDbServiceDefs::NextKey, pageObj);
MojErrCheck(err);
}
// append count
if (doCount) {
MojUInt32 count = 0;
err = cursor.count(count);
MojErrCheck(err);
err = writer.intProp(MojDbServiceDefs::CountKey, (MojInt64) count);
MojErrCheck(err);
}
err = writer.endObject();
MojErrCheck(err);
if (doWatch) {
// if this is a watched query, it cannot be part of a batch so it's safe to reply here
err = msg->reply();
MojErrCheck(err);
}
// notifications can fire any time after the cursor is closed,
// so don't close it until after sending the reply.
err = cursor.close();
MojErrCheck(err);
return MojErrNone;
}