Skip to content

Commit

Permalink
[se] Fix bug 71925
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaZotov committed Dec 13, 2024
1 parent e895698 commit ee704b3
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 15 deletions.
80 changes: 67 additions & 13 deletions cell/model/FormulaObjects/databaseFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ function (window, undefined) {

var previousWinArray;
var winElems = [];
let isContainsHeader = false;
for (var i = 1; i < conditionData.length; i++) {
previousWinArray = null;
for (var j = 0; j < conditionData[0].length; j++) {
Expand All @@ -334,6 +335,8 @@ function (window, undefined) {
continue;
}

isContainsHeader = true;

var winColumnArray = [];
for (var n = 0; n < databaseData.length; n++) {
if (previousWinArray && previousWinArray[n]) {
Expand All @@ -349,6 +352,9 @@ function (window, undefined) {
winElems[i - 1] = previousWinArray;
}

if ((!winElems.length || (winElems.length && winElems[0] && !winElems[0].length)) && isContainsHeader) {
return null;
}

var resArr = [];
var usuallyAddElems = [];
Expand All @@ -363,24 +369,36 @@ function (window, undefined) {
return new cError(cErrorType.wrong_value_type);
}

for (var i = 0; i < winElems.length; i++) {
for (var j in winElems[i]) {
if (winElems[i].hasOwnProperty(j)) {
if (true === usuallyAddElems[j] || cElementType.empty === needDataColumn[j].type) {
continue;
}
if (!isContainsHeader) {
//ms wins all
for (let i = 0; i < needDataColumn.length; i++) {
if (bIsGetObjArray) {
resArr.push(needDataColumn[i]);
} else {
resArr.push(needDataColumn[i].getValue());
}
}
} else {
for (let i = 0; i < winElems.length; i++) {
for (let j in winElems[i]) {
if (winElems[i].hasOwnProperty(j)) {
if (true === usuallyAddElems[j] || cElementType.empty === needDataColumn[j].type) {
continue;
}

if (bIsGetObjArray) {
resArr.push(needDataColumn[j]);
} else {
resArr.push(needDataColumn[j].getValue());
}
if (bIsGetObjArray) {
resArr.push(needDataColumn[j]);
} else {
resArr.push(needDataColumn[j].getValue());
}

usuallyAddElems[j] = true;
usuallyAddElems[j] = true;
}
}
}
}


return resArr.length ? resArr : new cError(cErrorType.division_by_zero);
}

Expand Down Expand Up @@ -416,6 +434,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cError(cErrorType.division_by_zero);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -467,6 +488,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2], null, true);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -517,6 +541,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2], true, true);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -559,6 +586,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cError(cErrorType.wrong_value_type);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -598,6 +628,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -638,6 +671,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -679,6 +715,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -727,6 +766,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cError(cErrorType.division_by_zero);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -783,6 +825,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2], true);
if (resArr === null) {
return new cError(cErrorType.division_by_zero);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -831,7 +876,7 @@ function (window, undefined) {
cDSUM.prototype.argumentsType = [argType.reference, argType.number, argType.text];
cDSUM.prototype.Calculate = function (arg) {

var oArguments = this._prepareArguments(arg, arguments[1], true, [cElementType.array, null, cElementType.array]);
var oArguments = this._prepareArguments(arg, arguments[1], true, [cElementType.array, null, cElementType.array], null, cErrorType.wrong_value_type);
var argClone = oArguments.args;

var argError;
Expand All @@ -840,6 +885,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2]);
if (resArr === null) {
return new cNumber(0);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -884,6 +932,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2], true);
if (resArr === null) {
return new cError(cErrorType.division_by_zero);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down Expand Up @@ -947,6 +998,9 @@ function (window, undefined) {
}

var resArr = getNeedValuesFromDataBase(argClone[0], argClone[1], argClone[2], true);
if (resArr === null) {
return new cError(cErrorType.division_by_zero);
}
if (cElementType.error === resArr.type) {
return resArr;
}
Expand Down
4 changes: 2 additions & 2 deletions cell/model/FormulaObjects/parserFormula.js
Original file line number Diff line number Diff line change
Expand Up @@ -3537,7 +3537,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara

return calculateFunc(argsArray);
};
cBaseFunction.prototype._prepareArguments = function (args, arg1, bAddFirstArrElem, typeArray, bFirstRangeElem) {
cBaseFunction.prototype._prepareArguments = function (args, arg1, bAddFirstArrElem, typeArray, bFirstRangeElem, notArrayError) {
var newArgs = [];
var indexArr = null;

Expand All @@ -3556,7 +3556,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
} else if (cElementType.error === arg.type) {
newArgs[i] = arg;
} else {
newArgs[i] = new cError(cErrorType.division_by_zero);
newArgs[i] = new cError(notArrayError ? notArrayError : cErrorType.division_by_zero);
}
} else if (cElementType.cellsRange === arg.type || cElementType.cellsRange3D === arg.type) {
newArgs[i] = bFirstRangeElem ? arg.getValueByRowCol(0,0) : arg.cross(arg1);
Expand Down
Loading

0 comments on commit ee704b3

Please sign in to comment.