Browse Source

fix: binding in filter

pull/2424/head
Wing-Kam Wong 2 years ago
parent
commit
04fe0dc619
  1. 5
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 10
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

5
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -308,8 +308,9 @@ class BaseModelSqlv2 {
qb.count(this.model.primaryKey?.column_name || '*', {
as: 'count'
}).first();
return ((await qb) as any).count;
return ((await this.dbDriver.raw(
qb.toQuery().replaceAll('\\?', '?')
)) as any)[0][0].count;
}
async groupBy(

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

@ -203,16 +203,18 @@ const parseConditionV2 = async (
filter.comparison_op === 'notempty'
)
filter.value = '';
let field = customWhereClause
let field = (customWhereClause
? filter.value
: alias
? `${alias}.${column.column_name}`
: column.column_name;
: column.column_name
).replaceAll('?', '\\\\?');
let val = customWhereClause ? customWhereClause : filter.value;
return qb => {
switch (filter.comparison_op) {
case 'eq':
console.log(qb.toQuery());
qb = qb.where(field, val);
break;
case 'neq':
@ -221,7 +223,7 @@ const parseConditionV2 = async (
case 'like':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%');
} else {
val = `%${val}%`;
}
@ -234,7 +236,7 @@ const parseConditionV2 = async (
case 'nlike':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%');
} else {
val = `%${val}%`;
}

Loading…
Cancel
Save