From: adam Date: Wed, 9 Jan 2013 10:26:21 +0000 (+0700) Subject: v1.0.45 #32 X-Git-Tag: v1.2.12~523 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73961fb45798b6c947e1a10c90d38cadce2a6665;p=platform%2Fupstream%2Fejdb.git v1.0.45 #32 --- diff --git a/Changelog b/Changelog index 42ed1d0..095bf69 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,8 @@ 2013-01-09 Anton Adamansky. + * Collection should be automatically created for $upsert queries (ticket #32) + - Release 1.0.45 + +2013-01-09 Anton Adamansky. * Fixed crash on sorting (ticket #31) - Release 1.0.44 diff --git a/node/ejdb_native.cc b/node/ejdb_native.cc index d50f72d..bea95cc 100644 --- a/node/ejdb_native.cc +++ b/node/ejdb_native.cc @@ -1374,13 +1374,25 @@ namespace ejdb { TCLIST *res = NULL; bson oqarrstack[8]; //max 8 $or bsons on stack BSONQCmdData *cmdata = task->cmd_data; + std::vector &bsons = cmdata->bsons; EJCOLL *coll = ejdbgetcoll(m_jb, cmdata->cname.c_str()); - if (!coll) { //No collection -> no results - cmdata->res = tclistnew2(1); - cmdata->count = 0; - return; + if (!coll) { + bson *qbs = bsons.front(); + bson_iterator it; + //If we are in $upsert mode so new collection will be created + if (qbs && bson_find(&it, qbs, "$upsert") == BSON_OBJECT) { + coll = ejdbcreatecoll(m_jb, cmdata->cname.c_str(), NULL); + if (!coll) { + task->cmd_ret = CMD_RET_ERROR; + task->cmd_ret_msg = _jb_error_msg(); + return; + } + } else { //No collection -> no results + cmdata->res = tclistnew2(1); + cmdata->count = 0; + return; + } } - std::vector &bsons = cmdata->bsons; int orsz = (int) bsons.size() - 2; //Minus main qry at begining and hints object at the end if (orsz < 0) orsz = 0; bson *oqarr = ((orsz <= 8) ? oqarrstack : (bson*) malloc(orsz * sizeof (bson))); diff --git a/node/nodejs b/node/nodejs index b00527f..1c9c627 160000 --- a/node/nodejs +++ b/node/nodejs @@ -1 +1 @@ -Subproject commit b00527fcf05c3d9fb5d5d790f9472906a59fe218 +Subproject commit 1c9c6277d5cfcaaac8569c0c8f7daa64292048a9 diff --git a/node/tests/t2.js b/node/tests/t2.js index bbb1a1f..918d810 100644 --- a/node/tests/t2.js +++ b/node/tests/t2.js @@ -422,6 +422,22 @@ module.exports.testTx1 = function(test) { }); }; +module.exports.testCreateCollectionOn$upsert = function(test) { + test.ok(jb); + test.ok(jb.isOpen()); + jb.update("upsertcoll", {foo : "bar", $upsert : {foo : "bar"}}, function(err, count) { + test.ifError(err); + test.equal(count, 1); + jb.findOne("upsertcoll", {foo : "bar"}, function(err, obj) { + test.ifError(err); + test.ok(obj); + test.equal(obj.foo, "bar"); + test.done(); + }); + }); +}; + + module.exports.testClose = function(test) { test.ok(jb); jb.close(); diff --git a/package.json b/package.json index 1bd6f52..722cc64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "ejdb", - "version" : "1.0.44", + "version" : "1.0.45", "main" : "node/ejdb.js", "homepage" : "http://ejdb.org", "description" : "EJDB - Embedded JSON Database engine", diff --git a/tcejdb/configure b/tcejdb/configure index ebcb713..d68a2b5 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.44. +# Generated by GNU Autoconf 2.69 for tcejdb 1.0.45. # # # 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.44' -PACKAGE_STRING='tcejdb 1.0.44' +PACKAGE_VERSION='1.0.45' +PACKAGE_STRING='tcejdb 1.0.45' 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.44 to adapt to many kinds of systems. +\`configure' configures tcejdb 1.0.45 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.44:";; + short | recursive ) echo "Configuration of tcejdb 1.0.45:";; 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.44 +tcejdb configure 1.0.45 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.44, which was +It was created by tcejdb $as_me 1.0.45, 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.44, which was +This file was extended by tcejdb $as_me 1.0.45, 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.44 +tcejdb config.status 1.0.45 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 0650566..40dfd6b 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.44) +AC_INIT(tcejdb, 1.0.45) # Package information MYLIBVER=9