From 966307fd3cbd76c551243bdce674ad4272fefbaf Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 10 Feb 2022 18:50:08 +0100 Subject: [PATCH] fixed analyse of mysql procedures/functions --- packages/types/dbinfo.d.ts | 4 +++- plugins/dbgate-plugin-mysql/src/backend/Analyser.js | 4 ++++ plugins/dbgate-plugin-mysql/src/backend/sql/programmables.js | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/types/dbinfo.d.ts b/packages/types/dbinfo.d.ts index ad70e22c..b12bd347 100644 --- a/packages/types/dbinfo.d.ts +++ b/packages/types/dbinfo.d.ts @@ -97,7 +97,9 @@ export interface ViewInfo extends SqlObjectInfo { export interface ProcedureInfo extends SqlObjectInfo {} -export interface FunctionInfo extends SqlObjectInfo {} +export interface FunctionInfo extends SqlObjectInfo { + // returnDataType?: string; +} export interface TriggerInfo extends SqlObjectInfo {} diff --git a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js index b63a90ca..88d4a918 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js @@ -132,6 +132,7 @@ class Analyser extends DatabaseAnalyser { .map(fp.omit(['objectType'])) .map(x => ({ ...x, + createSql: `DELIMITER //\n\nCREATE PROCEDURE \`${x.pureName}\`()\n${x.routineDefinition}\n\nDELIMITER ;\n`, objectId: x.pureName, contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate, })), @@ -140,6 +141,9 @@ class Analyser extends DatabaseAnalyser { .map(fp.omit(['objectType'])) .map(x => ({ ...x, + createSql: `CREATE FUNCTION \`${x.pureName}\`()\nRETURNS ${x.returnDataType} ${ + x.isDeterministic == 'YES' ? 'DETERMINISTIC' : 'NOT DETERMINISTIC' + }\n${x.routineDefinition}`, objectId: x.pureName, contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate, })), diff --git a/plugins/dbgate-plugin-mysql/src/backend/sql/programmables.js b/plugins/dbgate-plugin-mysql/src/backend/sql/programmables.js index 06f92c31..f6442fcc 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/sql/programmables.js +++ b/plugins/dbgate-plugin-mysql/src/backend/sql/programmables.js @@ -3,7 +3,9 @@ select ROUTINE_NAME as pureName, ROUTINE_TYPE as objectType, COALESCE(LAST_ALTERED, CREATED) as modifyDate, - ROUTINE_DEFINITION as createSql + DATA_TYPE AS returnDataType, + ROUTINE_DEFINITION as routineDefinition, + IS_DETERMINISTIC as isDeterministic from information_schema.routines where ROUTINE_SCHEMA = '#DATABASE#' and ROUTINE_NAME =OBJECT_ID_CONDITION `;