Browse Source

fix(nocodb): filter condition logic

pull/4969/head
Wing-Kam Wong 2 years ago
parent
commit
838411682c
  1. 22
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

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

@ -308,8 +308,8 @@ const parseConditionV2 = async (
} else { } else {
qb = qb.where(field, val); qb = qb.where(field, val);
} }
if (isNumericCol(column.uidt) && val === 0) { if (column.uidt === UITypes.Rating && val === 0) {
// unset number is considered as NULL // unset rating is considered as NULL
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
break; break;
@ -331,8 +331,8 @@ const parseConditionV2 = async (
.whereNot(field, val) .whereNot(field, val)
.orWhereNull(customWhereClause ? _val : _field); .orWhereNull(customWhereClause ? _val : _field);
}); });
} else if (isNumericCol(column.uidt)) { } else if (column.uidt === UITypes.Rating) {
// unset number is considered as NULL // unset rating is considered as NULL
if (val === 0) { if (val === 0) {
qb = qb.whereNot(field, val).whereNotNull(field); qb = qb.whereNot(field, val).whereNotNull(field);
} else { } else {
@ -342,7 +342,7 @@ const parseConditionV2 = async (
// mysql is case-insensitive for strings, turn to case-sensitive // mysql is case-insensitive for strings, turn to case-sensitive
qb = qb.where((nestedQb) => { qb = qb.where((nestedQb) => {
nestedQb.whereRaw('BINARY ?? != ?', [field, val]); nestedQb.whereRaw('BINARY ?? != ?', [field, val]);
if (!isNumericCol(column.uidt)) { if (column.uidt !== UITypes.Rating) {
nestedQb.orWhereNull(customWhereClause ? _val : _field); nestedQb.orWhereNull(customWhereClause ? _val : _field);
} }
}); });
@ -463,7 +463,8 @@ const parseConditionV2 = async (
case 'gt': case 'gt':
const gt_op = customWhereClause ? '<' : '>'; const gt_op = customWhereClause ? '<' : '>';
qb = qb.where(field, gt_op, val); 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) { if (gt_op === '<' && val > 0) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -473,7 +474,8 @@ const parseConditionV2 = async (
case 'gte': case 'gte':
const ge_op = customWhereClause ? '<=' : '>='; const ge_op = customWhereClause ? '<=' : '>=';
qb = qb.where(field, ge_op, val); 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)) { if (ge_op === '<=' || (ge_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -518,7 +520,8 @@ const parseConditionV2 = async (
case 'lt': case 'lt':
const lt_op = customWhereClause ? '>' : '<'; const lt_op = customWhereClause ? '>' : '<';
qb = qb.where(field, lt_op, val); 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) { if (lt_op === '<' && val > 0) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -528,7 +531,8 @@ const parseConditionV2 = async (
case 'lte': case 'lte':
const le_op = customWhereClause ? '>=' : '<='; const le_op = customWhereClause ? '>=' : '<=';
qb = qb.where(field, le_op, val); 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)) { if (le_op === '<=' || (le_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }

Loading…
Cancel
Save