diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index 022f9faf6c8..3ce0c3f9e78 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -220,7 +220,7 @@ void DBClientCursor::requestMore() {
void DBClientCursor::dataReceived() {
QueryResult *qr = (QueryResult *) m->data;
- if ( qr->resultFlags() & ResultFlag_CursorNotFound ) {
+ if ( qr->resultFlags() & QueryResult::ResultFlag_CursorNotFound ) {
// cursor id no longer valid at the server.
assert( qr->cursorId == 0 );
cursorId = 0; // 0 indicates no longer valid (dead)
diff --git a/client/dbclient.h b/client/dbclient.h
index d2c7290bed2..ba103899be0 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -22,7 +22,7 @@
#include "../db/jsobj.h"
/* the query field 'options' can have these bits set: */
-enum {
+enum QueryOptions {
/* Tailable means cursor is not closed when the last data is retrieved. rather, the cursor marks
the final object's position. you can resume using the cursor later, from where it was located,
if more data were received. Set on dbQuery and dbGetMore.
@@ -42,8 +42,23 @@ enum {
class BSONObj;
+/* db response format
+
+ Query or GetMore: // see struct QueryResult
+ int resultFlags;
+ int64 cursorID;
+ int startingFrom;
+ int nReturned;
+ list of marshalled JSObjects;
+*/
+
#pragma pack(push,1)
struct QueryResult : public MsgData {
+ enum {
+ ResultFlag_CursorNotFound = 1, /* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
+ ResultFlag_ErrSet = 2 /* { $err : ... } is being returned */
+ };
+
long long cursorId;
int startingFrom;
int nReturned;
diff --git a/db/db.vcproj b/db/db.vcproj
index 62bca326d45..398141e20f5 100644
--- a/db/db.vcproj
+++ b/db/db.vcproj
@@ -545,10 +545,6 @@
RelativePath=".\minilex.h"
>
-
-
@@ -645,6 +641,22 @@
>
+
+
+
+
+
+
+
+
_data[0] = 0;
- qr->_data[1] = 0;
- qr->_data[2] = 0;
- qr->_data[3] = 0;
+ qr->resultFlags() = queryResultFlags;
qr->len = b.len();
qr->setOperation(opReply);
qr->cursorId = cursorId;
@@ -149,10 +147,11 @@ inline void replyToQuery(MessagingPort& p, Message& requestMsg,
//#include "bsonobj.h"
-inline void replyToQuery(MessagingPort& p, Message& requestMsg,
+inline void replyToQuery(int queryResultFlags,
+ MessagingPort& p, Message& requestMsg,
BSONObj& responseObj)
{
- replyToQuery(
+ replyToQuery(queryResultFlags,
p, requestMsg,
(void *) responseObj.objdata(), responseObj.objsize(), 1);
}
diff --git a/db/instance.cpp b/db/instance.cpp
index 7a20a33f8fe..dfd4502e295 100644
--- a/db/instance.cpp
+++ b/db/instance.cpp
@@ -293,10 +293,7 @@ void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, *
msgdata = (QueryResult *) b.buf();
b.decouple();
QueryResult *qr = msgdata;
- qr->_data[0] = queryError;
- qr->_data[1] = 0;
- qr->_data[2] = 0;
- qr->_data[3] = 0;
+ qr->resultFlags() = QueryResult::ResultFlag_ErrSet;
qr->len = b.len();
qr->setOperation(opReply);
qr->cursorId = 0;
diff --git a/db/query.cpp b/db/query.cpp
index d8221eaa903..72be11e4f98 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -754,10 +754,7 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret
}
QueryResult *qr = (QueryResult *) b.buf();
- qr->_data[0] = 0;
- qr->_data[1] = 0;
- qr->_data[2] = 0;
- qr->_data[3] = 0;
+ qr->resultFlags() = 0;
qr->len = b.len();
ss << " reslen:" << b.len();
// qr->channel = 0;
@@ -810,7 +807,7 @@ QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid) {
if ( !cc ) {
DEV log() << "getMore: cursorid not found " << ns << " " << cursorid << endl;
cursorid = 0;
- resultFlags = ResultFlag_CursorNotFound;
+ resultFlags = QueryResult::ResultFlag_CursorNotFound;
}
else {
start = cc->pos;
diff --git a/db/query.h b/db/query.h
index eff237ff2ad..9509447056e 100644
--- a/db/query.h
+++ b/db/query.h
@@ -63,25 +63,7 @@
Note that the update field layout is very similar layout to Query.
*/
-// see dbclient.h for query options enum
-
-/* db response format
-
- Query or GetMore: // see struct QueryResult
- int resultFlags = 0;
- int64 cursorID;
- int startingFrom;
- int nReturned;
- list of marshalled JSObjects;
-*/
-
-/* the field 'resultFlags' above */
-enum {
- /* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
- ResultFlag_CursorNotFound = 1
-};
-
-// grab struct QueryResult from:
+// struct QueryOptions, QueryResult, QueryResultFlags in:
#include "../client/dbclient.h"
// for an existing query (ie a ClientCursor), send back additional information.
diff --git a/dbgrid/request.cpp b/dbgrid/request.cpp
index 3cd457c2eb7..9ae86caafa0 100644
--- a/dbgrid/request.cpp
+++ b/dbgrid/request.cpp
@@ -72,7 +72,7 @@ void queryOp(Message& m, MessagingPort& p) {
bool ok = runCommandAgainstRegistered(q.ns, q.query, builder);
if ( ok ) {
BSONObj x = builder.done();
- replyToQuery(p, m, x);
+ replyToQuery(0, p, m, x);
return;
}
}
@@ -91,7 +91,7 @@ void queryOp(Message& m, MessagingPort& p) {
BSONObjBuilder err;
err.append("$err", string("dbgrid ") + (e.msg.empty() ? "dbgrid assertion during query" : e.msg));
BSONObj errObj = err.done();
- replyToQuery(p, m, errObj);
+ replyToQuery(QueryResult::ResultFlag_ErrSet, p, m, errObj);
return;
}
}
@@ -99,6 +99,7 @@ void queryOp(Message& m, MessagingPort& p) {
void writeOp(int op, Message& m, MessagingPort& p) {
DbMessage d(m);
const char *ns = d.getns();
+ assert( *ns );
ScopedDbConnection dbcon(tempHost);
DBClientConnection &c = dbcon.conn();
diff --git a/grid/message.h b/grid/message.h
index 35dd7e3fb7b..d158989077b 100644
--- a/grid/message.h
+++ b/grid/message.h
@@ -82,14 +82,6 @@ enum Operations {
dbKillCursors = 2007
};
-/*
- * flags for query responses
- */
-enum ReponseMsgFlags {
- operationOk = 0x00,
- queryError = 0x01
-};
-
struct MsgData {
int len; /* len of the msg, including this field */
MSGID id; /* request/reply id's match... */