#14 + minors
authorAnton Adamansky <adamansky@gmail.com>
Tue, 10 Feb 2015 07:08:16 +0000 (13:08 +0600)
committerAnton Adamansky <adamansky@gmail.com>
Tue, 10 Feb 2015 07:08:16 +0000 (13:08 +0600)
28 files changed:
.gitignore
tcejdb/basedefs.h
tcejdb/bson.c
tcejdb/bson.h
tcejdb/ejdb.c
tcejdb/ejdb.h
tcejdb/ejdb_private.h
tcejdb/ejdbutl.h
tcejdb/myconf.c
tcejdb/myconf.h
tcejdb/platform.c
tcejdb/tcadb.c
tcejdb/tcadb.h
tcejdb/tcbdb.c
tcejdb/tcbdb.h
tcejdb/tcfdb.c
tcejdb/tcfdb.h
tcejdb/tchdb.c
tcejdb/tchdb.h
tcejdb/tctdb.c
tcejdb/tctdb.h
tcejdb/tcutil.c
tcejdb/tcutil.h
tcejdb/testejdb/Makefile.in
tcejdb/testejdb/t1.c
tcejdb/testejdb/t2.c
tcejdb/testejdb/t3.c
tcejdb/testejdb/t5.c [new file with mode: 0644]

index d9e556f..be93df5 100644 (file)
@@ -32,6 +32,7 @@ config.status
 
 /npm-debug.log
 /.idea/workspace.xml
+/.idea
 
 /tcejdb/*.dll
 /tcejdb/i686-w64*
@@ -83,6 +84,7 @@ config.status
 /tcejdb/testejdb/t2
 /tcejdb/testejdb/t3
 /tcejdb/testejdb/t4
+/tcejdb/testejdb/t5
 /tcejdb/testejdb/test*
 
 */nbproject/private/*
index 90d3eb0..4411eaa 100644 (file)
@@ -1,6 +1,6 @@
 /*************************************************************************************************
  * The abstract database API of EJDB
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of EJDB.
  * EJDB is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index d154196..1152481 100644 (file)
@@ -1,7 +1,7 @@
 /* bson.c */
 
 /*    Copyright 2009, 2010 10gen Inc.
- *    Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *    Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
index 79e8270..02395d0 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 /*    Copyright 2009-2012 10gen Inc.
- *    Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *    Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
index d947d8b..f4e861b 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************************************
  *  EJDB database library http://ejdb.org
- *  Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *  Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *  This file is part of EJDB.
  *  EJDB is free software; you can redistribute it and/or modify it under the terms of
@@ -201,7 +201,7 @@ const char* ejdberrmsg(int ecode) {
         case JBEQINCEXCL:
             return "$fields hint cannot mix include and exclude fields";
         case JBEQACTKEY:
-            return "action key in $do block can only be one of: $join";
+            return "action key in $do block can be one of: $join, $slice";
         case JBEMAXNUMCOLS:
             return "exceeded the maximum number of collections per database: 1024";
         case JBEEJSONPARSE:
@@ -2516,59 +2516,113 @@ static bson_visitor_cmd_t _bson$dovisitor(const char *ipath, int ipathlen, const
             assert(dofield->updateobj && (dofield->flags & EJCONDOIT));
             BSON_ITERATOR_INIT(&doit, dofield->updateobj);
             while ((bt = bson_iterator_next(&doit)) != BSON_EOO) {
-                if (bt != BSON_STRING || strcmp("$join", BSON_ITERATOR_KEY(&doit))) continue;
-                coll = _getcoll(ictx->jb, bson_iterator_string(&doit));
-                if (!coll) break;
-                bson_oid_t loid;
-                if (lbt == BSON_STRING) {
-                    sval = bson_iterator_string(it);
-                    if (!ejdbisvalidoidstr(sval)) break;
-                    bson_oid_from_string(&loid, sval);
-                } else if (lbt == BSON_OID) {
-                    loid = *(bson_iterator_oid(it));
-                }
-                if (lbt == BSON_STRING || lbt == BSON_OID) {
-                    tcxstrclear(ictx->q->colbuf);
-                    tcxstrclear(ictx->q->tmpbuf);
-                    if (!tchdbgetintoxstr(coll->tdb->hdb, &loid, sizeof (loid), ictx->q->colbuf) ||
-                            !tcmaploadoneintoxstr(TCXSTRPTR(ictx->q->colbuf), TCXSTRSIZE(ictx->q->colbuf),
-                                                  JDBCOLBSON, JDBCOLBSONL, ictx->q->tmpbuf)) {
-                        break;
-                    }
-                    BSON_ITERATOR_FROM_BUFFER(&bufit, TCXSTRPTR(ictx->q->tmpbuf));
-                    bson_append_object_from_iterator(BSON_ITERATOR_KEY(it), &bufit, ictx->sbson);
-                    break;
-                }
-                if (lbt == BSON_ARRAY) {
-                    BSON_ITERATOR_SUBITERATOR(it, &sit);
-                    bson_append_start_array(ictx->sbson, BSON_ITERATOR_KEY(it));
-                    while ((bt = bson_iterator_next(&sit)) != BSON_EOO) {
-                        if (bt != BSON_STRING && bt != BSON_OID) {
-                            bson_append_field_from_iterator(&sit, ictx->sbson);
-                            continue;
-                        }
-                        if (bt == BSON_STRING) {
-                            sval = bson_iterator_string(&sit);
-                            if (!ejdbisvalidoidstr(sval)) break;
-                            bson_oid_from_string(&loid, sval);
-                        } else if (bt == BSON_OID) {
-                            loid = *(bson_iterator_oid(&sit));
-                        }
-                        tcxstrclear(ictx->q->colbuf);
-                        tcxstrclear(ictx->q->tmpbuf);
-                        if (!tchdbgetintoxstr(coll->tdb->hdb, &loid, sizeof (loid), ictx->q->colbuf) ||
-                                !tcmaploadoneintoxstr(TCXSTRPTR(ictx->q->colbuf), TCXSTRSIZE(ictx->q->colbuf),
-                                                      JDBCOLBSON, JDBCOLBSONL, ictx->q->tmpbuf)) {
-                            bson_append_field_from_iterator(&sit, ictx->sbson);
-                            continue;
-                        }
-                        BSON_ITERATOR_FROM_BUFFER(&bufit, TCXSTRPTR(ictx->q->tmpbuf));
-                        bson_append_object_from_iterator(BSON_ITERATOR_KEY(&sit), &bufit, ictx->sbson);
-                    }
-                    bson_append_finish_array(ictx->sbson);
-                    rv = (BSON_VCMD_SKIP_AFTER | BSON_VCMD_SKIP_NESTED);
-                }
-            }
+                               const char *dofname = BSON_ITERATOR_KEY(&doit);
+                               
+                               if (bt == BSON_STRING && !strcmp("$join", dofname)) {
+                                       coll = _getcoll(ictx->jb, bson_iterator_string(&doit));
+                                       if (!coll) break;
+                                       bson_oid_t loid;
+                                       if (lbt == BSON_STRING) {
+                                               sval = bson_iterator_string(it);
+                                               if (!ejdbisvalidoidstr(sval)) break;
+                                               bson_oid_from_string(&loid, sval);
+                                       } else if (lbt == BSON_OID) {
+                                               loid = *(bson_iterator_oid(it));
+                                       }
+                                       if (lbt == BSON_STRING || lbt == BSON_OID) {
+                                               tcxstrclear(ictx->q->colbuf);
+                                               tcxstrclear(ictx->q->tmpbuf);
+                                               if (!tchdbgetintoxstr(coll->tdb->hdb, &loid, sizeof (loid), ictx->q->colbuf) ||
+                                                               !tcmaploadoneintoxstr(TCXSTRPTR(ictx->q->colbuf), TCXSTRSIZE(ictx->q->colbuf),
+                                                                                                         JDBCOLBSON, JDBCOLBSONL, ictx->q->tmpbuf)) {
+                                                       break;
+                                               }
+                                               BSON_ITERATOR_FROM_BUFFER(&bufit, TCXSTRPTR(ictx->q->tmpbuf));
+                                               bson_append_object_from_iterator(BSON_ITERATOR_KEY(it), &bufit, ictx->sbson);
+                                               break;
+                                       }
+                                       if (lbt == BSON_ARRAY) {
+                                               BSON_ITERATOR_SUBITERATOR(it, &sit);
+                                               bson_append_start_array(ictx->sbson, BSON_ITERATOR_KEY(it));
+                                               while ((bt = bson_iterator_next(&sit)) != BSON_EOO) {
+                                                       if (bt != BSON_STRING && bt != BSON_OID) {
+                                                               bson_append_field_from_iterator(&sit, ictx->sbson);
+                                                               continue;
+                                                       }
+                                                       if (bt == BSON_STRING) {
+                                                               sval = bson_iterator_string(&sit);
+                                                               if (!ejdbisvalidoidstr(sval)) break;
+                                                               bson_oid_from_string(&loid, sval);
+                                                       } else if (bt == BSON_OID) {
+                                                               loid = *(bson_iterator_oid(&sit));
+                                                       }
+                                                       tcxstrclear(ictx->q->colbuf);
+                                                       tcxstrclear(ictx->q->tmpbuf);
+                                                       if (!tchdbgetintoxstr(coll->tdb->hdb, &loid, sizeof (loid), ictx->q->colbuf) ||
+                                                                       !tcmaploadoneintoxstr(TCXSTRPTR(ictx->q->colbuf), TCXSTRSIZE(ictx->q->colbuf),
+                                                                                                                 JDBCOLBSON, JDBCOLBSONL, ictx->q->tmpbuf)) {
+                                                               bson_append_field_from_iterator(&sit, ictx->sbson);
+                                                               continue;
+                                                       }
+                                                       BSON_ITERATOR_FROM_BUFFER(&bufit, TCXSTRPTR(ictx->q->tmpbuf));
+                                                       bson_append_object_from_iterator(BSON_ITERATOR_KEY(&sit), &bufit, ictx->sbson);
+                                               }
+                                               bson_append_finish_array(ictx->sbson);
+                                               rv = (BSON_VCMD_SKIP_AFTER | BSON_VCMD_SKIP_NESTED);
+                                       }
+                                       
+                               } else if (lbt == BSON_ARRAY && 
+                                                       (bt == BSON_ARRAY || BSON_IS_NUM_TYPE(bt)) && 
+                                                       !strcmp("$slice", dofname)) {
+                                                               
+                                       bson_append_start_array(ictx->sbson, BSON_ITERATOR_KEY(it));
+                                       int skip = 0, limit, idx = 0, i;
+                                       char nbuff[TCNUMBUFSIZ];
+                                       
+                                       if (bt == BSON_ARRAY) { // $slice : [skip, limit]
+                                               bson_type bt2;
+                                               bson_iterator sit2;
+                                               BSON_ITERATOR_SUBITERATOR(&doit, &sit2);
+                                               
+                                               bt2 = bson_find_fieldpath_value2("0", 1, &sit2);
+                                               if (!BSON_IS_NUM_TYPE(bt2)) {
+                                                       bson_append_field_from_iterator(it, ictx->sbson);
+                                                       break;
+                                               }
+                                               skip = bson_iterator_int(&sit2);
+                                               
+                                               bt2 = bson_find_fieldpath_value2("1", 1, &sit2);
+                                               if (!BSON_IS_NUM_TYPE(bt2)) {
+                                                       bson_append_field_from_iterator(it, ictx->sbson);
+                                                       break;
+                                               }
+                                               limit = abs(bson_iterator_int(&sit2));
+                                       } else { // $slice : limit
+                                               limit = abs(bson_iterator_int(&doit));
+                                       }
+                                       
+                                       if (skip < 0) {
+                                               int cnt = 0;
+                                               BSON_ITERATOR_SUBITERATOR(it, &sit);
+                                               while (bson_iterator_next(&sit) != BSON_EOO) ++cnt;
+                                               skip = cnt + skip % cnt;
+                                               if (skip == cnt) {
+                                                       skip = 0;
+                                               }
+                                       }
+                                       
+                                       limit = (limit <= INT_MAX - skip) ? limit + skip : INT_MAX;
+                                       BSON_ITERATOR_SUBITERATOR(it, &sit);
+                                       for (i = 0; idx < limit && (bt = bson_iterator_next(&sit)) != BSON_EOO; ++idx) {
+                                               if (idx >= skip) {
+                                                       bson_numstrn(nbuff, TCNUMBUFSIZ, i++);
+                                                       bson_append_field_from_iterator2(nbuff, &sit, ictx->sbson);
+                                               }
+                                       }
+                                       bson_append_finish_array(ictx->sbson);
+                                       rv = (BSON_VCMD_SKIP_AFTER | BSON_VCMD_SKIP_NESTED);
+                               }
+                       }
             break;
         }
         default:
@@ -4830,7 +4884,7 @@ static int _parse_qobj_impl(EJDB *jb, EJQ *q, bson_iterator *it, TCLIST *qlist,
                         int ac = 0;
                         while ((sbt = bson_iterator_next(&sit)) != BSON_EOO) {
                             const char *akey = BSON_ITERATOR_KEY(&sit);
-                            if (!strcmp("$join", akey)) {
+                            if (!strcmp("$join", akey) || !strcmp("$slice", akey)) {
                                 bson_append_field_from_iterator(&sit, qf.updateobj);
                                 ++ac;
                             }
@@ -5495,4 +5549,4 @@ static bool _qrycondcheckstror(const char *vbuf, const TCLIST *tokens) {
         }
     }
     return false;
-}
+}
\ No newline at end of file
index e3a32b5..7797bd5 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************************************
  *  C/C++ API for EJDB database library http://ejdb.org
- *  Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *  Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *  This file is part of EJDB.
  *  EJDB is free software; you can redistribute it and/or modify it under the terms of
@@ -62,7 +62,7 @@ enum { /** Error codes */
     JBEQUPDFAILED = 9010, /**< Updating failed. */
     JBEQONEEMATCH = 9011, /**< Only one $elemMatch allowed in the fieldpath. */
     JBEQINCEXCL = 9012, /**< $fields hint cannot mix include and exclude fields */
-    JBEQACTKEY = 9013, /**< action key in $do block can only be one of: $join */
+    JBEQACTKEY = 9013, /**< action key in $do block can only be one of: $join, $slice */
     JBEMAXNUMCOLS = 9014, /**< Exceeded the maximum number of collections per database */
     JBEEI = 9015, /**< EJDB export/import error */
     JBEEJSONPARSE = 9016, /**< JSON parsing failed */
@@ -329,7 +329,6 @@ EJDB_EXPORT bson* ejdbloadbson(EJCOLL *coll, const bson_oid_t *oid);
  *          - { $unset: { 'fpath1' : "", ... } }
  *
  * - Collection joins supported in the following form:
- *
  *      {..., $do : {fpath : {$join : 'collectionname'}} }
  *      Where 'fpath' value points to object's OIDs from 'collectionname'. Its value
  *      can be OID, string representation of OID or array of this pointers.
index 57d60ad..fc5f454 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************************************
  *  EJDB database library http://ejdb.org
- *  Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *  Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *  This file is part of EJDB.
  *  EJDB is free software; you can redistribute it and/or modify it under the terms of
index aeb7030..b4300b5 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************************************
  *  EJDB database library http://ejdb.org
- *  Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *  Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  *
  *  This file is part of EJDB.
  *  EJDB is free software; you can redistribute it and/or modify it under the terms of
index 3c4a6ea..9df9f0e 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * System-dependent configurations of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 11c7439..e01d05b 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * System-dependent configurations of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 8c99a23..192d958 100644 (file)
@@ -1,6 +1,6 @@
 /*************************************************************************************************
  * The abstract database API of EJDB
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of EJDB.
  * EJDB is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 63d33a5..627a69a 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The abstract database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index abac4db..7cb84f8 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The abstract database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 3f3baac..a5cf206 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The B+ tree database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 3291020..1928698 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The B+ tree database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index c6c6762..1e5e478 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The fixed-length database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index e83259f..f6f8a71 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The fixed-length database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 34fe4d4..9dea335 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The hash database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
@@ -3730,7 +3730,6 @@ static bool tchdbopenimpl(TCHDB *hdb, const char *path, int omode) {
     hdb->omode = omode;
     hdb->fd = fd;
 
-
     if (!(omode & HDBONOLCK)) {
         if (!tclock(fd, omode & HDBOWRITER, omode & HDBOLCKNB)) {
             tchdbsetecode(hdb, TCELOCK, __FILE__, __LINE__, __func__);
index 460b977..157ce85 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The hash database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index a623d0a..5db0722 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The table database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index d62a17e..82cee8f 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The table database API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index 9fe9cbf..e4739cf 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The utility API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
index f2aecfa..7cb2f13 100644 (file)
@@ -1,7 +1,7 @@
 /*************************************************************************************************
  * The utility API of Tokyo Cabinet
  *                                                               Copyright (C) 2006-2012 FAL Labs
- *                                                               Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
+ *                                                               Copyright (C) 2012-2015 Softmotions Ltd <info@softmotions.com>
  * This file is part of Tokyo Cabinet.
  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
  * the GNU Lesser General Public License as published by the Free Software Foundation; either
@@ -3733,7 +3733,7 @@ typedef unsigned char TCBITMAP; /* type of a bit map object */
 
 #include <stdio.h>
 
-#define _TC_VERSION    "1.1.25"
+#define _TC_VERSION    "1.1.26"
 #define _TC_LIBVER     911
 #define _TC_FORMATVER  "1.0"
 
index 7ed5e67..cf17289 100644 (file)
@@ -7,7 +7,7 @@ CMDLDFLAGS =
 LIBS = -lcunit -ltcejdb @LIBS@
 RUNENV = LD_LIBRARY_PATH=.:.. DYLD_LIBRARY_PATH=.:..
 
-TESTS = t1 t2 t3 t4
+TESTS = t1 t2 t3 t4 t5
 
 check : all check-t1 check-t2 check-t3 check-t4;
 
@@ -23,6 +23,10 @@ check-valgrind-t3 :
 check-valgrind-t4 :
        make RUNCMD="valgrind --tool=memcheck --leak-check=full --error-exitcode=1" check-t4
 
+check-valgrind-t5 :
+       make RUNCMD="valgrind --tool=memcheck --leak-check=full --error-exitcode=1" check-t5
+
+
 check-t1 :
        $(RUNENV) $(RUNCMD) ./t1
 
@@ -34,6 +38,9 @@ check-t3 :
 
 check-t4 :
        $(RUNENV) $(RUNCMD) ./t4
+       
+check-t5 :
+       $(RUNENV) $(RUNCMD) ./t5
 
 
 all : $(TESTS)
@@ -52,6 +59,9 @@ t3 : t3.o
 
 t4 : t4.o
        $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) $(CMDLDFLAGS) $(LIBS)
+               
+t5 : t5.o
+       $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) $(CMDLDFLAGS) $(LIBS)
 
 
 .PHONY : all clean check check-t1 check-t2 check-t3 check-t4
index 4e57b9c..1d9e6f1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * File:   ejdbtest1.c
- * Author: Adamansky Anton <anton@adamansky.com>
+ * Author: Adamansky Anton <adamansky@gmail.com>
  *
  * Created on Sep 18, 2012, 10:42:19 PM
  */
index 2677f85..5652c66 100644 (file)
@@ -30,7 +30,7 @@ int clean_suite(void) {
     return 0;
 }
 
-void testAddData() {
+void testAddData(void) {
     CU_ASSERT_PTR_NOT_NULL_FATAL(jb);
     bson_oid_t oid;
     EJCOLL *ccoll = ejdbcreatecoll(jb, "contacts", NULL);
@@ -129,10 +129,10 @@ void testAddData() {
     bson_destroy(&a1);
 }
 
-void testInvalidQueries1() {
+void testInvalidQueries1(void) {
 }
 
-void testSetIndex1() {
+void testSetIndex1(void) {
     EJCOLL *ccoll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(ccoll);
     CU_ASSERT_TRUE(ejdbsetindex(ccoll, "ab.c.d", JBIDXSTR));
@@ -193,7 +193,7 @@ void testSetIndex1() {
     bson_destroy(&a1);
 }
 
-void testQuery1() {
+void testQuery1(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -256,7 +256,7 @@ void testQuery1() {
     tcxstrdel(log);
 }
 
-void testQuery2() {
+void testQuery2(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -311,7 +311,7 @@ void testQuery2() {
     tcxstrdel(log);
 }
 
-void testQuery3() {
+void testQuery3(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.zip", JBIDXDROPALL));
@@ -368,7 +368,7 @@ void testQuery3() {
     tcxstrdel(log);
 }
 
-void testQuery4() {
+void testQuery4(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXDROPALL));
@@ -423,8 +423,7 @@ void testQuery4() {
     tcxstrdel(log);
 }
 
-void testQuery5() {
-
+void testQuery5(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     bson bsq1;
@@ -456,7 +455,7 @@ void testQuery5() {
     ejdbquerydel(q1);
 }
 
-void testQuery6() {
+void testQuery6(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXARR));
@@ -514,7 +513,7 @@ void testQuery6() {
     ejdbquerydel(q1);
 }
 
-void testQuery7() {
+void testQuery7(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -567,7 +566,7 @@ void testQuery7() {
     ejdbquerydel(q1);
 }
 
-void testQuery8() {
+void testQuery8(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -690,7 +689,7 @@ void testQuery8() {
     ejdbquerydel(q1);
 }
 
-void testQuery9() {
+void testQuery9(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "labels", JBIDXDROPALL));
@@ -748,7 +747,7 @@ void testQuery9() {
     ejdbquerydel(q1);
 }
 
-void testQuery10() {
+void testQuery10(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXSTR));
@@ -813,7 +812,7 @@ void testQuery10() {
     ejdbquerydel(q1);
 }
 
-void testQuery11() {
+void testQuery11(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.street", JBIDXDROPALL));
@@ -879,7 +878,7 @@ void testQuery11() {
     ejdbquerydel(q1);
 }
 
-void testQuery12() {
+void testQuery12(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -942,7 +941,7 @@ void testQuery12() {
     ejdbquerydel(q1);
 }
 
-void testQuery13() {
+void testQuery13(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -1010,7 +1009,7 @@ void testQuery13() {
     ejdbquerydel(q1);
 }
 
-void testQuery14() {
+void testQuery14(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "drinks", JBIDXARR));
@@ -1064,7 +1063,7 @@ void testQuery14() {
     ejdbquerydel(q1);
 }
 
-void testQuery15() {
+void testQuery15(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
@@ -1110,7 +1109,7 @@ void testQuery15() {
     ejdbquerydel(q1);
 }
 
-void testQuery16() {
+void testQuery16(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXDROPALL));
@@ -1155,7 +1154,7 @@ void testQuery16() {
     ejdbquerydel(q1);
 }
 
-void testQuery17() {
+void testQuery17(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "dblscore", JBIDXNUM));
@@ -1276,7 +1275,7 @@ void testQuery17() {
     ejdbquerydel(q1);
 }
 
-void testQuery18() {
+void testQuery18(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR));
@@ -1391,7 +1390,7 @@ void testQuery18() {
     ejdbquerydel(q1);
 }
 
-void testQuery19() {
+void testQuery19(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "name", JBIDXARR));
@@ -1487,7 +1486,7 @@ void testQuery19() {
     ejdbquerydel(q1);
 }
 
-void testQuery20() {
+void testQuery20(void) {
     //dblscore
     //{'dblscore' : {'$gte' : 0.93}}
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
@@ -1646,7 +1645,7 @@ void testQuery20() {
     ejdbquerydel(q1);
 }
 
-void testQuery21() {
+void testQuery21(void) {
     //{'dblscore' : {'lte' : 0.93}}
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
@@ -1813,7 +1812,7 @@ void testQuery21() {
     ejdbquerydel(q1);
 }
 
-void testQuery22() {
+void testQuery22(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
     CU_ASSERT_TRUE(ejdbsetindex(contacts, "address.country", JBIDXSTR));
@@ -1939,7 +1938,7 @@ void testQuery22() {
     ejdbquerydel(q1);
 }
 
-void testQuery23() {
+void testQuery23(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -1992,7 +1991,7 @@ void testQuery23() {
     ejdbquerydel(q1);
 }
 
-void testQuery24() {
+void testQuery24(void) {
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2202,7 +2201,7 @@ void testQuery24() {
 
 }
 
-void testQuery25() { //$or
+void testQuery25(void) { //$or
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2261,7 +2260,7 @@ void testQuery25() { //$or
     }
 }
 
-void testQuery25_2() { //$or alternative
+void testQuery25_2(void) { //$or alternative
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2316,7 +2315,7 @@ void testQuery25_2() { //$or alternative
     ejdbquerydel(q1);
 }
 
-void testQuery26() { //$not $nin
+void testQuery26(void) { //$not $nin
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2447,7 +2446,7 @@ void testQuery26() { //$not $nin
     ejdbquerydel(q1);
 }
 
-void testQuery27() { //$exists
+void testQuery27(void) { //$exists
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2564,7 +2563,7 @@ void testQuery27() { //$exists
     ejdbquerydel(q1);
 }
 
-void testOIDSMatching() { //OID matching
+void testOIDSMatching(void) { //OID matching
     EJCOLL *contacts = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(contacts);
 
@@ -2625,7 +2624,7 @@ void testOIDSMatching() { //OID matching
     ejdbquerydel(q1);
 }
 
-void testEmptyFieldIndex() {
+void testEmptyFieldIndex(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXDROPALL));
@@ -2652,7 +2651,7 @@ void testEmptyFieldIndex() {
     CU_ASSERT_EQUAL(ejdbecode(coll->jb), 0);
 }
 
-void testICaseIndex() {
+void testICaseIndex(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXISTR)); //Ignore case string index
@@ -2748,7 +2747,7 @@ void testICaseIndex() {
     ejdbquerydel(q1);
 }
 
-void testTicket7() { //https://github.com/Softmotions/ejdb/issues/7
+void testTicket7(void) { //https://github.com/Softmotions/ejdb/issues/7
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -2845,7 +2844,7 @@ void testTicket7() { //https://github.com/Softmotions/ejdb/issues/7
     ejdbquerydel(q2);
 }
 
-void testTicket8() { //https://github.com/Softmotions/ejdb/issues/8
+void testTicket8(void) { //https://github.com/Softmotions/ejdb/issues/8
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -3025,8 +3024,7 @@ void testTicket8() { //https://github.com/Softmotions/ejdb/issues/8
 
 }
 
-void testUpdate1() { //https://github.com/Softmotions/ejdb/issues/9
-
+void testUpdate1(void) { //https://github.com/Softmotions/ejdb/issues/9
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -3147,7 +3145,7 @@ void testUpdate1() { //https://github.com/Softmotions/ejdb/issues/9
        
 }
 
-void testUpdate2() { //https://github.com/Softmotions/ejdb/issues/9
+void testUpdate2(void) { //https://github.com/Softmotions/ejdb/issues/9
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "age", JBIDXNUM));
@@ -3204,7 +3202,7 @@ void testUpdate2() { //https://github.com/Softmotions/ejdb/issues/9
 
 }
 
-void testUpdate3() {
+void testUpdate3(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -3310,7 +3308,7 @@ void testUpdate3() {
        
 }
 
-void testTicket88() { //https://github.com/Softmotions/ejdb/issues/88
+void testTicket88(void) { //https://github.com/Softmotions/ejdb/issues/88
     EJCOLL *ccoll = ejdbcreatecoll(jb, "ticket88", NULL);
     CU_ASSERT_PTR_NOT_NULL(ccoll);
 
@@ -3362,7 +3360,7 @@ void testTicket88() { //https://github.com/Softmotions/ejdb/issues/88
     bson_destroy(&bsq2);
 }
 
-void testTicket89() { //https://github.com/Softmotions/ejdb/issues/89
+void testTicket89(void) { //https://github.com/Softmotions/ejdb/issues/89
     EJCOLL *ccoll = ejdbcreatecoll(jb, "ticket89", NULL);
     CU_ASSERT_PTR_NOT_NULL(ccoll);
 
@@ -3411,7 +3409,7 @@ void testTicket89() { //https://github.com/Softmotions/ejdb/issues/89
     bson_destroy(&bsq1);
 }
 
-void testQueryBool() {
+void testQueryBool(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -3459,7 +3457,7 @@ void testQueryBool() {
     ejdbquerydel(q1);
 }
 
-void testDropAll() {
+void testDropAll(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXSTR));
@@ -3507,7 +3505,7 @@ void testDropAll() {
     ejdbquerydel(q1);
 }
 
-void testTokens$begin() {
+void testTokens$begin(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXSTR));
@@ -3580,7 +3578,7 @@ void testTokens$begin() {
     ejdbquerydel(q1);
 }
 
-void testOneFieldManyConditions() {
+void testOneFieldManyConditions(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -3609,7 +3607,7 @@ void testOneFieldManyConditions() {
     ejdbquerydel(q1);
 }
 
-void test$addToSet() {
+void test$addToSet(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson bsq1;
@@ -3773,7 +3771,7 @@ void test$addToSet() {
     ejdbquerydel(q1);
 }
 
-void test$pull() {
+void test$pull(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson bsq1;
@@ -3825,7 +3823,7 @@ void test$pull() {
     ejdbquerydel(q1);
 }
 
-void testFindInComplexArray() {
+void testFindInComplexArray(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson bsq1;
@@ -4005,7 +4003,7 @@ void testFindInComplexArray() {
     ejdbquerydel(q1);
 }
 
-void test$elemMatch() {
+void test$elemMatch(void) {
     // { complexarr: { $elemMatch: { key: 'title', value: 'some title' } } }
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
@@ -4144,7 +4142,7 @@ void test$elemMatch() {
     ejdbquerydel(q1);
 }
 
-void test$not$elemMatch() {
+void test$not$elemMatch(void) {
     // { complexarr: { $not: { $elemMatch: { key: 'title', value: 'some title' } } } }
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
@@ -4281,7 +4279,7 @@ void test$not$elemMatch() {
     ejdbquerydel(q1);
 }
 
-void testTicket16() {
+void testTicket16(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "abcd", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_EQUAL(coll->tdb->inum, 0);
@@ -4292,7 +4290,7 @@ void testTicket16() {
     CU_ASSERT_EQUAL(coll->tdb->inum, 0);
 }
 
-void test$upsert() {
+void test$upsert(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "abcd", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson bsq1;
@@ -4369,7 +4367,7 @@ void test$upsert() {
     ejdbquerydel(q1);
 }
 
-void testPrimitiveCases1() {
+void testPrimitiveCases1(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "abcd", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson bsq1;
@@ -4416,7 +4414,7 @@ void testPrimitiveCases1() {
     ejdbquerydel(q1);
 }
 
-void testTicket29() {
+void testTicket29(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     CU_ASSERT_TRUE(ejdbsetindex(coll, "name", JBIDXARR));
@@ -4460,7 +4458,7 @@ void testTicket29() {
     ejdbquerydel(q1);
 }
 
-void testTicket28() {
+void testTicket28(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     //{$some:2}
@@ -4491,7 +4489,7 @@ void testTicket28() {
     tclistdel(q1res);
 }
 
-void testTicket38() {
+void testTicket38(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket38", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -4565,7 +4563,7 @@ void testTicket38() {
     tclistdel(q1res);
 }
 
-void testTicket43() {
+void testTicket43(void) {
 
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket43", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
@@ -4738,7 +4736,7 @@ void testTicket43() {
     tcxstrdel(log);
 }
 
-void testTicket54() {
+void testTicket54(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket54", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
     bson b;
@@ -4751,7 +4749,7 @@ void testTicket54() {
     CU_ASSERT_TRUE(ejdbsetindex(coll, "value", JBIDXNUM));
 }
 
-void testMetaInfo() {
+void testMetaInfo(void) {
     bson *meta = ejdbmeta(jb);
     CU_ASSERT_PTR_NOT_NULL_FATAL(meta);
     const char *metabsdata = bson_data(meta);
@@ -4763,7 +4761,7 @@ void testMetaInfo() {
     bson_del(meta);
 }
 
-void testTicket81() {
+void testTicket81(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket81", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -4873,7 +4871,7 @@ void testTicket81() {
 // https://github.com/Softmotions/ejdb/issues/15
 // http://docs.mongodb.org/manual/reference/projection/positional/#proj._S_
 
-void testDQprojection() {
+void testDQprojection(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "f_projection", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5013,7 +5011,7 @@ void testDQprojection() {
     bson_destroy(&bsq1);
 }
 
-void testTicket96() {
+void testTicket96(void) {
     EJCOLL *coll = ejdbgetcoll(jb, "f_projection");
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5051,7 +5049,7 @@ void testTicket96() {
 // https://github.com/Softmotions/ejdb/issues/15
 // http://docs.mongodb.org/manual/reference/projection/positional/#proj._S_
 
-void testDQupdate() {
+void testDQupdate(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "f_update", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5108,7 +5106,7 @@ void testDQupdate() {
 
 }
 
-void testDQupdate2() {
+void testDQupdate2(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "f_update", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5169,7 +5167,7 @@ void testDQupdate2() {
     bson_destroy(&bsq1);
 }
 
-void testTicket99() {
+void testTicket99(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket99", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5225,7 +5223,7 @@ void testTicket99() {
 }
 
 
-void testTicket101() {
+void testTicket101(void) {
     EJCOLL *coll = ejdbcreatecoll(jb, "ticket101", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
 
@@ -5290,7 +5288,7 @@ void testTicket101() {
     ejdbquerydel(q1);
 }
 
-void testTicket110() {
+void testTicket110(void) {
        EJCOLL *coll = ejdbcreatecoll(jb, "ticket110", NULL);
     CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
        
@@ -5358,6 +5356,171 @@ void testTicket110() {
        ejdbquerydel(q1);
 }
 
+// Ticket #14
+void testSlice(void) {
+       EJCOLL *coll = ejdbgetcoll(jb, "f_projection");
+    CU_ASSERT_PTR_NOT_NULL_FATAL(coll);
+       
+       bson_iterator it;
+       
+// { z : 44, $do : { arr : {$slice : 1} } }
+       bson bsq;
+    bson_init_as_query(&bsq);
+    bson_append_int(&bsq, "z", 44);
+    bson_append_start_object(&bsq, "$do");
+    bson_append_start_object(&bsq, "arr");
+    bson_append_int(&bsq, "$slice", 1);
+    bson_append_finish_object(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_finish(&bsq);
+    CU_ASSERT_FALSE_FATAL(bsq.err);
+       
+       EJQ *q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+       
+       uint32_t count = 0;
+    TCLIST *q1res = ejdbqryexecute(coll, q1, &count, 0, NULL);
+       //fprintf(stderr, "\n%s", TCXSTRPTR(log));
+       CU_ASSERT_EQUAL(TCLISTNUM(q1res), 1);
+    for (int i = 0; i < TCLISTNUM(q1res); ++i) {
+               void *bsdata = TCLISTVALPTR(q1res, i);
+        CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
+        CU_ASSERT_FALSE(bson_compare_long(1, bsdata, "arr.0.h"));
+               bson_iterator_from_buffer(&it, bsdata);
+               CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.1.h", &it) == BSON_EOO);
+    }
+       tclistdel(q1res);
+       bson_destroy(&bsq);
+       ejdbquerydel(q1);
+       
+       // { z : 44, $do : { arr : {$slice : 2} } }
+       bson_init_as_query(&bsq);
+    bson_append_int(&bsq, "z", 44);
+    bson_append_start_object(&bsq, "$do");
+    bson_append_start_object(&bsq, "arr");
+    bson_append_int(&bsq, "$slice", 2);
+    bson_append_finish_object(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_finish(&bsq);
+    CU_ASSERT_FALSE_FATAL(bsq.err);
+       
+       q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+       
+       count = 0;
+    q1res = ejdbqryexecute(coll, q1, &count, 0, NULL);
+       CU_ASSERT_EQUAL(TCLISTNUM(q1res), 1);
+       CU_ASSERT_EQUAL(count, 1);
+    for (int i = 0; i < TCLISTNUM(q1res); ++i) {
+               void *bsdata = TCLISTVALPTR(q1res, i);
+        CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
+        CU_ASSERT_FALSE(bson_compare_long(1, bsdata, "arr.0.h"));
+        CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.1.h"));
+               bson_iterator_from_buffer(&it, bsdata);
+               CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.2.h", &it) == BSON_EOO);
+    }
+       tclistdel(q1res);
+       bson_destroy(&bsq);
+       ejdbquerydel(q1);
+       
+       // { $do : { arr : {$slice : [1, 2]} } }
+       bson_init_as_query(&bsq);
+    bson_append_start_object(&bsq, "$do");
+    bson_append_start_object(&bsq, "arr");
+    bson_append_start_array(&bsq, "$slice");
+       bson_append_int(&bsq, "0", 1);
+       bson_append_int(&bsq, "1", 2);
+       bson_append_finish_array(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_finish(&bsq);
+    CU_ASSERT_FALSE_FATAL(bsq.err);
+       
+       q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+       
+       count = 0;
+    q1res = ejdbqryexecute(coll, q1, &count, 0, NULL);
+       CU_ASSERT_EQUAL(TCLISTNUM(q1res), 3);
+       CU_ASSERT_EQUAL(count, 3);
+    for (int i = 0; i < TCLISTNUM(q1res); ++i) {
+               void *bsdata = TCLISTVALPTR(q1res, i);
+        CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
+               if (i == 0) {
+                       CU_ASSERT_FALSE(bson_compare_long(1, bsdata, "arr.0"));
+                       CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.1"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.2", &it) == BSON_EOO);
+               } else if (i == 1) {
+                       CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.0"));
+                       CU_ASSERT_FALSE(bson_compare_long(1, bsdata, "arr.1"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.2", &it) == BSON_EOO);
+               } else if (i == 2) {
+                       CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.0.h"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.1", &it) == BSON_EOO);
+               }
+    }
+       tclistdel(q1res);
+       bson_destroy(&bsq);
+       ejdbquerydel(q1);
+       
+       
+       
+//{ _id: '54d7a2f07e671e140000001f',
+//  z: 33,
+//  arr: [ 0, 1, 2, 3 ] }
+//{ _id: '54d7a2f07e671e1400000020',
+//  z: 33,
+//  arr: [ 3, 2, 1, 0 ] }
+//{ _id: '54d7a2f07e671e1400000021',
+//  z: 44,
+//  arr: [ { h: 1 }, { h: 2 } ] } 
+       
+       // { $do : { arr : {$slice : [-3, 1]} } }
+       bson_init_as_query(&bsq);
+    bson_append_start_object(&bsq, "$do");
+    bson_append_start_object(&bsq, "arr");
+    bson_append_start_array(&bsq, "$slice");
+       bson_append_int(&bsq, "0", -3);
+       bson_append_int(&bsq, "1", 1);
+       bson_append_finish_array(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_append_finish_object(&bsq);
+    bson_finish(&bsq);
+    CU_ASSERT_FALSE_FATAL(bsq.err);
+       
+       q1 = ejdbcreatequery(jb, &bsq, NULL, 0, NULL);
+    CU_ASSERT_PTR_NOT_NULL_FATAL(q1);
+       
+       count = 0;
+    q1res = ejdbqryexecute(coll, q1, &count, 0, NULL);
+       CU_ASSERT_EQUAL(TCLISTNUM(q1res), 3);
+       CU_ASSERT_EQUAL(count, 3);
+    for (int i = 0; i < TCLISTNUM(q1res); ++i) {
+               void *bsdata = TCLISTVALPTR(q1res, i);
+        CU_ASSERT_PTR_NOT_NULL_FATAL(bsdata);
+               if (i == 0) {
+                       CU_ASSERT_FALSE(bson_compare_long(1, bsdata, "arr.0"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.1", &it) == BSON_EOO);
+               } else if (i == 1) {
+                       CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.0"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.1", &it) == BSON_EOO);
+               } else if (i == 2) {
+                       CU_ASSERT_FALSE(bson_compare_long(2, bsdata, "arr.0.h"));
+                       bson_iterator_from_buffer(&it, bsdata);
+                       CU_ASSERT_TRUE(bson_find_fieldpath_value("arr.1", &it) == BSON_EOO);
+               }
+    }
+       tclistdel(q1res);
+       bson_destroy(&bsq);
+       ejdbquerydel(q1);
+}
+
+
 
 int main() {
     setlocale(LC_ALL, "en_US.UTF-8");
@@ -5441,6 +5604,7 @@ int main() {
             (NULL == CU_add_test(pSuite, "testTicket99", testTicket99)) ||
             (NULL == CU_add_test(pSuite, "testTicket101", testTicket101)) || 
             (NULL == CU_add_test(pSuite, "testTicket110", testTicket110)) ||
+                       (NULL == CU_add_test(pSuite, "testSlice", testSlice)) ||
             (NULL == CU_add_test(pSuite, "testMetaInfo", testMetaInfo))
 
     ) {
index e44e7d1..de79205 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * File:   t3.c
- * Author: Adamansky Anton <anton@adamansky.com>
+ * Author: Adamansky Anton <adamansky@gmail.com>
  *
  * Created on Oct 26, 2012, 12:12:45 PM
  */
diff --git a/tcejdb/testejdb/t5.c b/tcejdb/testejdb/t5.c
new file mode 100644 (file)
index 0000000..23efb30
--- /dev/null
@@ -0,0 +1,15 @@
+
+#include "myconf.h"
+#include "ejdb_private.h"
+
+
+int main() {
+    setlocale(LC_ALL, "en_US.UTF-8");
+//     EJDB *jb = ejdbnew();
+//    if (!ejdbopen(jb, "dbt5", JBOWRITER | JBOCREAT)) {
+//             return 1;
+//     }
+//    ejdbclose(jb);
+//    ejdbdel(jb);
+    return 0;
+}
\ No newline at end of file