Browse Source

Merge pull request #4543 from nocodb/fix/formula-division

fix: formula division for mysql
pull/4545/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
a5160cd744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulaQueryBuilderFromString.ts
  2. 5
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts
  3. 2
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts

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

@ -136,6 +136,11 @@ export default function formulaQueryBuilder(
type: 'CallExpression', type: 'CallExpression',
arguments: [pt.left], arguments: [pt.left],
}; };
pt.right = {
callee: { name: 'FLOAT' },
type: 'CallExpression',
arguments: [pt.right],
};
} }
const query = knex.raw( const query = knex.raw(

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

@ -646,6 +646,11 @@ export default async function formulaQueryBuilderv2(
type: 'CallExpression', type: 'CallExpression',
arguments: [pt.left], arguments: [pt.left],
}; };
pt.right = {
callee: { name: 'FLOAT' },
type: 'CallExpression',
arguments: [pt.right],
};
} }
pt.left.fnName = pt.left.fnName || 'ARITH'; pt.left.fnName = pt.left.fnName || 'ARITH';
pt.right.fnName = pt.right.fnName || 'ARITH'; pt.right.fnName = pt.right.fnName || 'ARITH';

2
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts

@ -36,7 +36,7 @@ const mysql2 = {
MID: 'SUBSTR', MID: 'SUBSTR',
FLOAT: (args: MapFnArgs) => { FLOAT: (args: MapFnArgs) => {
return args.knex return args.knex
.raw(`CAST(${args.fn(args.pt.arguments[0])} as DOUBLE)${args.colAlias}`) .raw(`CAST(CAST(${args.fn(args.pt.arguments[0])} as CHAR) AS DOUBLE)${args.colAlias}`)
.wrap('(', ')'); .wrap('(', ')');
}, },
DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => { DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => {

Loading…
Cancel
Save