mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-18 04:10:33 +01:00
Merge pull request #755 from fbraem/develop
Fix #750 and change double into int for count command
This commit is contained in:
commit
e64ccbf405
MongoDB
@ -117,6 +117,7 @@ inline void BSONReader::read<Binary::Ptr>(Binary::Ptr& to)
|
||||
template<>
|
||||
inline void BSONWriter::write<Binary::Ptr>(Binary::Ptr& from)
|
||||
{
|
||||
_writer << (Poco::Int32) from->buffer().size();
|
||||
_writer << from->subtype();
|
||||
_writer.writeRaw((char*) from->buffer().begin(), from->buffer().size());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
virtual ~Database();
|
||||
/// Destructor
|
||||
|
||||
double count(Connection& connection, const std::string& collectionName) const;
|
||||
int count(Connection& connection, const std::string& collectionName) const;
|
||||
/// Sends a count request for the given collection to MongoDB. When
|
||||
/// the command fails, -1 is returned.
|
||||
|
||||
|
@ -32,7 +32,7 @@ Database::~Database()
|
||||
}
|
||||
|
||||
|
||||
double Database::count(Connection& connection, const std::string& collectionName) const
|
||||
int Database::count(Connection& connection, const std::string& collectionName) const
|
||||
{
|
||||
Poco::SharedPtr<Poco::MongoDB::QueryRequest> countRequest = createCountRequest(collectionName);
|
||||
|
||||
@ -42,7 +42,7 @@ double Database::count(Connection& connection, const std::string& collectionName
|
||||
if ( response.documents().size() > 0 )
|
||||
{
|
||||
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
|
||||
return doc->get<double>("n");
|
||||
return doc->get<int>("n");
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -221,7 +221,8 @@ void MongoDBTest::testCountCommand()
|
||||
if ( response.documents().size() > 0 )
|
||||
{
|
||||
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
|
||||
double count = doc->get<double>("n");
|
||||
std::cout << doc->toString() << std::endl;
|
||||
int count = doc->get<int>("n");
|
||||
assert(count == 1);
|
||||
}
|
||||
else
|
||||
@ -248,7 +249,7 @@ void MongoDBTest::testDBCountCommand()
|
||||
if ( response.documents().size() > 0 )
|
||||
{
|
||||
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
|
||||
double count = doc->get<double>("n");
|
||||
int count = doc->get<int>("n");
|
||||
assert(count == 1);
|
||||
}
|
||||
else
|
||||
@ -267,7 +268,7 @@ void MongoDBTest::testDBCount2Command()
|
||||
}
|
||||
|
||||
Poco::MongoDB::Database db("team");
|
||||
double count = db.count(_mongo, "players");
|
||||
int count = db.count(_mongo, "players");
|
||||
assert(count == 1);
|
||||
}
|
||||
|
||||
@ -305,7 +306,8 @@ void MongoDBTest::testCursorRequest()
|
||||
}
|
||||
_mongo.sendRequest(*insertRequest);
|
||||
|
||||
double count = db.count(_mongo, "numbers");
|
||||
int count = db.count(_mongo, "numbers");
|
||||
std::cout << "count= " << count << std::endl;
|
||||
assert(count == 10000);
|
||||
|
||||
Poco::MongoDB::Cursor cursor("team", "numbers");
|
||||
@ -390,7 +392,7 @@ void MongoDBTest::testConnectionPool()
|
||||
if ( response.documents().size() > 0 )
|
||||
{
|
||||
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
|
||||
double count = doc->get<double>("n");
|
||||
int count = doc->get<int>("n");
|
||||
assert(count == 1);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user