Mercurial > hg > audiodb
changeset 719:e3f1cf653c30
wooo! direct insert works! at least for the rather limited cases I've tests.
Bad news is that I seem to have found a rather nasty bug in the query code I wrote back in september.
(segfaults around line 471 if the query returns no results...)
author | map01bf |
---|---|
date | Fri, 25 Jun 2010 09:08:56 +0000 |
parents | 14568e432e73 |
children | 2fad8cfdb2d8 |
files | bindings/python/pyadb.py bindings/python/pyadbmodule.c |
diffstat | 2 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/bindings/python/pyadb.py Thu Jun 24 16:38:32 2010 +0000 +++ b/bindings/python/pyadb.py Fri Jun 25 09:08:56 2010 +0000 @@ -78,7 +78,7 @@ args["key"]=str(key) if featFile: if not _pyadb._pyadb_insertFromFile(**args): - raise(RuntimeError, "Insertion from file failed for an unknown reason.") + raise RuntimeError("Insertion from file failed for an unknown reason.") else: self._updateDBAttributes() return @@ -87,8 +87,9 @@ args["nDim"], args["nVect"] = args["features"].shape args["features"] = args["features"].flatten() print "args: " + str(args) - if not _pyadb._pyadb_insertFromArray(**args): - raise(RuntimeError, "Direct data insertion failed for an unknown reason.") + ok = _pyadb._pyadb_insertFromArray(**args) + if not (ok==0): + raise RuntimeError("Direct data insertion failed for an unknown reason. err code = %i"%ok) else: self._updateDBAttributes() return
--- a/bindings/python/pyadbmodule.c Thu Jun 24 16:38:32 2010 +0000 +++ b/bindings/python/pyadbmodule.c Fri Jun 25 09:08:56 2010 +0000 @@ -211,30 +211,34 @@ //verify that the data to be inserted is the correct size for the database. ins = (adb_datum_t *)malloc(sizeof(adb_datum_t)); - if (!PyArray_AsCArray(&features, &(ins->data), dims, 1, descr)){ + if (PyArray_AsCArray(&features, &(ins->data), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); return NULL; } if (power){ - if (!PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ + if (PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); return NULL; } + }else{ + ins->power=NULL; } if (times){ - if (!PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ + if (PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); return NULL; } + }else{ + ins->times=NULL; } ins->key = key; ins->nvectors = (uint32_t)nVect; ins->dim = (uint32_t)nDims; //printf("features::%s\npower::%s\nkey::%s\ntimes::%s\n", ins->features, ins->power, ins->key, ins->times); ok = audiodb_insert_datum(current_db, ins);//(current_db, ins); - return PyBool_FromLong(ok-1); + return PyInt_FromLong(ok); }