Browse Source

fix: wrap with boolean function if type is boolean to avoid any issue while comparing

pull/7437/head
Pranav C 10 months ago
parent
commit
fe748106df
  1. 6
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  2. 28
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
  3. 2
      packages/nocodb/src/db/functionMappings/pg.ts

6
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -1594,7 +1594,11 @@ async function extractColumnIdentifierType({
res.dataType = FormulaDataTypes.STRING;
break;
case UITypes.Checkbox:
res.dataType = FormulaDataTypes.NUMERIC;
if (col.dt === 'boolean' || col.dt === 'bool') {
res.dataType = FormulaDataTypes.BOOLEAN;
} else {
res.dataType = FormulaDataTypes.NUMERIC;
}
break;
case UITypes.ID:
case UITypes.ForeignKey:

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

@ -889,20 +889,26 @@ async function _formulaQueryBuilder(
// if operator is == or !=, then handle comparison with BLANK which should accept NULL and empty string
if (pt.operator === '==' || pt.operator === '!=') {
for (const operand of ['left', 'right']) {
if (
pt[operand].dataType === FormulaDataTypes.BOOLEAN &&
pt[operand === 'left' ? 'right' : 'left'].dataType ===
FormulaDataTypes.NUMERIC
) {
pt[operand === 'left' ? 'right' : 'left'] = {
type: 'CallExpression',
arguments: [pt[operand === 'left' ? 'right' : 'left']],
callee: {
type: 'Identifier',
name: 'BOOLEAN',
},
dataType: FormulaDataTypes.BOOLEAN,
};
}
}
if (pt.left.callee?.name !== pt.right.callee?.name) {
// if left/right is BLANK, accept both NULL and empty string
for (const operand of ['left', 'right']) {
if (pt[operand].type === FormulaDataTypes.BOOLEAN) {
pt[operand] = {
type: 'CallExpression',
arguments: [pt[operand]],
callee: {
type: 'Identifier',
name: 'BOOLEAN',
},
};
}
if (
pt[operand].type === 'CallExpression' &&
pt[operand].callee.name === 'BLANK'

2
packages/nocodb/src/db/functionMappings/pg.ts

@ -351,7 +351,7 @@ END ${colAlias}`,
BOOLEAN: async (args: MapFnArgs) => {
return {
builder: args.knex.raw(
`(${(await args.fn(args.pt.arguments[0])).builder})::boolean ${
`(${(await args.fn(args.pt.arguments[0])).builder})::boolean${
args.colAlias
}`,
),

Loading…
Cancel
Save