diff --git a/src/renderer/components/ModalAskParameters.vue b/src/renderer/components/ModalAskParameters.vue new file mode 100644 index 00000000..3ca76c5d --- /dev/null +++ b/src/renderer/components/ModalAskParameters.vue @@ -0,0 +1,102 @@ + + + + + diff --git a/src/renderer/components/WorkspacePropsTabFunction.vue b/src/renderer/components/WorkspacePropsTabFunction.vue index 37bd33de..da0248bc 100644 --- a/src/renderer/components/WorkspacePropsTabFunction.vue +++ b/src/renderer/components/WorkspacePropsTabFunction.vue @@ -25,9 +25,9 @@
@@ -80,6 +86,7 @@ import BaseLoader from '@/components/BaseLoader'; import QueryEditor from '@/components/QueryEditor'; import WorkspacePropsFunctionOptionsModal from '@/components/WorkspacePropsFunctionOptionsModal'; import WorkspacePropsFunctionParamsModal from '@/components/WorkspacePropsFunctionParamsModal'; +import ModalAskParameters from '@/components/ModalAskParameters'; import Functions from '@/ipc-api/Functions'; export default { @@ -88,7 +95,8 @@ export default { BaseLoader, QueryEditor, WorkspacePropsFunctionOptionsModal, - WorkspacePropsFunctionParamsModal + WorkspacePropsFunctionParamsModal, + ModalAskParameters }, props: { connection: Object, @@ -101,6 +109,7 @@ export default { isSaving: false, isOptionsModal: false, isParamsModal: false, + isAskingParameters: false, originalFunction: null, localFunction: { sql: '' }, lastFunction: null, @@ -166,7 +175,8 @@ export default { addNotification: 'notifications/addNotification', refreshStructure: 'workspaces/refreshStructure', setUnsavedChanges: 'workspaces/setUnsavedChanges', - changeBreadcrumbs: 'workspaces/changeBreadcrumbs' + changeBreadcrumbs: 'workspaces/changeBreadcrumbs', + newTab: 'workspaces/newTab' }), async getFunctionData () { if (!this.function) return; @@ -257,6 +267,31 @@ export default { parametersUpdate (parameters) { this.localFunction = { ...this.localFunction, parameters }; }, + runFunctionCheck () { + if (this.localFunction.parameters.length) + this.showAskParamsModal(); + else + this.runFunction(); + }, + runFunction (params) { + if (!params) params = []; + + let sql; + 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 'mssql': + sql = `SELECT ${this.originalFunction.name} ${params.join(',')}`; + break; + default: + sql = `SELECT \`${this.originalFunction.name}\` (${params.join(',')})`; + } + + this.newTab({ uid: this.connection.uid, content: sql, autorun: true }); + }, showOptionsModal () { this.isOptionsModal = true; }, @@ -268,6 +303,12 @@ export default { }, hideParamsModal () { this.isParamsModal = false; + }, + showAskParamsModal () { + this.isAskingParameters = true; + }, + hideAskParamsModal () { + this.isAskingParameters = false; } } }; diff --git a/src/renderer/components/WorkspacePropsTabRoutine.vue b/src/renderer/components/WorkspacePropsTabRoutine.vue index e1bbdfb4..83511e36 100644 --- a/src/renderer/components/WorkspacePropsTabRoutine.vue +++ b/src/renderer/components/WorkspacePropsTabRoutine.vue @@ -25,9 +25,9 @@
@@ -80,6 +86,7 @@ import QueryEditor from '@/components/QueryEditor'; import BaseLoader from '@/components/BaseLoader'; import WorkspacePropsRoutineOptionsModal from '@/components/WorkspacePropsRoutineOptionsModal'; import WorkspacePropsRoutineParamsModal from '@/components/WorkspacePropsRoutineParamsModal'; +import ModalAskParameters from '@/components/ModalAskParameters'; import Routines from '@/ipc-api/Routines'; export default { @@ -88,7 +95,8 @@ export default { QueryEditor, BaseLoader, WorkspacePropsRoutineOptionsModal, - WorkspacePropsRoutineParamsModal + WorkspacePropsRoutineParamsModal, + ModalAskParameters }, props: { connection: Object, @@ -101,6 +109,7 @@ export default { isSaving: false, isOptionsModal: false, isParamsModal: false, + isAskingParameters: false, originalRoutine: null, localRoutine: { sql: '' }, lastRoutine: null, @@ -257,22 +266,30 @@ export default { parametersUpdate (parameters) { this.localRoutine = { ...this.localRoutine, parameters }; }, - runRoutine () { // TODO: create ask for params modal + runRoutineCheck () { + if (this.localRoutine.parameters.length) + this.showAskParamsModal(); + else + this.runRoutine(); + }, + runRoutine (params) { + if (!params) params = []; + let sql; switch (this.connection.client) { // TODO: move in a better place case 'maria': case 'mysql': case 'pg': - sql = `CALL \`${this.originalRoutine.name}\` ()`; + sql = `CALL \`${this.originalRoutine.name}\` (${params.join(',')})`; break; case 'mssql': - sql = `EXEC ${this.originalRoutine.name}`; + sql = `EXEC ${this.originalRoutine.name} ${params.join(',')}`; break; default: - sql = `CALL \`${this.originalRoutine.name}\` ()`; + sql = `CALL \`${this.originalRoutine.name}\` (${params.join(',')})`; } - this.newTab({ uid: this.connection.uid, content: sql, autorun: !this.originalRoutine.parameters.length }); + this.newTab({ uid: this.connection.uid, content: sql, autorun: true }); }, showOptionsModal () { this.isOptionsModal = true; @@ -285,6 +302,12 @@ export default { }, hideParamsModal () { this.isParamsModal = false; + }, + showAskParamsModal () { + this.isAskingParameters = true; + }, + hideAskParamsModal () { + this.isAskingParameters = false; } } };