mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-27 00:47:53 +01:00
fix: wrong field names when join tables
This commit is contained in:
parent
8e71f42a28
commit
ad0bad8486
@ -292,7 +292,7 @@ export class AntaresConnector {
|
|||||||
case 'maria':
|
case 'maria':
|
||||||
case 'mysql': {
|
case 'mysql': {
|
||||||
const { rows, report, fields } = await new Promise((resolve, reject) => {
|
const { rows, report, fields } = await new Promise((resolve, reject) => {
|
||||||
this._connection.query(query, (err, response, fields) => {
|
this._connection.query({ sql: query, nestTables: false }, (err, response, fields) => {
|
||||||
if (err)
|
if (err)
|
||||||
reject(err);
|
reject(err);
|
||||||
else {
|
else {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<i class="mdi mdi-48px mdi-power-plug-off" />
|
<i class="mdi mdi-48px mdi-power-plug-off" />
|
||||||
</div>
|
</div>
|
||||||
<p class="empty-title h5">
|
<p class="empty-title h5">
|
||||||
{{ $t('word.disconnected') }}
|
{{ isConnecting ? $t('word.connecting') : $t('word.disconnected') }}
|
||||||
</p>
|
</p>
|
||||||
<div class="empty-action">
|
<div class="empty-action">
|
||||||
<button
|
<button
|
||||||
|
@ -85,12 +85,15 @@ export default {
|
|||||||
setTabFields: 'workspaces/setTabFields',
|
setTabFields: 'workspaces/setTabFields',
|
||||||
setTabKeyUsage: 'workspaces/setTabKeyUsage'
|
setTabKeyUsage: 'workspaces/setTabKeyUsage'
|
||||||
}),
|
}),
|
||||||
getTable (index) {
|
getResultParams (index) {
|
||||||
const resultsWithRows = this.results.filter(result => result.rows);
|
const resultsWithRows = this.results.filter(result => result.rows);
|
||||||
|
|
||||||
if (resultsWithRows[index] && resultsWithRows[index].fields && resultsWithRows[index].fields.length)
|
if (resultsWithRows[index] && resultsWithRows[index].fields && resultsWithRows[index].fields.length) {
|
||||||
return resultsWithRows[index].fields[0].orgTable;
|
return resultsWithRows[index].fields.map(field => {
|
||||||
return '';
|
return { table: field.orgTable, schema: field.db };
|
||||||
|
}).filter((val, i, arr) => arr.findIndex(el => el.schema === val.schema && el.table === val.table) === i);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
},
|
},
|
||||||
async runQuery (query) {
|
async runQuery (query) {
|
||||||
if (!query) return;
|
if (!query) return;
|
||||||
@ -112,68 +115,69 @@ export default {
|
|||||||
let selectedFields = [];
|
let selectedFields = [];
|
||||||
const fieldsArr = [];
|
const fieldsArr = [];
|
||||||
const keysArr = [];
|
const keysArr = [];
|
||||||
let index = 0;
|
let qI = 0;
|
||||||
|
|
||||||
for (let i = 0; i < this.results.length; i++) {
|
for (const result of this.results) { // cycle queries
|
||||||
if (this.results[i].rows) { // if is a select
|
let fI = 0;
|
||||||
const table = this.getTable(index);
|
|
||||||
|
|
||||||
selectedFields = this.results[i].fields.map(field => field.orgName);
|
if (result.rows) { // if is a select
|
||||||
const selectedSchema = this.results[i].fields[0].db;
|
const paramsArr = this.getResultParams(qI);
|
||||||
this.resultsCount += this.results[i].rows.length;
|
|
||||||
|
|
||||||
try { // Table data
|
selectedFields = result.fields.map(field => field.orgName);
|
||||||
const params = {
|
this.resultsCount += result.rows.length;
|
||||||
uid: this.connection.uid,
|
|
||||||
schema: selectedSchema,
|
|
||||||
table
|
|
||||||
};
|
|
||||||
|
|
||||||
const { status, response } = await Tables.getTableColumns(params);
|
for (const paramObj of paramsArr) {
|
||||||
|
try { // Table data
|
||||||
|
const params = {
|
||||||
|
uid: this.connection.uid,
|
||||||
|
...paramObj
|
||||||
|
};
|
||||||
|
|
||||||
if (status === 'success') {
|
const { status, response } = await Tables.getTableColumns(params);
|
||||||
let fields = response.filter(field => selectedFields.includes(field.name));
|
|
||||||
if (selectedFields.length) {
|
if (status === 'success') {
|
||||||
fields = fields.map((field, index) => {
|
let fields = response.filter(field => selectedFields.includes(field.name));
|
||||||
return { ...field, alias: this.results[i].fields[index].name };
|
if (selectedFields.length) {
|
||||||
});
|
fields = fields.map(field => {
|
||||||
|
return { ...field, alias: result.fields[fI++].name };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsArr.push(fields);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
fieldsArr.push(fields);
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
}
|
}
|
||||||
else
|
|
||||||
this.addNotification({ status: 'error', message: response });
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
this.addNotification({ status: 'error', message: err.stack });
|
|
||||||
}
|
|
||||||
|
|
||||||
try { // Key usage (foreign keys)
|
try { // Key usage (foreign keys)
|
||||||
const params = {
|
const params = {
|
||||||
uid: this.connection.uid,
|
uid: this.connection.uid,
|
||||||
schema: selectedSchema,
|
...paramObj
|
||||||
table
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const { status, response } = await Tables.getKeyUsage(params);
|
const { status, response } = await Tables.getKeyUsage(params);
|
||||||
if (status === 'success')
|
if (status === 'success')
|
||||||
keysArr.push(response);
|
keysArr.push(response);
|
||||||
else
|
else
|
||||||
this.addNotification({ status: 'error', message: response });
|
this.addNotification({ status: 'error', message: response });
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
this.addNotification({ status: 'error', message: err.stack });
|
this.addNotification({ status: 'error', message: err.stack });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (this.results[i].report) { // if is a query without output
|
else if (result.report) { // if is a query without output
|
||||||
this.affectedCount += this.results[i].report.affectedRows;
|
this.affectedCount += result.report.affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
qI++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr });
|
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [fieldsArr.flat()] });
|
||||||
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr });
|
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: [keysArr.flat()] });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.addNotification({ status: 'error', message: response });
|
this.addNotification({ status: 'error', message: response });
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
<div class="thead">
|
<div class="thead">
|
||||||
<div class="tr">
|
<div class="tr">
|
||||||
<div
|
<div
|
||||||
v-for="field in fields"
|
v-for="(field, index) in fields"
|
||||||
:key="field.name"
|
:key="index"
|
||||||
class="th c-hand"
|
class="th c-hand"
|
||||||
>
|
>
|
||||||
<div ref="columnResize" class="column-resizable">
|
<div ref="columnResize" class="column-resizable">
|
||||||
|
@ -38,7 +38,8 @@ module.exports = {
|
|||||||
add: 'Add',
|
add: 'Add',
|
||||||
data: 'Data',
|
data: 'Data',
|
||||||
properties: 'Properties',
|
properties: 'Properties',
|
||||||
insert: 'Insert'
|
insert: 'Insert',
|
||||||
|
connecting: 'Connecting'
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
appWelcome: 'Welcome to Antares SQL Client!',
|
appWelcome: 'Welcome to Antares SQL Client!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user