diff --git a/src/main/libs/clients/MySQLClient.js b/src/main/libs/clients/MySQLClient.js index 0bdcdf55..98c4912c 100644 --- a/src/main/libs/clients/MySQLClient.js +++ b/src/main/libs/clients/MySQLClient.js @@ -581,7 +581,7 @@ export class MySQLClient extends AntaresCore { const sql = `SHOW CREATE PROCEDURE \`${schema}\`.\`${routine}\``; const results = await this.raw(sql); - return results.rows.map(row => { + return results.rows.map(async row => { if (!row['Create Procedure']) { return { definer: null, @@ -595,22 +595,23 @@ export class MySQLClient extends AntaresCore { }; } - const parameters = row['Create Procedure'] - .match(/(\([^()]*(?:(?:\([^()]*\))[^()]*)*\)\s*)/s)[0] - .replaceAll('\r', '') - .replaceAll('\t', '') - .slice(1, -1) - .split(',') - .map(el => { - const param = el.split(' '); - const type = param[2] ? param[2].replace(')', '').split('(') : ['', null]; - return { - name: param[1] ? param[1].replaceAll('`', '') : '', - type: type[0].replaceAll('\n', ''), - length: +type[1] ? +type[1].replace(/\D/g, '') : '', - context: param[0] ? param[0].replace('\n', '') : '' - }; - }).filter(el => el.name); + const sql = `SELECT * + FROM information_schema.parameters + WHERE SPECIFIC_NAME = '${routine}' + AND SPECIFIC_SCHEMA = '${schema}' + ORDER BY ORDINAL_POSITION + `; + + const results = await this.raw(sql); + + const parameters = results.rows.map(row => { + return { + name: row.PARAMETER_NAME, + type: row.DATA_TYPE.toUpperCase(), + length: row.NUMERIC_PRECISION || row.DATETIME_PRECISION || row.CHARACTER_MAXIMUM_LENGTH || '', + context: row.PARAMETER_MODE + }; + }); let dataAccess = 'CONTAINS SQL'; if (row['Create Procedure'].includes('NO SQL')) @@ -701,7 +702,7 @@ export class MySQLClient extends AntaresCore { const sql = `SHOW CREATE FUNCTION \`${schema}\`.\`${func}\``; const results = await this.raw(sql); - return results.rows.map(row => { + return results.rows.map(async row => { if (!row['Create Function']) { return { definer: null, @@ -717,22 +718,23 @@ export class MySQLClient extends AntaresCore { }; } - const parameters = row['Create Function'] - .match(/(\([^()]*(?:(?:\([^()]*\))[^()]*)*\)\s*)/s)[0] - .replaceAll('\r', '') - .replaceAll('\t', '') - .slice(1, -1) - .split(',') - .map(el => { - const param = el.split(' '); - const type = param[1] ? param[1].replace(')', '').split('(') : ['', null]; + const sql = `SELECT * + FROM information_schema.parameters + WHERE SPECIFIC_NAME = '${func}' + AND SPECIFIC_SCHEMA = '${schema}' + ORDER BY ORDINAL_POSITION + `; - return { - name: param[0] ? param[0].replaceAll('`', '') : '', - type: type[0], - length: +type[1] ? +type[1].replace(/\D/g, '') : '' - }; - }).filter(el => el.name); + const results = await this.raw(sql); + + const parameters = results.rows.filter(row => row.PARAMETER_MODE).map(row => { + return { + name: row.PARAMETER_NAME, + type: row.DATA_TYPE.toUpperCase(), + length: row.NUMERIC_PRECISION || row.DATETIME_PRECISION || row.CHARACTER_MAXIMUM_LENGTH || '', + context: row.PARAMETER_MODE + }; + }); let dataAccess = 'CONTAINS SQL'; if (row['Create Function'].includes('NO SQL')) @@ -804,13 +806,15 @@ export class MySQLClient extends AntaresCore { return acc; }, []).join(','); - const sql = `CREATE ${func.definer ? `DEFINER=${func.definer} ` : ''}FUNCTION \`${func.name}\`(${parameters}) RETURNS ${func.returns}${func.returnsLength ? `(${func.returnsLength})` : ''} + const body = func.returns ? func.sql : 'BEGIN\n RETURN 0;\nEND'; + + const sql = `CREATE ${func.definer ? `DEFINER=${func.definer} ` : ''}FUNCTION \`${func.name}\`(${parameters}) RETURNS ${func.returns || 'SMALLINT'}${func.returnsLength ? `(${func.returnsLength})` : ''} LANGUAGE SQL ${func.deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'} ${func.dataAccess} SQL SECURITY ${func.security} COMMENT '${func.comment}' - ${func.sql}`; + ${body}`; return await this.raw(sql, { split: false }); } diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 87b95672..ca3c88c1 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -577,25 +577,25 @@ export class PostgreSQLClient extends AntaresCore { } const sql = `SELECT proc.specific_schema AS procedure_schema, - proc.specific_name, - proc.routine_name AS procedure_name, - proc.external_language, - args.parameter_name, - args.parameter_mode, - args.data_type - FROM information_schema.routines proc - LEFT JOIN information_schema.parameters args - ON proc.specific_schema = args.specific_schema - AND proc.specific_name = args.specific_name - WHERE proc.routine_schema not in ('pg_catalog', 'information_schema') - AND proc.routine_type = 'PROCEDURE' - AND proc.routine_name = '${routine}' - AND proc.specific_schema = '${schema}' - ORDER BY procedure_schema, - specific_name, - procedure_name, - args.ordinal_position - `; + proc.specific_name, + proc.routine_name AS procedure_name, + proc.external_language, + args.parameter_name, + args.parameter_mode, + args.data_type + FROM information_schema.routines proc + LEFT JOIN information_schema.parameters args + ON proc.specific_schema = args.specific_schema + AND proc.specific_name = args.specific_name + WHERE proc.routine_schema not in ('pg_catalog', 'information_schema') + AND proc.routine_type = 'PROCEDURE' + AND proc.routine_name = '${routine}' + AND proc.specific_schema = '${schema}' + ORDER BY procedure_schema, + specific_name, + procedure_name, + args.ordinal_position + `; const results = await this.raw(sql); @@ -705,25 +705,25 @@ export class PostgreSQLClient extends AntaresCore { } const sql = `SELECT proc.specific_schema AS procedure_schema, - proc.specific_name, - proc.routine_name AS procedure_name, - proc.external_language, - args.parameter_name, - args.parameter_mode, - args.data_type - FROM information_schema.routines proc - LEFT JOIN information_schema.parameters args - ON proc.specific_schema = args.specific_schema - AND proc.specific_name = args.specific_name - WHERE proc.routine_schema not in ('pg_catalog', 'information_schema') - AND proc.routine_type = 'FUNCTION' - AND proc.routine_name = '${func}' - AND proc.specific_schema = '${schema}' - ORDER BY procedure_schema, - specific_name, - procedure_name, - args.ordinal_position - `; + proc.specific_name, + proc.routine_name AS procedure_name, + proc.external_language, + args.parameter_name, + args.parameter_mode, + args.data_type + FROM information_schema.routines proc + LEFT JOIN information_schema.parameters args + ON proc.specific_schema = args.specific_schema + AND proc.specific_name = args.specific_name + WHERE proc.routine_schema not in ('pg_catalog', 'information_schema') + AND proc.routine_type = 'FUNCTION' + AND proc.routine_name = '${func}' + AND proc.specific_schema = '${schema}' + ORDER BY procedure_schema, + specific_name, + procedure_name, + args.ordinal_position + `; const results = await this.raw(sql); diff --git a/src/renderer/components/ModalSettings.vue b/src/renderer/components/ModalSettings.vue index 0068577c..b70ee5cc 100644 --- a/src/renderer/components/ModalSettings.vue +++ b/src/renderer/components/ModalSettings.vue @@ -227,7 +227,7 @@

{{ appName }}

{{ $t('word.version') }} {{ appVersion }}
- GitHub | CHANGELOG
+ GitHub | Website
{{ $t('word.author') }} Fabio Di Stasio
{{ $t('message.madeWithJS') }}

diff --git a/src/renderer/components/WorkspacePropsFunctionOptionsModal.vue b/src/renderer/components/WorkspacePropsFunctionOptionsModal.vue index 61591657..484e0b85 100644 --- a/src/renderer/components/WorkspacePropsFunctionOptionsModal.vue +++ b/src/renderer/components/WorkspacePropsFunctionOptionsModal.vue @@ -77,6 +77,9 @@ class="form-select text-uppercase" style="width: 0;" > +