本文整理汇总了C++中poco::SharedPtr::selector方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedPtr::selector方法的具体用法?C++ SharedPtr::selector怎么用?C++ SharedPtr::selector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::SharedPtr
的用法示例。
在下文中一共展示了SharedPtr::selector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: authenticateMongoCR
bool MongoAuthentication::authenticateMongoCR(const std::string &user, const std::string &pwd)
{
bool ret = false;
_user = user;
_pwd = pwd;
try {
std::string nonce;
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector().add<Poco::Int32>("getnonce", 1);
command->setNumberToReturn(1);
Poco::MongoDB::ResponseMessage response;
_conn.sendRequest(*command, response);
if (response.documents().size() > 0) {
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
nonce = doc->get<std::string>("nonce", "");
std::string password = _user + ":mongo:" + _pwd;
Poco::MD5Engine md5;
md5.update(password);
std::string hashedPassword(Poco::DigestEngine::digestToHex(md5.digest()));
std::string key = nonce + _user + hashedPassword;
md5.reset();
md5.update(key);
std::string hashedKey(Poco::DigestEngine::digestToHex(md5.digest()));
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector()
.add<Poco::Int32>("authenticate", 1)
.add<std::string>("user", _user)
.add<std::string>("nonce", nonce)
.add<std::string>("key", hashedKey); // hex_md5( n.nonce + username + hex_md5( username + ":mongo:" + password ) )
_conn.sendRequest(*command, response);
if (response.documents().size() > 0 && response.documents()[0]->get<double>("ok")) {
ret = true;
}
}
} catch (Poco::Exception &) {
throw Poco::ApplicationException("auth failed.");
}
return ret;
}
示例2: createQueryRequest
Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCountRequest(const std::string& collectionName) const
{
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
request->setNumberToReturn(1);
request->selector().add("count", collectionName);
return request;
}
示例3: sample10
// SELECT DISTINCT birthyear FROM players WHERE birthyear > 1980
void sample10(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 10 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
command->selector()
.add("distinct", "players")
.add("key", "birthyear")
.addNewDocument("query")
.addNewDocument("birthyear")
.add("$gt", 1980);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*command, response);
if ( response.hasDocuments() )
{
Poco::MongoDB::Array::Ptr values = response.documents()[0]->get<Poco::MongoDB::Array::Ptr>("values");
for(int i = 0; i < values->size(); ++i )
{
std::cout << values->get<int>(i) << std::endl;
}
}
}
示例4: sample13
//DELETE players WHERE firstname = 'Victor'
void sample13(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 13 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::DeleteRequest> request = db.createDeleteRequest("players");
request->selector().add("firstname", "Victor");
connection.sendRequest(*request);
Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(connection);
std::cout << "LastError: " << lastError->toString(2) << std::endl;
}
示例5: getLastErrorDoc
Document::Ptr Database::getLastErrorDoc(Connection& connection) const
{
Document::Ptr errorDoc;
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
request->setNumberToReturn(1);
request->selector().add("getLastError", 1);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
errorDoc = response.documents()[0];
}
return errorDoc;
}
示例6: sample11
// SELECT COUNT(*) FROM players WHERE birthyear > 1980
void sample11(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 11 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> count = db.createCountRequest("players");
count->selector().addNewDocument("query")
.addNewDocument("birthyear")
.add("$gt", 1980);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*count, response);
if ( response.hasDocuments() )
{
std::cout << "Count: " << response.documents()[0]->get<double>("n") << std::endl;
}
}
示例7: testDBQueryRequest
void MongoDBTest::testDBQueryRequest()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = db.createQueryRequest("players");
request->selector().add("lastname" , std::string("Braem"));
Poco::MongoDB::ResponseMessage response;
_mongo.sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
try
{
std::string lastname = doc->get<std::string>("lastname");
assert(lastname.compare("Braem") == 0);
std::string firstname = doc->get<std::string>("firstname");
assert(firstname.compare("Franky") == 0);
Poco::Timestamp birthDateTimestamp = doc->get<Poco::Timestamp>("birthdate");
Poco::DateTime birthDate(birthDateTimestamp);
assert(birthDate.year() == 1969 && birthDate.month() == 3 && birthDate.day() == 9);
Poco::Timestamp lastupdatedTimestamp = doc->get<Poco::Timestamp>("lastupdated");
assert(doc->isType<NullValue>("unknown"));
std::string id = doc->get("_id")->toString();
std::cout << id << std::endl;
}
catch(Poco::NotFoundException& nfe)
{
fail(nfe.message() + " not found.");
}
}
else
{
fail("No document returned");
}
}
示例8: testCommand
void MongoDBTest::testCommand() {
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
command->selector().add("create", "fixCol")
.add("capped", true)
.add("max", 1024*1024)
.add("size", 1024);
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(*command, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
}
else
{
Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(*_mongo);
fail(lastError->toString(2));
}
}