#29
authoradam <adamansky@gmail.com>
Mon, 7 Jan 2013 18:33:42 +0000 (01:33 +0700)
committeradam <adamansky@gmail.com>
Mon, 7 Jan 2013 18:33:42 +0000 (01:33 +0700)
tcejdb/ejdb.c
tcejdb/testejdb/t2.c

index 052002e..cadfbb6 100644 (file)
@@ -3768,9 +3768,10 @@ static bool _updatebsonidx(EJCOLL *jcoll, const bson_oid_t *oid, const bson *bs,
         if (obsdata && obsdatasz > 0) {
             bson_iterator_from_buffer(&oit, obsdata);
             oft = bson_find_fieldpath_value2(mkey + 1, mkeysz - 1, &oit);
-            TCLIST *tokens = (oft == BSON_ARRAY) ? tclistnew() : NULL;
+            TCLIST *tokens = (oft == BSON_ARRAY || (oft == BSON_STRING && (iflags & JBIDXARR))) ? tclistnew() : NULL;
             ofvalue = BSON_IS_IDXSUPPORTED_TYPE(oft) ? _bsonitstrval(jcoll->jb, &oit, &ofvaluesz, tokens, textflags) : NULL;
             if (tokens) {
+                oft = BSON_ARRAY;
                 ofvalue = tclistdump(tokens, &ofvaluesz);
                 tclistdel(tokens);
             }
@@ -3778,9 +3779,10 @@ static bool _updatebsonidx(EJCOLL *jcoll, const bson_oid_t *oid, const bson *bs,
         if (bs) {
             bson_iterator_init(&fit, bs);
             ft = bson_find_fieldpath_value2(mkey + 1, mkeysz - 1, &fit);
-            TCLIST *tokens = (ft == BSON_ARRAY) ? tclistnew() : NULL;
+            TCLIST *tokens = (ft == BSON_ARRAY || (ft == BSON_STRING && (iflags & JBIDXARR))) ? tclistnew() : NULL;
             fvalue = BSON_IS_IDXSUPPORTED_TYPE(ft) ? _bsonitstrval(jcoll->jb, &fit, &fvaluesz, tokens, textflags) : NULL;
             if (tokens) {
+                ft = BSON_ARRAY;
                 fvalue = tclistdump(tokens, &fvaluesz);
                 tclistdel(tokens);
             }
index e86712b..fb58eb0 100644 (file)
@@ -3809,6 +3809,50 @@ void testPrimitiveCases1() {
     ejdbquerydel(q1);
 }
 
+void testTicket29() {
+    EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
+    CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXARR));
+
+    bson a1;
+    bson_init(&a1);
+    bson_append_string(&a1, "name", "Hello Мир");
+    bson_append_long(&a1, "longscore", 77);
+    bson_finish(&a1);
+    CU_ASSERT_FALSE_FATAL(a1.err);
+
+    bson_oid_t oid;
+    CU_ASSERT_TRUE(ejdbsavebson(coll, &a1, &oid));
+    bson_destroy(&a1);
+
+    //{"name" : {$strand : ["Hello", "Мир"]}}
+    bson bsq1;
+    bson_init_as_query(&bsq1);
+    bson_append_start_object(&bsq1, "name");
+    bson_append_start_array(&bsq1, "$strand");
+    bson_append_string(&bsq1, "0", "Hello");
+    bson_append_string(&bsq1, "1", "Мир");
+    bson_append_finish_array(&bsq1);
+    bson_append_finish_object(&bsq1);
+    bson_finish(&bsq1);
+    CU_ASSERT_FALSE_FATAL(bsq1.err);
+
+    EJQ *q1 = ejdbcreatequery(jb, &bsq1, NULL, 0, NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+    uint32_t count = 0;
+    TCXSTR *log = tcxstrnew();
+    TCLIST *q1res = ejdbqryexecute(coll, q1, &count, 0, log);
+    //fprintf(stderr, "%s", TCXSTRPTR(log));
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1res);
+    CU_ASSERT_EQUAL(count, 1);
+    CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "token occurrence: \"Hello\" 1"));
+
+    bson_destroy(&bsq1);
+    tclistdel(q1res);
+    tcxstrdel(log);
+    ejdbquerydel(q1);
+}
+
 int main() {
 
     setlocale(LC_ALL, "en_US.UTF-8");
@@ -3872,7 +3916,8 @@ int main() {
             (NULL == CU_add_test(pSuite, "test$elemMatch", test$elemMatch)) ||
             (NULL == CU_add_test(pSuite, "testTicket16", testTicket16)) ||
             (NULL == CU_add_test(pSuite, "test$upsert", test$upsert)) ||
-            (NULL == CU_add_test(pSuite, "testPrimitiveCases1", testPrimitiveCases1))
+            (NULL == CU_add_test(pSuite, "testPrimitiveCases1", testPrimitiveCases1)) ||
+            (NULL == CU_add_test(pSuite, "testTicket29", testTicket29))
             ) {
         CU_cleanup_registry();
         return CU_get_error();