#43
authoradam <adamansky@gmail.com>
Tue, 15 Jan 2013 16:58:26 +0000 (23:58 +0700)
committeradam <adamansky@gmail.com>
Tue, 15 Jan 2013 16:58:26 +0000 (23:58 +0700)
tcejdb/ejdb.c
tcejdb/ejdb_private.h
tcejdb/testejdb/t2.c

index 100f888..addfecd 100644 (file)
@@ -3314,7 +3314,9 @@ static int _parse_qobj_impl(EJDB *jb, EJQ *q, bson_iterator *it, TCLIST *qlist,
                     !strcmp("$addToSetAll", fkey) ||
                     !strcmp("$upsert", fkey) ||
                     !strcmp("$pull", fkey) ||
-                    !strcmp("$pullAll", fkey)) {
+                    !strcmp("$pullAll", fkey) ||
+                    !strcmp("$do", fkey)
+                    ) {
                 if (pqf) { //Top level ops
                     ret = JBEQERROR;
                     _ejdbsetecode(jb, ret, __FILE__, __LINE__, __func__);
@@ -3434,8 +3436,11 @@ static int _parse_qobj_impl(EJDB *jb, EJQ *q, bson_iterator *it, TCLIST *qlist,
                         } else if (!strcmp("$pullAll", fkey)) {
                             qf.flags |= EJCONDPULL;
                             qf.flags |= EJCONDALL;
+                        } else if (!strcmp("$do", fkey)) {
+                            qf.flags |= EJCONDOIT;
                         }
                     }
+
                     if ((qf.flags & (EJCONDSET | EJCONDINC | EJCONDADDSET | EJCONDPULL))) {
                         assert(qf.updateobj == NULL);
                         qf.q->flags |= EJQUPDATING;
@@ -3464,6 +3469,31 @@ static int _parse_qobj_impl(EJDB *jb, EJQ *q, bson_iterator *it, TCLIST *qlist,
                         TCLISTPUSH(qlist, &qf, sizeof (qf));
                         break;
                     }
+
+                    if (qf.flags & EJCONDOIT) { //$do
+                        assert(qf.updateobj == NULL);
+                        qf.updateobj = bson_create();
+                        bson_init_as_query(qf.updateobj);
+                        bson_type sbt;
+                        bson_iterator sit;
+                        bson_iterator_subiterator(it, &sit);
+                        while ((sbt = bson_iterator_next(&sit)) != BSON_EOO) {
+                            bson_append_field_from_iterator(&sit, qf.updateobj);
+                        }
+                        bson_finish(qf.updateobj);
+                        if (qf.updateobj->err) {
+                            ret = JBEQERROR;
+                            _ejdbsetecode(jb, ret, __FILE__, __LINE__, __func__);
+                            break;
+                        }
+                        qf.fpath = strdup(fkey);
+                        qf.fpathsz = strlen(qf.fpath);
+                        qf.tcop = TDBQTRUE;
+                        qf.flags |= EJFEXCLUDED;
+                        TCLISTPUSH(qlist, &qf, sizeof (qf));
+                        break;
+                    }
+
                     if (!strcmp("$elemMatch", fkey)) {
                         if (qf.elmatchgrp) { //only one $elemMatch allowed in query field
                             ret = JBEQERROR;
@@ -3483,6 +3513,11 @@ static int _parse_qobj_impl(EJDB *jb, EJQ *q, bson_iterator *it, TCLIST *qlist,
             }
             case BSON_OID:
             {
+
+                if (isckey) {
+
+                }
+
                 assert(!qf.fpath && !qf.expr);
                 qf.ftype = ftype;
                 TCMALLOC(qf.expr, 25 * sizeof (char));
index 452e211..f1beb7b 100644 (file)
@@ -59,7 +59,8 @@ enum { /**> Query field flags */
     EJCONDADDSET = 1 << 12, /**> $addToSet Adds value to the array only if its not in the array already.  */
     EJCONDPULL = 1 << 13, /**> $pull Removes all occurrences of value from field, if field is an array */
     EJCONDUPSERT = 1 << 14, /**> $upsert Upsert $set operation */
-    EJCONDALL  = 1 << 15 /**> 'All' modificator for $pull or $addToSet ($addToSetAll or $pullAll) */
+    EJCONDALL  = 1 << 15, /**> 'All' modificator for $pull or $addToSet ($addToSetAll or $pullAll) */
+    EJCONDOIT = 1 << 16 /**> $do query field operation */
 };
 
 
index ad9dbdf..8a113f3 100644 (file)
@@ -4049,6 +4049,18 @@ void testTicket38() {
     tclistdel(q1res);
 }
 
+
+void testTicket43() {
+    /*
+     Assuming fpath contains object id (or its string representation).
+     In query results fpath values will be replaced by loaded bson
+     objects with matching oids from collectionname
+
+     {..., $do : {fpath : {$join : 'collectionname'}} }
+
+    */
+}
+
 int main() {
 
     setlocale(LC_ALL, "en_US.UTF-8");
@@ -4116,7 +4128,8 @@ int main() {
             (NULL == CU_add_test(pSuite, "testPrimitiveCases1", testPrimitiveCases1)) ||
             (NULL == CU_add_test(pSuite, "testTicket29", testTicket29)) ||
             (NULL == CU_add_test(pSuite, "testTicket28", testTicket28)) ||
-            (NULL == CU_add_test(pSuite, "testTicket38", testTicket38))
+            (NULL == CU_add_test(pSuite, "testTicket38", testTicket38)) ||
+            (NULL == CU_add_test(pSuite, "testTicket43", testTicket43))
             ) {
         CU_cleanup_registry();
         return CU_get_error();