mirror of https://github.com/mongodb/mongo
query works
This commit is contained in:
parent
4faabfaa27
commit
33ed8aa684
18
db/db.cpp
18
db/db.cpp
|
|
@ -49,6 +49,14 @@ public:
|
||||||
ns = data;
|
ns = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pullInt() {
|
||||||
|
if( nextjsobj == data )
|
||||||
|
nextjsobj += strlen(data) + 1; // skip namespace
|
||||||
|
int i = *((int *)nextjsobj);
|
||||||
|
nextjsobj += 4;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
OID* getOID() {
|
OID* getOID() {
|
||||||
return (OID *) (data + strlen(data) + 1); // skip namespace
|
return (OID *) (data + strlen(data) + 1); // skip namespace
|
||||||
}
|
}
|
||||||
|
|
@ -126,11 +134,11 @@ struct EmptyObject {
|
||||||
|
|
||||||
void query(Message& m) {
|
void query(Message& m) {
|
||||||
DbMessage d(m);
|
DbMessage d(m);
|
||||||
const char *query;
|
|
||||||
int ntoreturn;
|
|
||||||
d.getQueryStuff(query, ntoreturn);
|
|
||||||
|
|
||||||
QueryResult* msgdata = runQuery(d.getns(), query, ntoreturn);
|
const char *ns = d.getns();
|
||||||
|
int ntoreturn = d.pullInt();
|
||||||
|
assert( d.moreJSObjs() );
|
||||||
|
QueryResult* msgdata = runQuery(ns, ntoreturn, d.nextJsObj());
|
||||||
Message resp;
|
Message resp;
|
||||||
resp.setData(msgdata, true);
|
resp.setData(msgdata, true);
|
||||||
dbMsgPort.reply(m, resp);
|
dbMsgPort.reply(m, resp);
|
||||||
|
|
@ -202,7 +210,7 @@ void run() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( m.data->operation == dbUpdate || dbInsert ) {
|
else if( m.data->operation == dbUpdate || m.data->operation == dbInsert ) {
|
||||||
dbinsert(m);
|
dbinsert(m);
|
||||||
}
|
}
|
||||||
else if( m.data->operation == dbGetByOID ) {
|
else if( m.data->operation == dbGetByOID ) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
// jsobj.h
|
// jsobj.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "pdfile.h"
|
#include "pdfile.h"
|
||||||
|
|
||||||
|
|
|
||||||
11
db/query.cpp
11
db/query.cpp
|
|
@ -8,14 +8,17 @@
|
||||||
|
|
||||||
int nextCursorId = 1;
|
int nextCursorId = 1;
|
||||||
|
|
||||||
QueryResult* runQuery(const char *ns, const char *query, int ntoreturn) {
|
QueryResult* runQuery(const char *ns, int ntoreturn, JSObj jsobj) {
|
||||||
|
|
||||||
|
cout << "runQuery ns:" << ns << " ntoreturn:" << ntoreturn << " queryobjsize:" <<
|
||||||
|
jsobj.objsize() << endl;
|
||||||
|
|
||||||
/* temp implementation -- just returns everything! */
|
/* temp implementation -- just returns everything! */
|
||||||
|
|
||||||
BufBuilder b;
|
BufBuilder b;
|
||||||
|
|
||||||
QueryResult *qr = 0;
|
QueryResult *qr = 0;
|
||||||
b.skip(qr->data - ((char *)qr));
|
b.skip(sizeof(QueryResult));
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
Cursor c = theDataFileMgr.findAll(ns);
|
Cursor c = theDataFileMgr.findAll(ns);
|
||||||
|
|
@ -29,7 +32,7 @@ QueryResult* runQuery(const char *ns, const char *query, int ntoreturn) {
|
||||||
b.append(r->data, r->netLength());
|
b.append(r->data, r->netLength());
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if( n >= ntoreturn )
|
if( n >= ntoreturn && ntoreturn != 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
c.advance();
|
c.advance();
|
||||||
|
|
@ -39,7 +42,7 @@ QueryResult* runQuery(const char *ns, const char *query, int ntoreturn) {
|
||||||
qr->len = b.len();
|
qr->len = b.len();
|
||||||
qr->reserved = 0;
|
qr->reserved = 0;
|
||||||
qr->operation = opReply;
|
qr->operation = opReply;
|
||||||
qr->cursorId = nextCursorId++;
|
qr->cursorId = 0; //nextCursorId++;
|
||||||
qr->startingFrom = 0;
|
qr->startingFrom = 0;
|
||||||
qr->nReturned = n;
|
qr->nReturned = n;
|
||||||
b.decouple();
|
b.decouple();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "../grid/message.h"
|
#include "../grid/message.h"
|
||||||
|
#include "jsobj.h"
|
||||||
|
|
||||||
/* requests:
|
/* requests:
|
||||||
|
|
||||||
|
|
@ -24,16 +25,16 @@
|
||||||
int reserved;
|
int reserved;
|
||||||
int64 cursorID;
|
int64 cursorID;
|
||||||
int startingFrom;
|
int startingFrom;
|
||||||
int nReturned;
|
int nReturned; // 0=infinity
|
||||||
list of marshalled JSObjects;
|
list of marshalled JSObjects;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct QueryResult : public MsgData {
|
struct QueryResult : public MsgData {
|
||||||
long long cursorId;
|
long long cursorId;
|
||||||
int startingFrom;
|
int startingFrom;
|
||||||
int nReturned;
|
int nReturned;
|
||||||
char data[4];
|
const char *data() { return (char *) (((int *)&nReturned)+1); }
|
||||||
};
|
};
|
||||||
|
|
||||||
QueryResult* runQuery(const char *ns, const char *query, int ntoreturn);
|
QueryResult* runQuery(const char *ns, int ntoreturn, JSObj);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue