From fa3f3e1fd8101f19f18df71e90d60fd37cdddaee Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 5 Feb 2022 09:43:37 +0100 Subject: [PATCH] fix(MySQL): default value not displayed for DECIMAL fields --- src/common/data-types/mysql.js | 2 +- src/main/libs/clients/MySQLClient.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/data-types/mysql.js b/src/common/data-types/mysql.js index 8e77f900..14b61229 100644 --- a/src/common/data-types/mysql.js +++ b/src/common/data-types/mysql.js @@ -121,7 +121,7 @@ module.exports = [ { name: 'JSON', length: false, - collation: true, + collation: false, unsigned: false, zerofill: false } diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index 6e31f262..09910f47 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -395,7 +395,7 @@ export class MySQLClient extends AntaresCore { return acc; }, '') .replaceAll('\n', '') - .split(',') + .split(/,\s?(?![^(]*\))/) .map(f => { try { const fieldArr = f.trim().split(' '); @@ -440,6 +440,10 @@ export class MySQLClient extends AntaresCore { ? field.COLUMN_TYPE.match(/\(([^)]+)\)/)[0].slice(1, -1) : null; + const defaultValue = (remappedFields && remappedFields[field.COLUMN_NAME]) + ? remappedFields[field.COLUMN_NAME].default + : field.COLUMN_DEFAULT; + return { name: field.COLUMN_NAME, key: field.COLUMN_KEY.toLowerCase(), @@ -458,7 +462,7 @@ export class MySQLClient extends AntaresCore { unsigned: field.COLUMN_TYPE.includes('unsigned'), zerofill: field.COLUMN_TYPE.includes('zerofill'), order: field.ORDINAL_POSITION, - default: (remappedFields && remappedFields[field.COLUMN_NAME]) ? remappedFields[field.COLUMN_NAME].default : field.COLUMN_DEFAULT, + default: defaultValue, charset: field.CHARACTER_SET_NAME, collation: field.COLLATION_NAME, autoIncrement: field.EXTRA.includes('auto_increment'),