Browse Source

fix: handle blank in IF function properly

pull/7299/head
Pranav C 9 months ago
parent
commit
27a31dc857
  1. 26
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
  2. 18
      packages/nocodb/src/db/functionMappings/commonFns.ts

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

@ -873,6 +873,32 @@ async function _formulaQueryBuilder(
);
}
// if operator is == or !=, then handle comparison with BLANK which should accept NULL and empty string
if (pt.operator === '==' || pt.operator === '!=') {
if (pt.left.callee?.name !== pt.left.callee?.name) {
// if left/right is BLANK, accept both NULL and empty string
['left', 'right'].forEach((operand) => {
if (
pt[operand].type === 'CallExpression' &&
pt[operand].callee.name === 'BLANK'
) {
return fn(
{
type: 'CallExpression',
arguments: [operand === 'left' ? pt.right : pt.left],
callee: {
type: 'Identifier',
name: 'ISBLANK',
},
},
alias,
prevBinaryOp,
);
}
});
}
}
if (pt.operator === '==') {
pt.operator = '=';
// if left/right is of different type, convert to string and compare

18
packages/nocodb/src/db/functionMappings/commonFns.ts

@ -321,4 +321,22 @@ export default {
),
};
},
ISBLANK: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
return {
builder: knex.raw(
`(${valueBuilder} IS NULL OR ${valueBuilder} = '')${colAlias}`,
),
};
},
ISNOTBLANK: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const { builder: valueBuilder } = await fn(pt.arguments[0]);
return {
builder: knex.raw(
`(${valueBuilder} IS NOT NULL AND ${valueBuilder} != '')${colAlias}`,
),
};
},
};

Loading…
Cancel
Save