Browse Source

feat(nocodb): handle eq & neq cases for numerics

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
62429ce310
  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

@ -274,8 +274,22 @@ const parseConditionV2 = async (
switch (filter.comparison_op) { switch (filter.comparison_op) {
case 'eq': case 'eq':
if (qb?.client?.config?.client === 'mysql2') { if (qb?.client?.config?.client === 'mysql2') {
// mysql is case-insensitive, turn to case-sensitive 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]); qb = qb.whereRaw('BINARY ?? = ?', [field, val]);
}
} else { } else {
qb = qb.where(field, val); qb = qb.where(field, val);
} }
@ -283,12 +297,30 @@ const parseConditionV2 = async (
case 'neq': case 'neq':
case 'not': case 'not':
if (qb?.client?.config?.client === 'mysql2') { if (qb?.client?.config?.client === 'mysql2') {
// mysql is case-insensitive, turn to case-sensitive 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) => { qb = qb.where((nestedQb) => {
nestedQb nestedQb
.whereRaw('BINARY ?? != ?', [field, val]) .whereRaw('BINARY ?? != ?', [field, val])
.orWhereNull(customWhereClause ? _val : _field); .orWhereNull(customWhereClause ? _val : _field);
}); });
}
} else { } else {
qb = qb.where((nestedQb) => { qb = qb.where((nestedQb) => {
nestedQb nestedQb

Loading…
Cancel
Save