From 0cf9f4d4e4e6c27f3bec05d31c67756bf38a7111 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 1 Feb 2023 18:13:04 +0800 Subject: [PATCH] fix(nocodb): condition like logic --- .../db/sql-data-mapper/lib/sql/conditionV2.ts | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 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 5c96d1a36a..9281e4ceb1 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 @@ -284,21 +284,28 @@ const parseConditionV2 = async ( }); break; case 'like': - if (column.uidt === UITypes.Formula) { - [field, val] = [val, field]; - val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%'); - } else { - val = val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`; - } - if (qb?.client?.config?.client === 'pg') { - qb = qb.whereRaw('??::text ilike ?', [field, val]); + if (!val) { + // val is empty -> all values including empty strings but NULL + qb.where(field, ''); + qb.orWhereNotNull(field); } else { - qb = qb.where(field, 'like', val); + if (column.uidt === UITypes.Formula) { + [field, val] = [val, field]; + val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%'); + } else { + val = + val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`; + } + if (qb?.client?.config?.client === 'pg') { + qb = qb.whereRaw('??::text ilike ?', [field, val]); + } else { + qb = qb.where(field, 'like', val); + } } break; case 'nlike': if (!val) { - // val is empty -> include all values but empty strings + // val is empty -> all values including NULL but empty strings qb.whereNot(field, ''); qb.orWhereNull(field); } else {