Merge pull request #755 from fbraem/develop

Fix #750 and change double into int for count command
This commit is contained in:
Günter Obiltschnig 2015-03-22 22:51:21 +01:00
commit e64ccbf405
4 changed files with 11 additions and 8 deletions

View File

@ -117,6 +117,7 @@ inline void BSONReader::read<Binary::Ptr>(Binary::Ptr& to)
template<> template<>
inline void BSONWriter::write<Binary::Ptr>(Binary::Ptr& from) inline void BSONWriter::write<Binary::Ptr>(Binary::Ptr& from)
{ {
_writer << (Poco::Int32) from->buffer().size();
_writer << from->subtype(); _writer << from->subtype();
_writer.writeRaw((char*) from->buffer().begin(), from->buffer().size()); _writer.writeRaw((char*) from->buffer().begin(), from->buffer().size());
} }

View File

@ -45,7 +45,7 @@ public:
virtual ~Database(); virtual ~Database();
/// Destructor /// 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 /// Sends a count request for the given collection to MongoDB. When
/// the command fails, -1 is returned. /// the command fails, -1 is returned.

View File

@ -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); 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 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
return doc->get<double>("n"); return doc->get<int>("n");
} }
return -1; return -1;

View File

@ -221,7 +221,8 @@ void MongoDBTest::testCountCommand()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[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); assert(count == 1);
} }
else else
@ -248,7 +249,7 @@ void MongoDBTest::testDBCountCommand()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n"); int count = doc->get<int>("n");
assert(count == 1); assert(count == 1);
} }
else else
@ -267,7 +268,7 @@ void MongoDBTest::testDBCount2Command()
} }
Poco::MongoDB::Database db("team"); Poco::MongoDB::Database db("team");
double count = db.count(_mongo, "players"); int count = db.count(_mongo, "players");
assert(count == 1); assert(count == 1);
} }
@ -305,7 +306,8 @@ void MongoDBTest::testCursorRequest()
} }
_mongo.sendRequest(*insertRequest); _mongo.sendRequest(*insertRequest);
double count = db.count(_mongo, "numbers"); int count = db.count(_mongo, "numbers");
std::cout << "count= " << count << std::endl;
assert(count == 10000); assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers"); Poco::MongoDB::Cursor cursor("team", "numbers");
@ -390,7 +392,7 @@ void MongoDBTest::testConnectionPool()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n"); int count = doc->get<int>("n");
assert(count == 1); assert(count == 1);
} }
else else