Browse Source

refactor: revise based on PR comment

pull/2424/head
Wing-Kam Wong 3 years ago
parent
commit
271fe9ba13
  1. 4
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 7
      packages/nocodb/src/lib/models/Model.ts

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

@ -314,9 +314,7 @@ class BaseModelSqlv2 {
qb.count(this.model.primaryKey?.column_name || '*', { qb.count(this.model.primaryKey?.column_name || '*', {
as: 'count' as: 'count'
}).first(); }).first();
const res = (await this.dbDriver.raw( const res = (await this.dbDriver.raw(unsanitize(qb.toQuery()))) as any;
qb.toQuery().replaceAll('\\?', '?')
)) as any;
return (this.isPg ? res.rows[0] : res[0][0] ?? res[0]).count; return (this.isPg ? res.rows[0] : res[0][0] ?? res[0]).count;
} }

7
packages/nocodb/src/lib/models/Model.ts

@ -20,6 +20,7 @@ import {
import View from './View'; import View from './View';
import { NcError } from '../meta/helpers/catchError'; import { NcError } from '../meta/helpers/catchError';
import Audit from './Audit'; import Audit from './Audit';
import { sanitize } from '../db/sql-data-mapper/lib/sql/helpers/sanitize';
export default class Model implements TableType { export default class Model implements TableType {
copy_enabled: boolean; copy_enabled: boolean;
@ -405,11 +406,7 @@ export default class Model implements TableType {
if (isVirtualCol(col)) continue; if (isVirtualCol(col)) continue;
const val = data?.[col.column_name] ?? data?.[col.title]; const val = data?.[col.column_name] ?? data?.[col.title];
if (val !== undefined) { if (val !== undefined) {
insertObj[ insertObj[sanitize(col.column_name)] = val;
col.column_name.replace(/([^\\]|^)(\?+)/g, (_, m1, m2) => {
return `${m1}${m2.split('?').join('\\?')}`;
})
] = val;
} }
} }
return insertObj; return insertObj;

Loading…
Cancel
Save