Browse Source

fix(nocodb): numeric filter logic

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

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

@ -281,7 +281,7 @@ const parseConditionV2 = async (
return; return;
} }
if (isNumericCol(column.uidt)) { if (isNumericCol(column.uidt) && typeof val === 'string') {
// convert to number // convert to number
val = +val; val = +val;
} }
@ -308,8 +308,8 @@ const parseConditionV2 = async (
} else { } else {
qb = qb.where(field, val); qb = qb.where(field, val);
} }
if (column.uidt === UITypes.Rating && val === 0) { if (isNumericCol(column.uidt) && val === 0) {
// unset rating is considered as NULL // unset number 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 (column.uidt === UITypes.Rating) { } else if (isNumericCol(column.uidt)) {
// unset rating is considered as NULL // unset number 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 (column.uidt !== UITypes.Rating) { if (!isNumericCol(column.uidt)) {
nestedQb.orWhereNull(customWhereClause ? _val : _field); nestedQb.orWhereNull(customWhereClause ? _val : _field);
} }
}); });
@ -463,7 +463,7 @@ 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 (column.uidt === UITypes.Rating) { if (isNumericCol(column.uidt)) {
if (gt_op === '<' && val > 0) { if (gt_op === '<' && val > 0) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -473,7 +473,7 @@ 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 (column.uidt === UITypes.Rating) { if (isNumericCol(column.uidt)) {
if (ge_op === '<=' || (ge_op === '>=' && val === 0)) { if (ge_op === '<=' || (ge_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -518,7 +518,7 @@ 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 (column.uidt === UITypes.Rating) { if (isNumericCol(column.uidt)) {
if (lt_op === '<' && val > 0) { if (lt_op === '<' && val > 0) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
} }
@ -528,7 +528,7 @@ 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 (column.uidt === UITypes.Rating) { if (isNumericCol(column.uidt)) {
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