query works

This commit is contained in:
Dwight 2007-10-28 16:38:06 -04:00
parent 4faabfaa27
commit 33ed8aa684
5 changed files with 27 additions and 13 deletions

BIN
db/db

Binary file not shown.

View File

@ -49,6 +49,14 @@ public:
ns = data;
}
int pullInt() {
if( nextjsobj == data )
nextjsobj += strlen(data) + 1; // skip namespace
int i = *((int *)nextjsobj);
nextjsobj += 4;
return i;
}
OID* getOID() {
return (OID *) (data + strlen(data) + 1); // skip namespace
}
@ -126,11 +134,11 @@ struct EmptyObject {
void query(Message& 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;
resp.setData(msgdata, true);
dbMsgPort.reply(m, resp);
@ -202,7 +210,7 @@ void run() {
break;
}
}
else if( m.data->operation == dbUpdate || dbInsert ) {
else if( m.data->operation == dbUpdate || m.data->operation == dbInsert ) {
dbinsert(m);
}
else if( m.data->operation == dbGetByOID ) {

View File

@ -1,5 +1,7 @@
// jsobj.h
#pragma once
#include "../stdafx.h"
#include "pdfile.h"

View File

@ -8,14 +8,17 @@
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! */
BufBuilder b;
QueryResult *qr = 0;
b.skip(qr->data - ((char *)qr));
b.skip(sizeof(QueryResult));
int n = 0;
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());
n++;
if( n >= ntoreturn )
if( n >= ntoreturn && ntoreturn != 0 )
break;
c.advance();
@ -39,7 +42,7 @@ QueryResult* runQuery(const char *ns, const char *query, int ntoreturn) {
qr->len = b.len();
qr->reserved = 0;
qr->operation = opReply;
qr->cursorId = nextCursorId++;
qr->cursorId = 0; //nextCursorId++;
qr->startingFrom = 0;
qr->nReturned = n;
b.decouple();

View File

@ -4,6 +4,7 @@
#include "../stdafx.h"
#include "../grid/message.h"
#include "jsobj.h"
/* requests:
@ -24,16 +25,16 @@
int reserved;
int64 cursorID;
int startingFrom;
int nReturned;
int nReturned; // 0=infinity
list of marshalled JSObjects;
*/
*/
struct QueryResult : public MsgData {
long long cursorId;
int startingFrom;
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);