diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index 17b0f098642ad4037d4766ecabd8cec8abe0a4fc..52b13ab7a7e3f548429593719ca7cec0d86f8905 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal if (resCode >= 0) { let fieldCount = cr._chandle.numFields(res2); if (fieldCount == 0) { - cr._chandle.freeResult(res2); //result will no longer be needed + } else { return res2; @@ -339,15 +339,14 @@ TDengineCursor.prototype.fetchall_a = function fetchall_a(result, options, callb // object which holds accumulated data in the data key. let asyncCallbackWrapper = function asyncCallbackWrapper(param2, result2, numOfRows2, rowData) { param2 = ref.readObject(param2); //return the object back from the pointer - // Keep fetching until now rows left. - if (numOfRows2 > 0) { + if (numOfRows2 > 0 && rowData.length != 0) { + // Keep fetching until now rows left. let buf2 = ref.alloc('Object'); param2.data.push(rowData); ref.writeObject(buf2, 0, param2); cr._chandle.fetch_rows_a(result2, asyncCallbackWrapper, buf2); } else { - let finalData = param2.data; let fields = cr._chandle.fetchFields_a(result2); let data = []; @@ -365,6 +364,7 @@ TDengineCursor.prototype.fetchall_a = function fetchall_a(result, options, callb } cr._chandle.freeResult(result2); // free result, avoid seg faults and mem leaks! callback(param2, result2, numOfRows2, {data:data,fields:fields}); + } } ref.writeObject(buf, 0, param); diff --git a/src/connector/nodejs/nodetaos/taosquery.js b/src/connector/nodejs/nodetaos/taosquery.js index bf6df473269eb976410022812bc56a623af5628f..eeede3ff6885e27c1d1c569a7a410f88109c9acd 100644 --- a/src/connector/nodejs/nodetaos/taosquery.js +++ b/src/connector/nodejs/nodetaos/taosquery.js @@ -69,11 +69,9 @@ TaosQuery.prototype.execute_a = async function execute_a(options = {}) { frej = reject; }); let asyncCallbackFetchall = async function(param, res, numOfRows, blocks) { - //param is expected to be the fetchPromise variable; - - //keep fetching until completion, possibly an issue though if (numOfRows > 0) { - frej("cursor.fetchall_a didn't fetch all data properly"); + // Likely a query like insert + fres(); } else { fres(new TaosResult(blocks.data, blocks.fields));