Browse Source

feat: convert to string if left and right operand datatypes are different(`==`)

pull/7268/head
Pranav C 11 months ago
parent
commit
d730d40125
  1. 26
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

26
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -1,5 +1,6 @@
import jsep from 'jsep';
import {
FormulaDataTypes,
jsepCurlyHook,
UITypes,
validateFormulaAndExtractTreeWithType,
@ -21,7 +22,6 @@ import {
validateDateWithUnknownFormat,
} from '~/helpers/formulaFnHelper';
import FormulaColumn from '~/models/FormulaColumn';
import { Source } from '~/models';
const logger = new Logger('FormulaQueryBuilderv2');
@ -835,6 +835,30 @@ async function _formulaQueryBuilder(
if (pt.operator === '==') {
pt.operator = '=';
// if left/right is of different type, convert to string and compare
if (
pt.left.dataType !== pt.right.dataType &&
[pt.left.dataType, pt.right.dataType].every(
(type) => type !== FormulaDataTypes.NULL,
)
) {
pt.left = {
type: 'CallExpression',
arguments: [pt.left],
callee: {
type: 'Identifier',
name: 'STRING',
},
};
pt.right = {
type: 'CallExpression',
arguments: [pt.right],
callee: {
type: 'Identifier',
name: 'STRING',
},
};
}
}
if (pt.operator === '/') {

Loading…
Cancel
Save