#59 #72
authoradam <adamansky@gmail.com>
Wed, 17 Jul 2013 06:26:17 +0000 (13:26 +0700)
committeradam <adamansky@gmail.com>
Wed, 17 Jul 2013 06:26:17 +0000 (13:26 +0700)
luaejdb/nbproject/configurations.xml
pyejdb/nbproject/configurations.xml
tcejdb/ejdb.c
tcejdb/ejdb.h
tcejdb/nbproject/configurations.xml
tcejdb/samples/sample1_mingw/nbproject/Makefile-Debug.mk
tcejdb/samples/sample1_mingw/nbproject/Makefile-Release.mk
tcejdb/samples/sample1_mingw/nbproject/Makefile-variables.mk
tcejdb/samples/sample1_mingw/nbproject/Package-Debug.bash
tcejdb/samples/sample1_mingw/nbproject/Package-Release.bash
tcejdb/testejdb/t4.c

index fc52988..dc6d92c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configurationDescriptor version="88">
+<configurationDescriptor version="89">
   <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
     <df root="." name="luaejdb">
       <in>luabson.c</in>
index ee03482..f0ccb2d 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configurationDescriptor version="88">
+<configurationDescriptor version="89">
   <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
     <df root="." name="pyejdb">
       <df name="src">
index 091083c..fcb212d 100644 (file)
@@ -134,6 +134,7 @@ static bool _exportcoll(EJCOLL *coll, const char *dpath, int flags, TCXSTR *log)
 static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags, TCXSTR *log);
 static EJCOLL* _createcollimpl(EJDB *jb, const char *colname, EJCOLLOPTS *opts);
 static bool _rmcollimpl(EJDB *jb, EJCOLL *coll, bool unlinkfile);
+static bool _setindeximpl(EJCOLL *jcoll, const char *fpath, int flags, bool nolock);
 
 
 extern const char *utf8proc_errmsg(ssize_t errcode);
@@ -524,158 +525,7 @@ void ejdbquerydel(EJQ *q) {
 
 /** Set index */
 bool ejdbsetindex(EJCOLL *jcoll, const char *fpath, int flags) {
-    assert(jcoll && fpath);
-    bool rv = true;
-    bson *imeta = NULL;
-    bson_iterator it;
-    int tcitype = 0; //TCDB index type
-    int oldiflags = 0; //Old index flags stored in meta
-    bool ibld = (flags & JBIDXREBLD);
-    if (ibld) {
-        flags &= ~JBIDXREBLD;
-    }
-    bool idrop = (flags & JBIDXDROP);
-    if (idrop) {
-        flags &= ~JBIDXDROP;
-    }
-    bool idropall = (flags & JBIDXDROPALL);
-    if (idropall) {
-        idrop = true;
-        flags &= ~JBIDXDROPALL;
-    }
-    bool iop = (flags & JBIDXOP);
-    if (iop) {
-        flags &= ~JBIDXOP;
-    }
-
-    char ipath[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
-    char ikey[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
-    int fpathlen = strlen(fpath);
-    if (fpathlen > BSON_MAX_FPATH_LEN) {
-        _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__);
-        rv = false;
-        goto finish;
-    }
-    memmove(ikey + 1, fpath, fpathlen + 1);
-    ikey[0] = 'i';
-    memmove(ipath + 1, fpath, fpathlen + 1);
-    ipath[0] = 's'; //defaulting to string index type
-
-    JBENSUREOPENLOCK(jcoll->jb, true, false);
-    imeta = _imetaidx(jcoll, fpath);
-    if (!imeta) {
-        if (idrop) { //Cannot drop/optimize not existent index;
-            JBUNLOCKMETHOD(jcoll->jb);
-            goto finish;
-        }
-        if (iop) {
-            iop = false; //New index will be created
-        }
-        imeta = bson_create();
-        bson_init(imeta);
-        bson_append_string(imeta, "ipath", fpath);
-        bson_append_int(imeta, "iflags", flags);
-        bson_finish(imeta);
-        rv = _metasetbson2(jcoll, ikey, imeta, false, false);
-        if (!rv) {
-            JBUNLOCKMETHOD(jcoll->jb);
-            goto finish;
-        }
-    } else {
-        if (bson_find(&it, imeta, "iflags") != BSON_EOO) {
-            oldiflags = bson_iterator_int(&it);
-        }
-        if (!idrop && oldiflags != flags) { //Update index meta
-            bson imetadelta;
-            bson_init(&imetadelta);
-            bson_append_int(&imetadelta, "iflags", (flags | oldiflags));
-            bson_finish(&imetadelta);
-            rv = _metasetbson2(jcoll, ikey, &imetadelta, true, true);
-            bson_destroy(&imetadelta);
-            if (!rv) {
-                JBUNLOCKMETHOD(jcoll->jb);
-                goto finish;
-            }
-        }
-    }
-    JBUNLOCKMETHOD(jcoll->jb);
-
-    if (idrop) {
-        tcitype = TDBITVOID;
-        if (idropall && oldiflags) {
-            flags = oldiflags; //Drop index only for existing types
-        }
-    } else if (iop) {
-        tcitype = TDBITOPT;
-        if (oldiflags) {
-            flags = oldiflags; //Optimize index for all existing types
-        }
-    }
-
-    if (!JBCLOCKMETHOD(jcoll, true)) {
-        rv = false;
-        goto finish;
-    }
-    _BSONIPATHROWLDR op;
-    op.icase = false;
-    op.jcoll = jcoll;
-
-    if (tcitype) {
-        if (flags & JBIDXSTR) {
-            ipath[0] = 's';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
-        }
-        if (flags & JBIDXISTR) {
-            ipath[0] = 'i';
-            op.icase = true;
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
-        }
-        if (rv && (flags & JBIDXNUM)) {
-            ipath[0] = 'n';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
-        }
-        if (rv && (flags & JBIDXARR)) {
-            ipath[0] = 'a';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
-        }
-        if (idrop) { //Update index meta on drop
-            oldiflags &= ~flags;
-            if (oldiflags) { //Index dropped only for some types
-                bson imetadelta;
-                bson_init(&imetadelta);
-                bson_append_int(&imetadelta, "iflags", oldiflags);
-                bson_finish(&imetadelta);
-                rv = _metasetbson2(jcoll, ikey, &imetadelta, true, true);
-                bson_destroy(&imetadelta);
-            } else { //Index dropped completely
-                rv = _metasetbson2(jcoll, ikey, NULL, false, false);
-            }
-        }
-    } else {
-        if ((flags & JBIDXSTR) && (ibld || !(oldiflags & JBIDXSTR))) {
-            ipath[0] = 's';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, &op);
-        }
-        if ((flags & JBIDXISTR) && (ibld || !(oldiflags & JBIDXISTR))) {
-            ipath[0] = 'i';
-            op.icase = true;
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, &op);
-        }
-        if (rv && (flags & JBIDXNUM) && (ibld || !(oldiflags & JBIDXNUM))) {
-            ipath[0] = 'n';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITDECIMAL, _bsonipathrowldr, &op);
-        }
-        if (rv && (flags & JBIDXARR) && (ibld || !(oldiflags & JBIDXARR))) {
-            ipath[0] = 'a';
-            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITTOKEN, _bsonipathrowldr, &op);
-        }
-    }
-    JBCUNLOCKMETHOD(jcoll);
-finish:
-    if (imeta) {
-        bson_del(imeta);
-    }
-    return rv;
+    return _setindeximpl(jcoll, fpath, flags, false);
 }
 
 uint32_t ejdbupdate(EJCOLL *jcoll, bson *qobj, bson *orqobjs, int orqobjsnum, bson *hints, TCXSTR *log) {
@@ -954,6 +804,9 @@ bool ejdbimport(EJDB *jb, const char *path, TCLIST *cnames, int flags, TCXSTR *l
     assert(jb && path);
     bool err = false;
     bool isdir = false;
+    if (flags == 0) {
+        flags |= JBIMPORTUPDATE;
+    }
     if (!tcstatfile(path, &isdir, NULL, NULL) || !isdir) {
         _ejdbsetecode2(jb, TCENOFILE, __FILE__, __LINE__, __func__, true);
         return false;
@@ -985,6 +838,172 @@ finish:
  * private features
  *************************************************************************************************/
 
+static bool _setindeximpl(EJCOLL *jcoll, const char *fpath, int flags, bool nolock) {
+    assert(jcoll && fpath);
+    bool rv = true;
+    bson *imeta = NULL;
+    bson_iterator it;
+    int tcitype = 0; //TCDB index type
+    int oldiflags = 0; //Old index flags stored in meta
+    bool ibld = (flags & JBIDXREBLD);
+    if (ibld) {
+        flags &= ~JBIDXREBLD;
+    }
+    bool idrop = (flags & JBIDXDROP);
+    if (idrop) {
+        flags &= ~JBIDXDROP;
+    }
+    bool idropall = (flags & JBIDXDROPALL);
+    if (idropall) {
+        idrop = true;
+        flags &= ~JBIDXDROPALL;
+    }
+    bool iop = (flags & JBIDXOP);
+    if (iop) {
+        flags &= ~JBIDXOP;
+    }
+    char ipath[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
+    char ikey[BSON_MAX_FPATH_LEN + 2]; //add 2 bytes for one char prefix and '\0'term
+    int fpathlen = strlen(fpath);
+    if (fpathlen > BSON_MAX_FPATH_LEN) {
+        _ejdbsetecode(jcoll->jb, JBEFPATHINVALID, __FILE__, __LINE__, __func__);
+        rv = false;
+        goto finish;
+    }
+    memmove(ikey + 1, fpath, fpathlen + 1);
+    ikey[0] = 'i';
+    memmove(ipath + 1, fpath, fpathlen + 1);
+    ipath[0] = 's'; //defaulting to string index type
+
+    if (!nolock) {
+        JBENSUREOPENLOCK(jcoll->jb, true, false);
+    }
+    imeta = _imetaidx(jcoll, fpath);
+    if (!imeta) {
+        if (idrop) { //Cannot drop/optimize not existent index;
+            if (!nolock) {
+                JBUNLOCKMETHOD(jcoll->jb);
+            }
+            goto finish;
+        }
+        if (iop) {
+            iop = false; //New index will be created
+        }
+        imeta = bson_create();
+        bson_init(imeta);
+        bson_append_string(imeta, "ipath", fpath);
+        bson_append_int(imeta, "iflags", flags);
+        bson_finish(imeta);
+        rv = _metasetbson2(jcoll, ikey, imeta, false, false);
+        if (!rv) {
+            if (!nolock) {
+                JBUNLOCKMETHOD(jcoll->jb);
+            }
+            goto finish;
+        }
+    } else {
+        if (bson_find(&it, imeta, "iflags") != BSON_EOO) {
+            oldiflags = bson_iterator_int(&it);
+        }
+        if (!idrop && oldiflags != flags) { //Update index meta
+            bson imetadelta;
+            bson_init(&imetadelta);
+            bson_append_int(&imetadelta, "iflags", (flags | oldiflags));
+            bson_finish(&imetadelta);
+            rv = _metasetbson2(jcoll, ikey, &imetadelta, true, true);
+            bson_destroy(&imetadelta);
+            if (!rv) {
+                if (!nolock) {
+                    JBUNLOCKMETHOD(jcoll->jb);
+                }
+                goto finish;
+            }
+        }
+    }
+    if (!nolock) {
+        JBUNLOCKMETHOD(jcoll->jb);
+    }
+    if (idrop) {
+        tcitype = TDBITVOID;
+        if (idropall && oldiflags) {
+            flags = oldiflags; //Drop index only for existing types
+        }
+    } else if (iop) {
+        tcitype = TDBITOPT;
+        if (oldiflags) {
+            flags = oldiflags; //Optimize index for all existing types
+        }
+    }
+
+    if (!nolock) {
+        if (!JBCLOCKMETHOD(jcoll, true)) {
+            rv = false;
+            goto finish;
+        }
+    }
+    _BSONIPATHROWLDR op;
+    op.icase = false;
+    op.jcoll = jcoll;
+    if (tcitype) {
+        if (flags & JBIDXSTR) {
+            ipath[0] = 's';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
+        }
+        if (flags & JBIDXISTR) {
+            ipath[0] = 'i';
+            op.icase = true;
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
+        }
+        if (rv && (flags & JBIDXNUM)) {
+            ipath[0] = 'n';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
+        }
+        if (rv && (flags & JBIDXARR)) {
+            ipath[0] = 'a';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, tcitype, _bsonipathrowldr, &op);
+        }
+        if (idrop) { //Update index meta on drop
+            oldiflags &= ~flags;
+            if (oldiflags) { //Index dropped only for some types
+                bson imetadelta;
+                bson_init(&imetadelta);
+                bson_append_int(&imetadelta, "iflags", oldiflags);
+                bson_finish(&imetadelta);
+                rv = _metasetbson2(jcoll, ikey, &imetadelta, true, true);
+                bson_destroy(&imetadelta);
+            } else { //Index dropped completely
+                rv = _metasetbson2(jcoll, ikey, NULL, false, false);
+            }
+        }
+    } else {
+        if ((flags & JBIDXSTR) && (ibld || !(oldiflags & JBIDXSTR))) {
+            ipath[0] = 's';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, &op);
+        }
+        if ((flags & JBIDXISTR) && (ibld || !(oldiflags & JBIDXISTR))) {
+            ipath[0] = 'i';
+            op.icase = true;
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITLEXICAL, _bsonipathrowldr, &op);
+        }
+        if (rv && (flags & JBIDXNUM) && (ibld || !(oldiflags & JBIDXNUM))) {
+            ipath[0] = 'n';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITDECIMAL, _bsonipathrowldr, &op);
+        }
+        if (rv && (flags & JBIDXARR) && (ibld || !(oldiflags & JBIDXARR))) {
+            ipath[0] = 'a';
+            rv = tctdbsetindexrldr(jcoll->tdb, ipath, TDBITTOKEN, _bsonipathrowldr, &op);
+        }
+    }
+    if (!nolock) {
+        JBCUNLOCKMETHOD(jcoll);
+    }
+finish:
+    if (imeta) {
+        bson_del(imeta);
+    }
+    return rv;
+}
+
 /**
  * In order to cleanup resources you need:
  *      _delcoldb(coll);
@@ -1054,7 +1073,7 @@ finish:
 
 static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags, TCXSTR *log) {
     if (log) {
-        tcxstrprintf(log, "\nImporting '%s'", bspath);
+        tcxstrprintf(log, "\n\nReading '%s'", bspath);
     }
     bool err = false;
     // /foo/bar.bson
@@ -1107,8 +1126,11 @@ static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags,
         }
         _ejdbsetecode2(jb, JBEEJSONPARSE, __FILE__, __LINE__, __func__, true);
     }
-    coll = ejdbgetcoll(jb, cname);
+    coll = _getcoll(jb, cname);
     if (coll && (flags & JBIMPORTREPLACE)) {
+        if (log) {
+            tcxstrprintf(log, "\nReplacing all data in '%s'", cname);
+        }
         err = !(_rmcollimpl(jb, coll, true));
         _delcoldb(coll);
         TCFREE(coll);
@@ -1121,6 +1143,7 @@ static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags,
         }
     }
     if (!coll) {
+        //Build collection options
         bson_iterator_init(&mbsonit, mbson);
         EJCOLLOPTS cops = {0};
         if (bson_find_fieldpath_value("opts", &mbsonit) == BSON_OBJECT) {
@@ -1148,6 +1171,41 @@ static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags,
             goto finish;
         }
     }
+
+    //Register collection indexes
+    bson_iterator_init(&mbsonit, mbson);
+    while ((bt = bson_iterator_next(&mbsonit)) != BSON_EOO) {
+        const char *key = bson_iterator_key(&mbsonit);
+        if (bt != BSON_OBJECT || strlen(key) < 2 || key[0] != 'i') {
+            continue;
+        }
+        char *ipath = NULL;
+        int iflags = 0;
+        bson_iterator sit;
+
+        bson_iterator_subiterator(&mbsonit, &sit);
+        bt = bson_find_fieldpath_value("ipath", &sit);
+        if (bt == BSON_STRING) {
+            ipath = strdup(bson_iterator_string(&sit));
+        }
+
+        bson_iterator_subiterator(&mbsonit, &sit);
+        bt = bson_find_fieldpath_value("iflags", &sit);
+        if (bt == BSON_INT || bt == BSON_LONG) {
+            iflags = bson_iterator_int(&sit);
+        }
+        if (ipath) {
+            if (!_setindeximpl(coll, ipath, iflags, true)) {
+                err = true;
+                if (log) {
+                    tcxstrprintf(log, "\nERROR: Error creating collection index. Collection: '%s' Field: '%s'", cname, ipath);
+                }
+                TCFREE(ipath);
+            }
+            TCFREE(ipath);
+        }
+    }
+
     int fd = open(bspath, O_RDONLY, TCFILEMODE);
     if (fd == -1) {
         err = true;
@@ -1161,34 +1219,45 @@ static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags,
         err = true;
         goto finish;
     }
-    int maxdocsiz = 0, docsiz = 0, numdocs = 0;
-    void *docbuf;
-    TCMALLOC(docbuf, 1);
+    int32_t maxdocsiz = 0, docsiz = 0, numdocs = 0;
+    char *docbuf;
+    TCMALLOC(docbuf, 4);
     while (true) {
-        numdocs = 0;
-        sp = read(fd, &docsiz, 4);
+        sp = read(fd, docbuf, 4);
         if (sp < 4) {
             break;
         }
+        memcpy(&docsiz, docbuf, 4);
         docsiz = TCHTOIL(docsiz);
         if (docsiz > EJDB_MAX_IMPORTED_BSON_SIZE) {
             err = true;
+            if (log) {
+                tcxstrprintf(log, "\nERROR: BSON document size: %d exceeds the maximum allowed size limit: %d for import operation",
+                        docsiz, EJDB_MAX_IMPORTED_BSON_SIZE);
+            }
             _ejdbsetecode2(jb, JBETOOBIGBSON, __FILE__, __LINE__, __func__, true);
             break;
         }
-        if (docsiz < 4) {
+        if (docsiz < 5) {
             break;
         }
         if (maxdocsiz < docsiz) {
             maxdocsiz = docsiz;
             TCREALLOC(docbuf, docbuf, maxdocsiz);
         }
-        sp = read(fd, docbuf, docsiz);
-        if (sp < docsiz) {
+        sp = read(fd, docbuf + 4, docsiz - 4);
+        if (sp < docsiz - 4) {
             break;
         }
         bson_oid_t oid;
-        if (!ejdbsavebson3(coll, docbuf, &oid, false)) {
+        bson savebs;
+        bson_init_with_data(&savebs, docbuf);
+        if (docbuf[docsiz - 1] != '\0' || savebs.err || !savebs.finished) {
+            err = true;
+            _ejdbsetecode(jb, JBEINVALIDBSON, __FILE__, __LINE__, __func__);
+            break;
+        }
+        if (!_ejdbsavebsonimpl(coll, &savebs, &oid, false)) {
             err = true;
             break;
         }
@@ -1197,11 +1266,11 @@ static bool _importcoll(EJDB *jb, const char *bspath, TCLIST *cnames, int flags,
     if (docbuf) {
         TCFREE(docbuf);
     }
-    if (!ejdbsyncoll(coll)) {
+    if (!tctdbsync(coll->tdb)) {
         err = true;
     }
     if (!err && log) {
-        tcxstrprintf(log, "\n%s imported %d entries", cname, numdocs);
+        tcxstrprintf(log, "\n%d objects imported into '%s'", numdocs, cname);
     }
     JBCUNLOCKMETHOD(coll);
 finish:
@@ -1214,7 +1283,7 @@ finish:
     tcxstrdel(xmetapath);
     TCFREE(cname);
     if (err && log) {
-         tcxstrprintf(log, "\nERROR: Importing data into: '%s' failed with error: '%s'", cname, ejdberrmsg(ejdbecode(jb)));
+        tcxstrprintf(log, "\nERROR: Importing data into: '%s' failed with error: '%s'", cname, (ejdbecode(jb) != 0) ? ejdberrmsg(ejdbecode(jb)) : "Unknown");
     }
     return !err;
 }
@@ -1296,6 +1365,8 @@ wfinish:
                 bson_del(bs);
             }
         }
+        tcmapdel(cmeta);
+
         bson_finish(&mbs);
         char *wbuf = NULL;
         int wsiz;
@@ -1326,6 +1397,7 @@ finish:
     tcxstrdel(colbuf);
     tcxstrdel(bsbuf);
     TCFREE(fpath);
+    TCFREE(fpathm);
     return !err;
 }
 
index a33dc17..749b1ee 100644 (file)
@@ -511,7 +511,7 @@ EJDB_EXPORT bson* ejdbmeta(EJDB *jb);
 /** Export/Import settings used in `ejdbexport()` and `ejdbimport()` functions. */
 enum {
     JBJSONEXPORT = 1, //If set json collection data will be exported as JSON files instead of BSON.
-    JBIMPORTUPDATE = 2, //Update existing collection entries with imported ones. Collection options are ignored.
+    JBIMPORTUPDATE = 2, //Update existing collection entries with imported ones. Collections will not be recreated and its options are ignored.
     JBIMPORTREPLACE = 3 //Recreate existing collections and replace all collection data with imported entries.
 };
 
index d7641ce..cdf8034 100644 (file)
@@ -49,7 +49,6 @@
       <in>tcftest.c</in>
       <in>tchdb.c</in>
       <in>tchdb.h</in>
-      <in>tchdb2.h</in>
       <in>tchmgr.c</in>
       <in>tchmttest.c</in>
       <in>tchtest.c</in>
@@ -96,7 +95,7 @@
           <buildCommandWorkingDir>.</buildCommandWorkingDir>
           <buildCommand>${MAKE} -f Makefile</buildCommand>
           <cleanCommand>${MAKE} -f Makefile clean</cleanCommand>
-          <executablePath>testejdb/t1</executablePath>
+          <executablePath>testejdb/t4</executablePath>
           <cTool>
             <preprocessorList>
               <Elem>_GNU_SOURCE=1</Elem>
       <item path="ejdb.c" ex="false" tool="0" flavor2="2">
         <cTool>
           <incDir>
-            <pElem>../../../../include</pElem>
             <pElem>.</pElem>
             <pElem>/usr/local/include</pElem>
           </incDir>
           <preprocessorList>
-            <Elem>_MYTESTS</Elem>
+            <Elem>EJDB_STATIC</Elem>
+            <Elem>_DEBUG</Elem>
+            <Elem>_TC_APPLIBS="-L/usr/local/lib -lpthread -lz -lrt -lm -lc "</Elem>
           </preprocessorList>
         </cTool>
       </item>
       </item>
       <item path="tchdb.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="tchdb2.h" ex="false" tool="3" flavor2="0">
-      </item>
       <item path="tchmgr.c" ex="false" tool="0" flavor2="0">
         <cTool>
           <incDir>
index dcf3ba5..60913e8 100644 (file)
@@ -21,8 +21,8 @@ FC=gfortran
 AS=as
 
 # Macros
-CND_PLATFORM=MinGW-Windows
-CND_DLIB_EXT=dll
+CND_PLATFORM=GNU-Linux-x86
+CND_DLIB_EXT=so
 CND_CONF=Debug
 CND_DISTDIR=dist
 CND_BUILDDIR=build
@@ -56,9 +56,9 @@ LDLIBSOPTIONS=-L../.. -ltcejdbdll
 
 # Build Targets
 .build-conf: ${BUILD_SUBPROJECTS}
-       "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe
+       "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
 
-${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe: ${OBJECTFILES}
+${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw: ${OBJECTFILES}
        ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
        ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw ${OBJECTFILES} ${LDLIBSOPTIONS}
 
@@ -73,7 +73,7 @@ ${OBJECTDIR}/main.o: main.c
 # Clean Targets
 .clean-conf: ${CLEAN_SUBPROJECTS}
        ${RM} -r ${CND_BUILDDIR}/${CND_CONF}
-       ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe
+       ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
 
 # Subprojects
 .clean-subprojects:
index 8210271..7a48b71 100644 (file)
@@ -21,8 +21,8 @@ FC=gfortran
 AS=as
 
 # Macros
-CND_PLATFORM=MinGW-Windows
-CND_DLIB_EXT=dll
+CND_PLATFORM=GNU-Linux-x86
+CND_DLIB_EXT=so
 CND_CONF=Release
 CND_DISTDIR=dist
 CND_BUILDDIR=build
@@ -56,9 +56,9 @@ LDLIBSOPTIONS=-L../.. -ltcejdbdll
 
 # Build Targets
 .build-conf: ${BUILD_SUBPROJECTS}
-       "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe
+       "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
 
-${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe: ${OBJECTFILES}
+${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw: ${OBJECTFILES}
        ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
        ${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw ${OBJECTFILES} ${LDLIBSOPTIONS}
 
@@ -73,7 +73,7 @@ ${OBJECTDIR}/main.o: main.c
 # Clean Targets
 .clean-conf: ${CLEAN_SUBPROJECTS}
        ${RM} -r ${CND_BUILDDIR}/${CND_CONF}
-       ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw.exe
+       ${RM} ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
 
 # Subprojects
 .clean-subprojects:
index 4741b40..69dfdf0 100644 (file)
@@ -7,21 +7,21 @@ CND_BASEDIR=`pwd`
 CND_BUILDDIR=build
 CND_DISTDIR=dist
 # Debug configuration
-CND_PLATFORM_Debug=MinGW-Windows
-CND_ARTIFACT_DIR_Debug=dist/Debug/MinGW-Windows
+CND_PLATFORM_Debug=GNU-Linux-x86
+CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-Linux-x86
 CND_ARTIFACT_NAME_Debug=sample1_mingw
-CND_ARTIFACT_PATH_Debug=dist/Debug/MinGW-Windows/sample1_mingw
-CND_PACKAGE_DIR_Debug=dist/Debug/MinGW-Windows/package
+CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-Linux-x86/sample1_mingw
+CND_PACKAGE_DIR_Debug=dist/Debug/GNU-Linux-x86/package
 CND_PACKAGE_NAME_Debug=sample1mingw.tar
-CND_PACKAGE_PATH_Debug=dist/Debug/MinGW-Windows/package/sample1mingw.tar
+CND_PACKAGE_PATH_Debug=dist/Debug/GNU-Linux-x86/package/sample1mingw.tar
 # Release configuration
-CND_PLATFORM_Release=MinGW-Windows
-CND_ARTIFACT_DIR_Release=dist/Release/MinGW-Windows
+CND_PLATFORM_Release=GNU-Linux-x86
+CND_ARTIFACT_DIR_Release=dist/Release/GNU-Linux-x86
 CND_ARTIFACT_NAME_Release=sample1_mingw
-CND_ARTIFACT_PATH_Release=dist/Release/MinGW-Windows/sample1_mingw
-CND_PACKAGE_DIR_Release=dist/Release/MinGW-Windows/package
+CND_ARTIFACT_PATH_Release=dist/Release/GNU-Linux-x86/sample1_mingw
+CND_PACKAGE_DIR_Release=dist/Release/GNU-Linux-x86/package
 CND_PACKAGE_NAME_Release=sample1mingw.tar
-CND_PACKAGE_PATH_Release=dist/Release/MinGW-Windows/package/sample1mingw.tar
+CND_PACKAGE_PATH_Release=dist/Release/GNU-Linux-x86/package/sample1mingw.tar
 #
 # include compiler specific variables
 #
index d31e01f..4f1be38 100644 (file)
@@ -6,10 +6,11 @@
 
 # Macros
 TOP=`pwd`
-CND_PLATFORM=MinGW-Windows
+CND_PLATFORM=GNU-Linux-x86
 CND_CONF=Debug
 CND_DISTDIR=dist
 CND_BUILDDIR=build
+CND_DLIB_EXT=so
 NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
 TMPDIRNAME=tmp-packaging
 OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
@@ -60,7 +61,7 @@ mkdir -p ${NBTMPDIR}
 # Copy files and create directories and links
 cd "${TOP}"
 makeDirectory "${NBTMPDIR}/sample1mingw/bin"
-copyFileToTmpDir "${OUTPUT_PATH}.exe" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}.exe" 0755
+copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
 # Generate tar file
index 29bdeae..9a5caa5 100644 (file)
@@ -6,10 +6,11 @@
 
 # Macros
 TOP=`pwd`
-CND_PLATFORM=MinGW-Windows
+CND_PLATFORM=GNU-Linux-x86
 CND_CONF=Release
 CND_DISTDIR=dist
 CND_BUILDDIR=build
+CND_DLIB_EXT=so
 NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
 TMPDIRNAME=tmp-packaging
 OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/sample1_mingw
@@ -60,7 +61,7 @@ mkdir -p ${NBTMPDIR}
 # Copy files and create directories and links
 cd "${TOP}"
 makeDirectory "${NBTMPDIR}/sample1mingw/bin"
-copyFileToTmpDir "${OUTPUT_PATH}.exe" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}.exe" 0755
+copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
 
 
 # Generate tar file
index 1229363..7abe7bf 100644 (file)
@@ -72,7 +72,6 @@ void testBSONExportImport() {
     ejdbsavebson(coll, &bv1, &oid);
     bson_destroy(&bv1);
 
-
     TCXSTR *log = tcxstrnew();
     TCLIST *cnames = tclistnew();
     tclistpush2(cnames, "col1");
@@ -84,22 +83,51 @@ void testBSONExportImport() {
         eprint(jb, __LINE__, "testBSONExportImport");
     }
     CU_ASSERT_TRUE(rv);
+
+
+    bson *ometa = ejdbmeta(jb);
+    CU_ASSERT_TRUE_FATAL(ometa != NULL);
+
     ejdbclose(jb);
     ejdbdel(jb);
 
     //Restore data:
 
     jb = ejdbnew();
-    CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC));
-
-    rv = ejdbimport(jb, "testBSONExportImport", cnames, 0, log);
+    CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT));
+    rv = ejdbimport(jb, "testBSONExportImport", cnames, JBIMPORTREPLACE, log);
     CU_ASSERT_TRUE(rv);
 
+    fprintf(stderr, "\n Import log: %s\n", TCXSTRPTR(log));
+
+    CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "Reading 'testBSONExportImport/col1.bson'"));
+    CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "Replacing all data in 'col1'"));
+    CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "1 objects imported into 'col1'"));
+    CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "2 objects imported into 'col2'"));
+
+    bson *nmeta = ejdbmeta(jb);
+    CU_ASSERT_TRUE_FATAL(nmeta != NULL);
+
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.name", strlen("collections.0.name")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.records", strlen("collections.0.records")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.name", strlen("collections.1.name")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.records", strlen("collections.1.records")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.buckets", strlen("collections.1.options.buckets")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.large", strlen("collections.1.options.large")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.field", strlen("collections.1.indexes.0.field")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.type", strlen("collections.1.indexes.0.type")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.records", strlen("collections.1.indexes.0.records")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.field", strlen("collections.1.indexes.1.field")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.type", strlen("collections.1.indexes.1.type")) == 0);
+    CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.records", strlen("collections.1.indexes.1.records")) == 0);
+
+    bson_del(ometa);
+    bson_del(nmeta);
+
     tcxstrdel(log);
     ejdbclose(jb);
     ejdbdel(jb);
     tclistdel(cnames);
-
 }
 
 int init_suite(void) {