本文整理汇总了C++中MojDbCursor::nextPage方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbCursor::nextPage方法的具体用法?C++ MojDbCursor::nextPage怎么用?C++ MojDbCursor::nextPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDbCursor
的用法示例。
在下文中一共展示了MojDbCursor::nextPage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pageTest
MojErr MojDbWatchTest::pageTest(MojDb& db)
{
MojObject id;
MojObject idFirst;
MojObject idFourth;
MojObject idLast;
MojInt64 rev;
for (int i = 100; i < 150; ++i) {
MojErr err = put(db, 100, i, id, rev);
MojTestErrCheck(err);
if (i == 100) {
idFirst = id;
} else if (i == 103) {
idFourth = id;
} else if (i == 149) {
idLast = id;
}
}
MojDbQuery query;
MojErr err = query.from(_T("WatchTest:1"));
MojTestErrCheck(err);
err = query.where(_T("foo"), MojDbQuery::OpGreaterThanEq, 100);
MojTestErrCheck(err);
query.limit(3);
MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
MojTestAssert(watcher.get());
MojDbCursor cursor;
err = db.find(query, cursor, watcher->m_slot);
MojTestErrCheck(err);
bool found = false;
MojUInt32 count = 0;
do {
MojObject obj;
err = cursor.get(obj, found);
MojTestErrCheck(err);
if (found)
++count;
} while (found);
MojTestAssert(count == 3);
MojDbQuery::Page page;
err = cursor.nextPage(page);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
err = merge(db, idFourth, 53);
MojTestErrCheck(err);
MojTestAssert(watcher->m_count == 0);
query.page(page);
MojRefCountedPtr<TestWatcher> watcher2(new TestWatcher);
MojTestAssert(watcher2.get());
err = db.find(query, cursor, watcher2->m_slot);
MojTestErrCheck(err);
found = false;
count = 0;
do {
MojObject obj;
err = cursor.get(obj, found);
MojTestErrCheck(err);
if (found)
++count;
} while (found);
MojTestAssert(count == 3);
err = cursor.close();
MojTestErrCheck(err);
err = db.del(idFirst, found);
MojTestErrCheck(err);
MojTestAssert(found);
MojTestAssert(watcher->m_count == 1);
MojTestAssert(watcher2->m_count == 0);
err = db.del(idFourth, found);
MojTestErrCheck(err);
MojTestAssert(found);
MojTestAssert(watcher->m_count == 1);
MojTestAssert(watcher2->m_count == 1);
// desc order
query.page(MojDbQuery::Page());
query.desc(true);
MojRefCountedPtr<TestWatcher> watcher3(new TestWatcher);
MojTestAssert(watcher3.get());
err = db.find(query, cursor, watcher3->m_slot);
MojTestErrCheck(err);
found = false;
count = 0;
do {
MojObject obj;
err = cursor.get(obj, found);
MojTestErrCheck(err);
if (found)
++count;
} while (found);
MojTestAssert(count == 3);
err = cursor.close();
MojTestErrCheck(err);
err = merge(db, idLast, 53);
MojTestErrCheck(err);
//.........这里部分代码省略.........
示例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;
}