From e114a7ec51379eac7dc043ae6ab015a40556f073 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 27 Dec 2012 16:45:17 +0700 Subject: [PATCH] #23 --- Changelog | 5 +++ package.json | 2 +- tcejdb/configure | 18 ++++----- tcejdb/configure.ac | 2 +- tcejdb/ejdb.c | 104 +++++++++++++++++++++++++------------------------- tcejdb/ejdb_private.h | 3 +- 6 files changed, 71 insertions(+), 63 deletions(-) diff --git a/Changelog b/Changelog index 68ffb7c..23a4895 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +2012-12-27 Anton Adamansky. + * Fixed crash when using update qry with single indexed field(ticket: #23) + - Release 1.0.36 + + 2012-12-26 Anton Adamansky. * Fixed crash on collection remove (ticket: #18) * Incorrect dropping of all field indexes (ticket: #16) diff --git a/package.json b/package.json index a258e2c..2bd5c0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "ejdb", - "version" : "1.0.35", + "version" : "1.0.36", "main" : "node/ejdb.js", "homepage" : "http://ejdb.org", "description" : "EJDB - Embedded JSON Database engine", diff --git a/tcejdb/configure b/tcejdb/configure index 7d32ccd..dfa9616 100755 --- a/tcejdb/configure +++ b/tcejdb/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for tcejdb 1.0.35. +# Generated by GNU Autoconf 2.69 for tcejdb 1.0.36. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='tcejdb' PACKAGE_TARNAME='tcejdb' -PACKAGE_VERSION='1.0.35' -PACKAGE_STRING='tcejdb 1.0.35' +PACKAGE_VERSION='1.0.36' +PACKAGE_STRING='tcejdb 1.0.36' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1257,7 +1257,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures tcejdb 1.0.35 to adapt to many kinds of systems. +\`configure' configures tcejdb 1.0.36 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1318,7 +1318,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of tcejdb 1.0.35:";; + short | recursive ) echo "Configuration of tcejdb 1.0.36:";; esac cat <<\_ACEOF @@ -1424,7 +1424,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -tcejdb configure 1.0.35 +tcejdb configure 1.0.36 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1722,7 +1722,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by tcejdb $as_me 1.0.35, which was +It was created by tcejdb $as_me 1.0.36, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -4870,7 +4870,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by tcejdb $as_me 1.0.35, which was +This file was extended by tcejdb $as_me 1.0.36, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4923,7 +4923,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -tcejdb config.status 1.0.35 +tcejdb config.status 1.0.36 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/tcejdb/configure.ac b/tcejdb/configure.ac index 5a19460..6a091d7 100644 --- a/tcejdb/configure.ac +++ b/tcejdb/configure.ac @@ -11,7 +11,7 @@ test -n "$CPPFLAGS" && MYCPPFLAGS="$CPPFLAGS $MYCPPFLAGS" test -n "$LDFLAGS" && MYLDFLAGS="$LDFLAGS $MYLDFLAGS" # Package name -AC_INIT(tcejdb, 1.0.35) +AC_INIT(tcejdb, 1.0.36) # Package information MYLIBVER=9 diff --git a/tcejdb/ejdb.c b/tcejdb/ejdb.c index 32fc55f..afa93ae 100644 --- a/tcejdb/ejdb.c +++ b/tcejdb/ejdb.c @@ -98,7 +98,7 @@ static bool _qrycondcheckstror(const char *vbuf, const TCLIST *tokens); static bool _qrybsvalmatch(const EJQF *qf, bson_iterator *it, bool expandarrays); static bool _qrybsmatch(EJQF *qf, const void *bsbuf, int bsbufsz); static bool _qryormatch(EJCOLL *jcoll, EJQ *ejq, const void *pkbuf, int pkbufsz, const void *bsbuf, int bsbufsz); -static bool _qryallcondsmatch(bool onlycount, int anum, EJCOLL *jcoll, EJQF **qfs, int qfsz, +static bool _qryallcondsmatch(EJQ *ejq, int anum, EJCOLL *jcoll, EJQF **qfs, int qfsz, const void *pkbuf, int pkbufsz, void **bsbuf, int *bsbufsz); static void _qrydup(const EJQ *src, EJQ *target, uint32_t qflags); static void _qrydel(EJQ *q, bool freequery); @@ -1380,6 +1380,7 @@ static bool _qryormatch(EJCOLL *jcoll, } bsbufsz = lbsbufsz; bsbuf = nbsbuf; + TCFREE(cbuf); } if (ejq->lastmatchedorqf && _qrybsmatch(ejq->lastmatchedorqf, bsbuf, bsbufsz)) { rv = true; @@ -1414,11 +1415,12 @@ finish: /** Caller must TCFREE(*bsbuf) if it return TRUE */ static bool _qryallcondsmatch( - bool onlycount, int anum, + EJQ *ejq, int anum, EJCOLL *jcoll, EJQF **qfs, int qfsz, const void *pkbuf, int pkbufsz, void **bsbuf, int *bsbufsz) { - if (onlycount && anum < 1) { + + if (!(ejq->flags & EJQUPDATING) && (ejq->flags & EJQONLYCOUNT) && anum < 1) { *bsbuf = NULL; *bsbufsz = 0; return true; @@ -1709,7 +1711,7 @@ static void _pushstripbson(TCLIST *rs, TCMAP *ifields, void *bsbuf, int bsbufsz) static bool _qryupdate(EJCOLL *jcoll, const EJQ *ejq, void *bsbuf, int bsbufsz, TCLIST *didxctx, TCXSTR *log) { assert(ejq->flags & EJQUPDATING); - assert(didxctx); + assert(bsbuf && didxctx); bool rv = true; bool update = false; @@ -1924,13 +1926,13 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int _qrydup(q, ejq, EJQINTERNAL); *outcount = 0; - bool onlycount = (qflags & JBQRYCOUNT); //quering only for result set count + if (qflags & JBQRYCOUNT) { + ejq->flags |= EJQONLYCOUNT; + }; bool all = false; //need all records - EJQF *mqf = NULL; //main indexed query condition if exists TCMAP *ifields = NULL; //field names included in result set - - TCLIST *res = onlycount ? NULL : tclistnew2(4096); + TCLIST *res = (ejq->flags & EJQONLYCOUNT) ? NULL : tclistnew2(4096); _qrypreprocess(jcoll, ejq, qflags, &mqf, &ifields); int anum = 0; //number of active conditions @@ -1982,7 +1984,7 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int } if (qf->orderseq) { ofsz++; - if (onlycount) { + if (ejq->flags & EJQONLYCOUNT) { qf->flags |= EJFORDERUSED; } } @@ -2006,7 +2008,7 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int for (int i = 0; i < ofsz; ++i) assert(ofs[i] != NULL); } - if (!onlycount && aofsz > 0 && (!midx || mqf->orderseq != 1)) { //Main index is not the main order field + if (!(ejq->flags & EJQONLYCOUNT) && aofsz > 0 && (!midx || mqf->orderseq != 1)) { //Main index is not the main order field all = true; //Need all records for ordering for some other fields } @@ -2014,7 +2016,7 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int tcxstrprintf(log, "UPDATING MODE: %s\n", (ejq->flags & EJQUPDATING) ? "YES" : "NO"); tcxstrprintf(log, "MAX: %u\n", max); tcxstrprintf(log, "SKIP: %u\n", skip); - tcxstrprintf(log, "COUNT ONLY: %s\n", onlycount ? "YES" : "NO"); + tcxstrprintf(log, "COUNT ONLY: %s\n", (ejq->flags & EJQONLYCOUNT) ? "YES" : "NO"); tcxstrprintf(log, "MAIN IDX: '%s'\n", midx ? midx->name : "NONE"); tcxstrprintf(log, "ORDER FIELDS: %d\n", ofsz); tcxstrprintf(log, "ACTIVE CONDITIONS: %d\n", anum); @@ -2034,12 +2036,12 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int tcxstrprintf(log, "MAIN IDX TCOP: %d\n", mqf->tcop); } -#define JBQREGREC(_bsbuf, _bsbufsz) \ +#define JBQREGREC(_pkbuf, _pkbufsz, _bsbuf, _bsbufsz) \ ++count; \ if (ejq->flags & EJQUPDATING) { \ _qryupdate(jcoll, ejq, (_bsbuf), (_bsbufsz), didxctx, log); \ } \ - if (!onlycount && (all || count > skip)) { \ + if (!(ejq->flags & EJQONLYCOUNT) && (all || count > skip)) { \ if (ifields) {\ _pushstripbson(res, ifields, (_bsbuf), (_bsbufsz)); \ } else { \ @@ -2064,13 +2066,13 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int do { bson_oid_t oid; bson_oid_from_string(&oid, mqf->expr); - void *cdata = tchdbget(jcoll->tdb->hdb, &oid, sizeof (oid), &bsbufsz); - if (!cdata) { + void *cbuf = tchdbget(jcoll->tdb->hdb, &oid, sizeof (oid), &bsbufsz); + if (!cbuf) { break; } - bsbuf = tcmaploadone(cdata, bsbufsz, JDBCOLBSON, JDBCOLBSONL, &bsbufsz); + bsbuf = tcmaploadone(cbuf, bsbufsz, JDBCOLBSON, JDBCOLBSONL, &bsbufsz); if (!bsbuf) { - TCFREE(cdata); + TCFREE(cbuf); break; } bool matched = true; @@ -2084,11 +2086,11 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int } } if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, &oid, sizeof (oid), bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(&oid, sizeof (oid), bsbuf, bsbufsz); } else { TCFREE(bsbuf); } - TCFREE(cdata); + TCFREE(cbuf); } while (false); } else if (mqf->tcop == TDBQCSTROREQ) { TCLIST *tokens = mqf->exprlist; @@ -2130,7 +2132,7 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int } } if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, &oid, sizeof (oid), bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(&oid, sizeof (oid), bsbuf, bsbufsz); } else { TCFREE(bsbuf); } @@ -2149,8 +2151,8 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int while ((all || count < max) && (kbuf = tcbdbcurkey3(cur, &kbufsz)) != NULL) { if (trim) kbufsz -= 3; vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz)) { - JBQREGREC(bsbuf, bsbufsz); + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz)) { + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } if (mqf->order >= 0) { tcbdbcurnext(cur); @@ -2169,9 +2171,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (trim) kbufsz -= 3; if (kbufsz == exprsz && !memcmp(kbuf, expr, exprsz)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2189,9 +2191,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (trim) kbufsz -= 3; if (kbufsz >= exprsz && !memcmp(kbuf, expr, exprsz)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2226,9 +2228,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (trim) kbufsz -= 3; if (kbufsz >= tsiz && !memcmp(kbuf, token, tsiz)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2264,9 +2266,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (trim) kbufsz -= 3; if (kbufsz == tsiz && !memcmp(kbuf, token, tsiz)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2286,9 +2288,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int while ((all || count < max) && (kbuf = tcbdbcurkey3(cur, &kbufsz)) != NULL) { if (_nucmp(&num, kbuf, mqf->ftype) == 0) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2313,9 +2315,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (cmp < 0) break; if (cmp > 0 || (mqf->tcop == TDBQCNUMGE && cmp >= 0)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } tcbdbcurprev(cur); @@ -2328,9 +2330,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int int cmp = _nucmp2(&knum, &xnum, mqf->ftype); if (cmp > 0 || (mqf->tcop == TDBQCNUMGE && cmp >= 0)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } tcbdbcurnext(cur); @@ -2354,9 +2356,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int if (cmp > 0) break; if (cmp < 0 || (cmp <= 0 && mqf->tcop == TDBQCNUMLE)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } tcbdbcurnext(cur); @@ -2369,9 +2371,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int int cmp = _nucmp2(&knum, &xnum, mqf->ftype); if (cmp < 0 || (cmp <= 0 && mqf->tcop == TDBQCNUMLE)) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } tcbdbcurprev(cur); @@ -2400,14 +2402,14 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int while ((all || count < max) && (kbuf = tcbdbcurkey3(cur, &kbufsz)) != NULL) { if (tctdbatof(kbuf) > upper) break; vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } tcbdbcurnext(cur); } tcbdbcurdel(cur); - if (!all && !onlycount && mqf->order < 0 && (mqf->flags & EJFORDERUSED)) { //DESC + if (!all && !(ejq->flags & EJQONLYCOUNT) && mqf->order < 0 && (mqf->flags & EJFORDERUSED)) { //DESC tclistinvert(res); } } else if (mqf->tcop == TDBQCNUMOREQ) { /* number is equal to at least one token in */ @@ -2437,9 +2439,9 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int while ((all || count < max) && (kbuf = tcbdbcurkey3(cur, &kbufsz)) != NULL) { if (tctdbatof(kbuf) == xnum) { vbuf = tcbdbcurval3(cur, &vbufsz); - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, vbuf, vbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, vbuf, vbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(vbuf, vbufsz, bsbuf, bsbufsz); } } else { break; @@ -2474,15 +2476,15 @@ static TCLIST* _qryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *outcount, int TCMAP *tres = tctdbidxgetbytokens(jcoll->tdb, midx, tokens, mqf->tcop, log); tcmapiterinit(tres); while ((all || count < max) && (kbuf = tcmapiternext(tres, &kbufsz)) != NULL) { - if (_qryallcondsmatch(onlycount, anum, jcoll, qfs, qfsz, kbuf, kbufsz, &bsbuf, &bsbufsz) && + if (_qryallcondsmatch(ejq, anum, jcoll, qfs, qfsz, kbuf, kbufsz, &bsbuf, &bsbufsz) && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, kbuf, kbufsz, bsbuf, bsbufsz))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(kbuf, kbufsz, bsbuf, bsbufsz); } } tcmapdel(tres); } - if (onlycount) { + if (ejq->flags & EJQONLYCOUNT) { goto finish; } else { goto sorting; @@ -2524,12 +2526,12 @@ fullscan: /* Full scan */ if (matched && (ejq->orqobjsnum == 0 || _qryormatch(jcoll, ejq, TCXSTRPTR(skbuf), TCXSTRSIZE(skbuf), bsbuf, bsbufsz))) { if (updkeys) { //we are in updating mode if (tcmapputkeep(updkeys, TCXSTRPTR(skbuf), TCXSTRSIZE(skbuf), &yes, sizeof (yes))) { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(TCXSTRPTR(skbuf), TCXSTRSIZE(skbuf), bsbuf, bsbufsz); } else { TCFREE(bsbuf); } } else { - JBQREGREC(bsbuf, bsbufsz); + JBQREGREC(TCXSTRPTR(skbuf), TCXSTRSIZE(skbuf), bsbuf, bsbufsz); } } else { TCFREE(bsbuf); @@ -2588,7 +2590,7 @@ finish: if (log) { tcxstrprintf(log, "RS COUNT: %d\n", count); tcxstrprintf(log, "RS SIZE: %d\n", (res ? TCLISTNUM(res) : 0)); - tcxstrprintf(log, "FINAL SORTING: %s\n", (onlycount || aofsz <= 0) ? "NO" : "YES"); + tcxstrprintf(log, "FINAL SORTING: %s\n", ((ejq->flags & EJQONLYCOUNT) || aofsz <= 0) ? "NO" : "YES"); } //Apply deffered index changes diff --git a/tcejdb/ejdb_private.h b/tcejdb/ejdb_private.h index 75606ab..1cf5cb8 100644 --- a/tcejdb/ejdb_private.h +++ b/tcejdb/ejdb_private.h @@ -64,7 +64,8 @@ enum { /**> Query field flags */ enum { /**> Query flags */ EJQINTERNAL = 1, /**> Internal query object used in _ejdbqryexecute */ EJQUPDATING = 1 << 1, /**> Query in updating mode */ - EJQDROPALL = 1 << 2 /**> Drop bson object if matched */ + EJQDROPALL = 1 << 2, /**> Drop bson object if matched */ + EJQONLYCOUNT = 1 << 3 /**> Only count mode */ }; struct EJQF { /**> Matching field and status */ -- 2.7.4