Code pruning, fix bug with infinite row async fetching when using insert

This commit is contained in:
StoneT2000 2019-08-03 20:39:47 -07:00
parent bd526d2216
commit 3ab2d86aef
2 changed files with 6 additions and 8 deletions

View File

@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal
if (resCode >= 0) { if (resCode >= 0) {
let fieldCount = cr._chandle.numFields(res2); let fieldCount = cr._chandle.numFields(res2);
if (fieldCount == 0) { if (fieldCount == 0) {
cr._chandle.freeResult(res2); //result will no longer be needed
} }
else { else {
return res2; 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. // object which holds accumulated data in the data key.
let asyncCallbackWrapper = function asyncCallbackWrapper(param2, result2, numOfRows2, rowData) { let asyncCallbackWrapper = function asyncCallbackWrapper(param2, result2, numOfRows2, rowData) {
param2 = ref.readObject(param2); //return the object back from the pointer param2 = ref.readObject(param2); //return the object back from the pointer
if (numOfRows2 > 0 && rowData.length != 0) {
// Keep fetching until now rows left. // Keep fetching until now rows left.
if (numOfRows2 > 0) {
let buf2 = ref.alloc('Object'); let buf2 = ref.alloc('Object');
param2.data.push(rowData); param2.data.push(rowData);
ref.writeObject(buf2, 0, param2); ref.writeObject(buf2, 0, param2);
cr._chandle.fetch_rows_a(result2, asyncCallbackWrapper, buf2); cr._chandle.fetch_rows_a(result2, asyncCallbackWrapper, buf2);
} }
else { else {
let finalData = param2.data; let finalData = param2.data;
let fields = cr._chandle.fetchFields_a(result2); let fields = cr._chandle.fetchFields_a(result2);
let data = []; 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! cr._chandle.freeResult(result2); // free result, avoid seg faults and mem leaks!
callback(param2, result2, numOfRows2, {data:data,fields:fields}); callback(param2, result2, numOfRows2, {data:data,fields:fields});
} }
} }
ref.writeObject(buf, 0, param); ref.writeObject(buf, 0, param);

View File

@ -69,11 +69,9 @@ TaosQuery.prototype.execute_a = async function execute_a(options = {}) {
frej = reject; frej = reject;
}); });
let asyncCallbackFetchall = async function(param, res, numOfRows, blocks) { 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) { if (numOfRows > 0) {
frej("cursor.fetchall_a didn't fetch all data properly"); // Likely a query like insert
fres();
} }
else { else {
fres(new TaosResult(blocks.data, blocks.fields)); fres(new TaosResult(blocks.data, blocks.fields));