diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 7136a865..87b95672 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -727,7 +727,7 @@ export class PostgreSQLClient extends AntaresCore { const results = await this.raw(sql); - const parameters = results.rows.map(row => { + const parameters = results.rows.filter(row => row.parameter_mode).map(row => { return { name: row.parameter_name, type: row.data_type.toUpperCase(), @@ -746,7 +746,7 @@ export class PostgreSQLClient extends AntaresCore { deterministic: null, dataAccess: null, language: row.pg_get_functiondef.match(/(?<=LANGUAGE )(.*)(?<=[\S+\n\r\s])/gm)[0], - returns: row.pg_get_functiondef.match(/(?<=RETURNS SETOF )(.*)(?<=[\S+\n\r\s])/gm)[0].toUpperCase() + returns: row.pg_get_functiondef.match(/(?<=RETURNS )(.*)(?<=[\S+\n\r\s])/gm)[0].replace('SETOF ', '').toUpperCase() }; })[0]; } @@ -758,7 +758,7 @@ export class PostgreSQLClient extends AntaresCore { * @memberof PostgreSQLClient */ async dropFunction (params) { - const sql = `DROP FUNCTION \`${params.func}\``; + const sql = `DROP FUNCTION ${this._schema}.${params.func}`; return await this.raw(sql); } @@ -791,18 +791,23 @@ export class PostgreSQLClient extends AntaresCore { * @memberof PostgreSQLClient */ async createFunction (func) { - const parameters = func.parameters.reduce((acc, curr) => { - acc.push(`\`${curr.name}\` ${curr.type}${curr.length ? `(${curr.length})` : ''}`); - return acc; - }, []).join(','); + const parameters = 'parameters' in func + ? func.parameters.reduce((acc, curr) => { + acc.push(`${curr.context} ${curr.name} ${curr.type}${curr.length ? `(${curr.length})` : ''}`); + return acc; + }, []).join(',') + : ''; - const sql = `CREATE ${func.definer ? `DEFINER=${func.definer} ` : ''}FUNCTION \`${func.name}\`(${parameters}) RETURNS ${func.returns}${func.returnsLength ? `(${func.returnsLength})` : ''} + if (this._schema !== 'public') + this.use(this._schema); + + const body = func.returns ? func.sql : '$BODY$\n$BODY$'; + + const sql = `CREATE FUNCTION ${this._schema}.${func.name}(${parameters}) + RETURNS ${func.returns || 'void'} LANGUAGE ${func.language} - ${func.deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'} - ${func.dataAccess} - SQL SECURITY ${func.security} - COMMENT '${func.comment}' - ${func.sql}`; + SECURITY ${func.security} + AS ${body}`; return await this.raw(sql, { split: false }); } diff --git a/src/renderer/components/ModalAskParameters.vue b/src/renderer/components/ModalAskParameters.vue index ed4e795c..05e779f8 100644 --- a/src/renderer/components/ModalAskParameters.vue +++ b/src/renderer/components/ModalAskParameters.vue @@ -15,7 +15,7 @@
@@ -66,6 +66,11 @@ export default { values: {} }; }, + computed: { + inParameters () { + return this.localRoutine.parameters.filter(param => param.context === 'IN'); + } + }, created () { window.addEventListener('keydown', this.onKey); diff --git a/src/renderer/components/ModalNewFunction.vue b/src/renderer/components/ModalNewFunction.vue index 6d9494ab..4c319923 100644 --- a/src/renderer/components/ModalNewFunction.vue +++ b/src/renderer/components/ModalNewFunction.vue @@ -7,7 +7,7 @@ >
@@ -25,7 +25,19 @@ >
-
+
+ +
+ +
+
+
@@ -53,42 +65,7 @@
-
- -
-
- - -
-
-
-
+
@@ -111,7 +88,7 @@
-
+
@@ -124,7 +101,7 @@
-
+
+
+ +
+ +
+
-
+
+ +
+ +
+
+
@@ -81,6 +93,7 @@
-
+
@@ -112,7 +125,7 @@
-
+
@@ -125,7 +138,7 @@
-
+
-
+
@@ -119,6 +119,37 @@ >
+
+ +
+ + + +
+
@@ -168,6 +199,9 @@ export default { }, isChanged () { return JSON.stringify(this.localParameters) !== JSON.stringify(this.parametersProxy); + }, + customizations () { + return this.workspace.customizations; } }, mounted () { diff --git a/src/renderer/components/WorkspacePropsTabFunction.vue b/src/renderer/components/WorkspacePropsTabFunction.vue index 044e26b0..380c1c37 100644 --- a/src/renderer/components/WorkspacePropsTabFunction.vue +++ b/src/renderer/components/WorkspacePropsTabFunction.vue @@ -281,9 +281,11 @@ export default { switch (this.connection.client) { // TODO: move in a better place case 'maria': case 'mysql': - case 'pg': sql = `SELECT \`${this.originalFunction.name}\` (${params.join(',')})`; break; + case 'pg': + sql = `SELECT ${this.originalFunction.name}(${params.join(',')})`; + break; case 'mssql': sql = `SELECT ${this.originalFunction.name} ${params.join(',')}`; break;