From 838411682cc2f694ba14aa081386aa4722451e5a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 16 Feb 2023 15:46:40 +0800 Subject: [PATCH] fix(nocodb): filter condition logic --- .../db/sql-data-mapper/lib/sql/conditionV2.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts index 4238c5bb93..901e358d8f 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts @@ -308,8 +308,8 @@ const parseConditionV2 = async ( } else { qb = qb.where(field, val); } - if (isNumericCol(column.uidt) && val === 0) { - // unset number is considered as NULL + if (column.uidt === UITypes.Rating && val === 0) { + // unset rating is considered as NULL qb = qb.orWhereNull(field); } break; @@ -331,8 +331,8 @@ const parseConditionV2 = async ( .whereNot(field, val) .orWhereNull(customWhereClause ? _val : _field); }); - } else if (isNumericCol(column.uidt)) { - // unset number is considered as NULL + } else if (column.uidt === UITypes.Rating) { + // unset rating is considered as NULL if (val === 0) { qb = qb.whereNot(field, val).whereNotNull(field); } else { @@ -342,7 +342,7 @@ const parseConditionV2 = async ( // mysql is case-insensitive for strings, turn to case-sensitive qb = qb.where((nestedQb) => { nestedQb.whereRaw('BINARY ?? != ?', [field, val]); - if (!isNumericCol(column.uidt)) { + if (column.uidt !== UITypes.Rating) { nestedQb.orWhereNull(customWhereClause ? _val : _field); } }); @@ -463,7 +463,8 @@ const parseConditionV2 = async ( case 'gt': const gt_op = customWhereClause ? '<' : '>'; qb = qb.where(field, gt_op, val); - if (isNumericCol(column.uidt)) { + if (column.uidt === UITypes.Rating) { + // unset rating is considered as NULL if (gt_op === '<' && val > 0) { qb = qb.orWhereNull(field); } @@ -473,7 +474,8 @@ const parseConditionV2 = async ( case 'gte': const ge_op = customWhereClause ? '<=' : '>='; qb = qb.where(field, ge_op, val); - if (isNumericCol(column.uidt)) { + if (column.uidt === UITypes.Rating) { + // unset rating is considered as NULL if (ge_op === '<=' || (ge_op === '>=' && val === 0)) { qb = qb.orWhereNull(field); } @@ -518,7 +520,8 @@ const parseConditionV2 = async ( case 'lt': const lt_op = customWhereClause ? '>' : '<'; qb = qb.where(field, lt_op, val); - if (isNumericCol(column.uidt)) { + if (column.uidt === UITypes.Rating) { + // unset number is considered as NULL if (lt_op === '<' && val > 0) { qb = qb.orWhereNull(field); } @@ -528,7 +531,8 @@ const parseConditionV2 = async ( case 'lte': const le_op = customWhereClause ? '>=' : '<='; qb = qb.where(field, le_op, val); - if (isNumericCol(column.uidt)) { + if (column.uidt === UITypes.Rating) { + // unset number is considered as NULL if (le_op === '<=' || (le_op === '>=' && val === 0)) { qb = qb.orWhereNull(field); }