From 62429ce310dc3d1cef3e0ca5e5ca2b87ff4fa545 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 2 Feb 2023 17:03:00 +0800 Subject: [PATCH] feat(nocodb): handle eq & neq cases for numerics --- .../db/sql-data-mapper/lib/sql/conditionV2.ts | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 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 a97e7a8c87..8a8c65ded4 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 @@ -274,8 +274,22 @@ const parseConditionV2 = async ( switch (filter.comparison_op) { case 'eq': if (qb?.client?.config?.client === 'mysql2') { - // mysql is case-insensitive, turn to case-sensitive - qb = qb.whereRaw('BINARY ?? = ?', [field, val]); + if ( + [ + UITypes.Duration, + UITypes.Currency, + UITypes.Percent, + UITypes.Number, + UITypes.Decimal, + UITypes.Rating, + UITypes.Rollup, + ].includes(column.uidt) + ) { + qb = qb.where(field, val); + } else { + // mysql is case-insensitive for strings, turn to case-sensitive + qb = qb.whereRaw('BINARY ?? = ?', [field, val]); + } } else { qb = qb.where(field, val); } @@ -283,12 +297,30 @@ const parseConditionV2 = async ( case 'neq': case 'not': if (qb?.client?.config?.client === 'mysql2') { - // mysql is case-insensitive, turn to case-sensitive - qb = qb.where((nestedQb) => { - nestedQb - .whereRaw('BINARY ?? != ?', [field, val]) - .orWhereNull(customWhereClause ? _val : _field); - }); + if ( + [ + UITypes.Duration, + UITypes.Currency, + UITypes.Percent, + UITypes.Number, + UITypes.Decimal, + UITypes.Rating, + UITypes.Rollup, + ].includes(column.uidt) + ) { + qb = qb.where((nestedQb) => { + nestedQb + .whereNot(field, val) + .orWhereNull(customWhereClause ? _val : _field); + }); + } else { + // mysql is case-insensitive for strings, turn to case-sensitive + qb = qb.where((nestedQb) => { + nestedQb + .whereRaw('BINARY ?? != ?', [field, val]) + .orWhereNull(customWhereClause ? _val : _field); + }); + } } else { qb = qb.where((nestedQb) => { nestedQb