From aef17be36cfcf3a6325a954e80f973623e250405 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Tue, 19 Oct 2021 17:42:31 +0200 Subject: [PATCH] fix(PostgreSQL): issue with uppercase characters in table field names --- src/common/customizations/defaults.js | 2 ++ src/common/customizations/mysql.js | 2 ++ src/common/customizations/postgresql.js | 2 ++ src/common/fieldTypes.js | 2 ++ src/main/libs/clients/PostgreSQLClient.js | 22 +++++++++++- src/renderer/components/WorkspaceTabTable.vue | 1 + .../components/WorkspaceTabTableFilters.vue | 35 ++++++++++++------- 7 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/common/customizations/defaults.js b/src/common/customizations/defaults.js index 73477750..1cc0fe47 100644 --- a/src/common/customizations/defaults.js +++ b/src/common/customizations/defaults.js @@ -22,6 +22,8 @@ module.exports = { functions: false, schedulers: false, // Settings + elementsWrapper: '', + stringsWrapper: '"', tableAdd: false, viewAdd: false, triggerAdd: false, diff --git a/src/common/customizations/mysql.js b/src/common/customizations/mysql.js index d55bee9f..673adea2 100644 --- a/src/common/customizations/mysql.js +++ b/src/common/customizations/mysql.js @@ -21,6 +21,8 @@ module.exports = { functions: true, schedulers: true, // Settings + elementsWrapper: '', + stringsWrapper: '"', tableAdd: true, viewAdd: true, triggerAdd: true, diff --git a/src/common/customizations/postgresql.js b/src/common/customizations/postgresql.js index 14609113..602663e4 100644 --- a/src/common/customizations/postgresql.js +++ b/src/common/customizations/postgresql.js @@ -18,6 +18,8 @@ module.exports = { routines: true, functions: true, // Settings + elementsWrapper: '"', + stringsWrapper: '\'', tableAdd: true, viewAdd: true, triggerAdd: true, diff --git a/src/common/fieldTypes.js b/src/common/fieldTypes.js index 011c9939..d3a8a1db 100644 --- a/src/common/fieldTypes.js +++ b/src/common/fieldTypes.js @@ -4,6 +4,7 @@ export const TEXT = [ 'CHARACTER', 'CHARACTER VARYING' ]; + export const LONG_TEXT = [ 'TEXT', 'MEDIUMTEXT', @@ -50,6 +51,7 @@ export const BOOLEAN = [ ]; export const DATE = ['DATE']; + export const TIME = [ 'TIME', 'TIME WITH TIME ZONE' diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index c3292e75..7d9125e7 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -36,6 +36,26 @@ export class PostgreSQLClient extends AntaresCore { }; } + _reducer (acc, curr) { + const type = typeof curr; + + switch (type) { + case 'number': + case 'string': + return [...acc, curr]; + case 'object': + if (Array.isArray(curr)) + return [...acc, ...curr]; + else { + const clausoles = []; + for (const key in curr) + clausoles.push(`"${key}" ${curr[key]}`); + + return clausoles; + } + } + } + _getTypeInfo (type) { return dataTypes .reduce((acc, group) => [...acc, ...group.types], []) @@ -1065,7 +1085,7 @@ export class PostgreSQLClient extends AntaresCore { const typeInfo = this._getTypeInfo(field.type); const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; - newColumns.push(`${field.name} + newColumns.push(`"${field.name}" ${field.type.toUpperCase()}${length ? `(${length})` : ''} ${field.unsigned ? 'UNSIGNED' : ''} ${field.zerofill ? 'ZEROFILL' : ''} diff --git a/src/renderer/components/WorkspaceTabTable.vue b/src/renderer/components/WorkspaceTabTable.vue index 84e6999f..4385ab04 100644 --- a/src/renderer/components/WorkspaceTabTable.vue +++ b/src/renderer/components/WorkspaceTabTable.vue @@ -131,6 +131,7 @@ diff --git a/src/renderer/components/WorkspaceTabTableFilters.vue b/src/renderer/components/WorkspaceTabTableFilters.vue index 16fb1a4e..8ba632f8 100644 --- a/src/renderer/components/WorkspaceTabTableFilters.vue +++ b/src/renderer/components/WorkspaceTabTableFilters.vue @@ -71,9 +71,13 @@