diff --git a/src/renderer/components/WorkspaceQueryTab.vue b/src/renderer/components/WorkspaceQueryTab.vue index df179503..abc77d17 100644 --- a/src/renderer/components/WorkspaceQueryTab.vue +++ b/src/renderer/components/WorkspaceQueryTab.vue @@ -15,10 +15,10 @@
-
+
{{ $t('word.results') }}: {{ resultsCount }}
-
+
{{ $t('message.affectedRows') }}: {{ affectedCount }}
@@ -67,9 +67,8 @@ export default { lastQuery: '', isQuering: false, results: [], - resultsCount: 0, - affectedCount: 0, - selectedResultsset: 0 + resultsCount: false, + affectedCount: false }; }, computed: { @@ -78,11 +77,6 @@ export default { }), workspace () { return this.getWorkspace(this.connection.uid); - }, - schema () { - if ('fields' in this.results && this.results[this.selectedResultsset].fields.length) - return this.results[this.selectedResultsset].fields[0].db; - return this.workspace.breadcrumbs.schema; } }, methods: { @@ -92,8 +86,10 @@ export default { setTabKeyUsage: 'workspaces/setTabKeyUsage' }), getTable (index) { - if ('fields' in this.results[index] && this.results[index].fields.length) - return this.results[index].fields[0].orgTable; + const resultsWithRows = this.results.filter(result => result.rows); + + if (resultsWithRows[index] && resultsWithRows[index].fields && resultsWithRows[index].fields.length) + return resultsWithRows[index].fields[0].orgTable; return ''; }, async runQuery (query) { @@ -116,17 +112,20 @@ export default { let selectedFields = []; const fieldsArr = []; const keysArr = []; + let index = 0; - for (const [index, result] of this.results.entries()) { - if (result.rows) { // if is a select - selectedFields = result.fields.map(field => field.orgName); - this.resultsCount += result.rows.length; + for (let i = 0; i < this.results.length; i++) { + if (this.results[i].rows) { // if is a select + const table = this.getTable(index); + + selectedFields = this.results[i].fields.map(field => field.orgName); + this.resultsCount += this.results[i].rows.length; try { // Table data const params = { uid: this.connection.uid, schema: this.schema, - table: this.getTable(index) + table }; const { status, response } = await Tables.getTableColumns(params); @@ -135,7 +134,7 @@ export default { let fields = response.filter(field => selectedFields.includes(field.name)); if (selectedFields.length) { fields = fields.map((field, index) => { - return { ...field, alias: result.fields[index].name }; + return { ...field, alias: this.results[i].fields[index].name }; }); } @@ -152,7 +151,7 @@ export default { const params = { uid: this.connection.uid, schema: this.schema, - table: this.getTable(index) + table }; const { status, response } = await Tables.getKeyUsage(params); @@ -165,11 +164,13 @@ export default { this.addNotification({ status: 'error', message: err.stack }); } } - else { // if is a query without results - this.affectedCount += result.report.affectedRows; + else if (this.results[i].report) { // if is a query without output + this.affectedCount += this.results[i].report.affectedRows; } + + index++; } - console.log(fieldsArr); + this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr }); this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr }); } @@ -188,8 +189,8 @@ export default { }, clearTabData () { this.results = []; - this.resultsCount = 0; - this.affectedCount = 0; + this.resultsCount = false; + this.affectedCount = false; this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] }); } } diff --git a/src/renderer/components/WorkspaceQueryTable.vue b/src/renderer/components/WorkspaceQueryTable.vue index 817757c2..cfc8f7e4 100644 --- a/src/renderer/components/WorkspaceQueryTable.vue +++ b/src/renderer/components/WorkspaceQueryTable.vue @@ -11,15 +11,15 @@ @delete-selected="deleteSelected" @close-context="isContext = false" /> -
result.rows); + }, fields () { return this.getWorkspaceTab(this.tabUid) && this.getWorkspaceTab(this.tabUid).fields[this.resultsetIndex] ? this.getWorkspaceTab(this.tabUid).fields[this.resultsetIndex] : []; }, @@ -192,9 +195,14 @@ export default { return 'UNKNOWN ' + key; } }, + getTable (index) { + if (this.resultsWithRows[index] && this.resultsWithRows[index].fields && this.resultsWithRows[index].fields.length) + return this.resultsWithRows[index].fields[0].orgTable; + return ''; + }, setLocalResults () { this.resetSort(); - this.localResults = this.results[this.resultsetIndex] && this.results[this.resultsetIndex].rows ? this.results[this.resultsetIndex].rows.map(item => { + this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows ? this.resultsWithRows[this.resultsetIndex].rows.map(item => { return { ...item, _id: uidGen() }; }) : []; }, @@ -219,6 +227,7 @@ export default { else { const params = { primary: this.primaryField.name, + table: this.getTable(this.resultsetIndex), id, ...payload }; @@ -232,6 +241,7 @@ export default { const rowIDs = this.localResults.filter(row => this.selectedRows.includes(row._id)).map(row => row[this.primaryField.name]); const params = { primary: this.primaryField.name, + table: this.getTable(this.resultsetIndex), rows: rowIDs }; this.$emit('delete-selected', params); diff --git a/src/renderer/components/WorkspaceTableTab.vue b/src/renderer/components/WorkspaceTableTab.vue index f9274922..b45320e5 100644 --- a/src/renderer/components/WorkspaceTableTab.vue +++ b/src/renderer/components/WorkspaceTableTab.vue @@ -123,7 +123,7 @@ export default { const params = { uid: this.connection.uid, - schema: this.workspace.breadcrumbs.schema, + schema: this.schema, table: this.workspace.breadcrumbs.table }; diff --git a/src/renderer/mixins/tableTabs.js b/src/renderer/mixins/tableTabs.js index 01a9f6c1..9330f8cf 100644 --- a/src/renderer/mixins/tableTabs.js +++ b/src/renderer/mixins/tableTabs.js @@ -1,6 +1,17 @@ import Tables from '@/ipc-api/Tables'; export default { + computed: { + schema () { + if (Array.isArray(this.results)) { + const resultsWithRows = this.results.filter(result => result.rows); + + if (resultsWithRows[this.selectedResultsset] && resultsWithRows[this.selectedResultsset].fields.length) + return resultsWithRows[this.selectedResultsset].fields[0].db; + } + return this.workspace.breadcrumbs.schema; + } + }, methods: { async updateField (payload) { this.isQuering = true; @@ -8,7 +19,6 @@ export default { const params = { uid: this.connection.uid, schema: this.schema, - table: this.getTable(this.selectedResultsset), ...payload }; @@ -35,7 +45,6 @@ export default { const params = { uid: this.connection.uid, schema: this.schema, - table: this.getTable(this.selectedResultsset), ...payload };