Browse Source

fix(nocodb): condition nlike logic

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
625c59e2f5
  1. 36
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

36
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -297,20 +297,34 @@ const parseConditionV2 = async (
} }
break; break;
case 'nlike': case 'nlike':
if (column.uidt === UITypes.Formula) { if (!val) {
[field, val] = [val, field]; // val is empty -> include all values but empty strings
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%'); qb.whereNot(field, '');
qb.orWhereNull(field);
} else { } else {
val = val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`; if (column.uidt === UITypes.Formula) {
} [field, val] = [val, field];
qb.where((nestedQb) => { val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%');
if (qb?.client?.config?.client === 'pg') {
nestedQb.whereRaw('??::text not ilike ?', [field, val]);
} else { } else {
nestedQb.whereNot(field, 'like', val); val =
val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`;
} }
nestedQb.orWhereNull(field); qb.where((nestedQb) => {
}); if (qb?.client?.config?.client === 'pg') {
nestedQb.whereRaw('??::text not ilike ?', [field, val]);
} else {
nestedQb.whereNot(field, 'like', val);
}
if (val !== '%%') {
// if value is not empty, empty or null should be included
nestedQb.orWhere(field, '');
nestedQb.orWhereNull(field);
} else {
// if value is empty, then only null is included
nestedQb.orWhereNull(field);
}
});
}
break; break;
case 'allof': case 'allof':
case 'anyof': case 'anyof':

Loading…
Cancel
Save