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. 4
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  2. 18
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
  3. 2
      packages/nocodb/src/db/functionMappings/pg.ts

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

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

18
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 operator is == or !=, then handle comparison with BLANK which should accept NULL and empty string
if (pt.operator === '==' || pt.operator === '!=') { if (pt.operator === '==' || pt.operator === '!=') {
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']) { for (const operand of ['left', 'right']) {
if (pt[operand].type === FormulaDataTypes.BOOLEAN) { if (
pt[operand] = { pt[operand].dataType === FormulaDataTypes.BOOLEAN &&
pt[operand === 'left' ? 'right' : 'left'].dataType ===
FormulaDataTypes.NUMERIC
) {
pt[operand === 'left' ? 'right' : 'left'] = {
type: 'CallExpression', type: 'CallExpression',
arguments: [pt[operand]], arguments: [pt[operand === 'left' ? 'right' : 'left']],
callee: { callee: {
type: 'Identifier', type: 'Identifier',
name: 'BOOLEAN', 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 ( if (
pt[operand].type === 'CallExpression' && pt[operand].type === 'CallExpression' &&
pt[operand].callee.name === 'BLANK' pt[operand].callee.name === 'BLANK'

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

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

Loading…
Cancel
Save