Skip to content

Commit

Permalink
fix: value overridden when join tables with fields with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Sep 13, 2020
1 parent 9b76c8e commit 78965d2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ This is a roadmap with major features will come in near future.
## Translations

[Giuseppe Gigliotti](https://github.com/ReverbOD) / [Italian Translation](https://github.com/EStarium/antares/pull/20)
[Mohd-PH](https://github.com/Mohd-PH) / [Arabic Translation](https://github.com/EStarium/antares/pull/29)
[Mohd-PH](https://github.com/Mohd-PH) / [Arabic Translation](https://github.com/EStarium/antares/pull/29)
[hongkfui](https://github.com/hongkfui) / [Spanish Translation](https://github.com/EStarium/antares/pull/32)
6 changes: 4 additions & 2 deletions src/main/libs/AntaresConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ export class AntaresConnector {

/**
* @param {string} sql raw SQL query
* @param {boolean} [nest]
* @returns {Promise}
* @memberof AntaresConnector
*/
async raw (sql) {
async raw (sql, nest) {
const nestTables = nest ? '.' : false;
const resultsArr = [];
const queries = sql.split(';');

Expand All @@ -292,7 +294,7 @@ export class AntaresConnector {
case 'maria':
case 'mysql': {
const { rows, report, fields } = await new Promise((resolve, reject) => {
this._connection.query({ sql: query, nestTables: false }, (err, response, fields) => {
this._connection.query({ sql: query, nestTables }, (err, response, fields) => {
if (err)
reject(err);
else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/models/Generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default class {
return err;
}
}
return connection.raw(query);
return connection.raw(query, true);
}
}
2 changes: 2 additions & 0 deletions src/main/models/InformationSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default class {
name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE,
schema: field.TABLE_SCHEMA,
table: field.TABLE_NAME,
numPrecision: field.NUMERIC_PRECISION,
datePrecision: field.DATETIME_PRECISION,
charLength: field.CHARACTER_MAXIMUM_LENGTH,
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/components/WorkspaceQueryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
class="tr"
:class="{'selected': selectedRows.includes(row._id)}"
@select-row="selectRow($event, row._id)"
@update-field="updateField($event, row[primaryField.alias || primaryField.name])"
@update-field="updateField($event, getPrimaryValue(row))"
@contextmenu="contextMenu"
/>
</template>
Expand Down Expand Up @@ -200,6 +200,15 @@ export default {
return this.resultsWithRows[index].fields[0].orgTable;
return '';
},
getPrimaryValue (row) {
const primaryFieldName = Object.keys(row).find(prop => [
this.primaryField.alias,
this.primaryField.name,
`${this.primaryField.table}.${this.primaryField.alias}`,
`${this.primaryField.table}.${this.primaryField.name}`
].includes(prop));
return row[primaryFieldName];
},
setLocalResults () {
this.resetSort();
this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows ? this.resultsWithRows[this.resultsetIndex].rows.map(item => {
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/components/WorkspaceQueryTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ export default {
return length;
},
getFieldObj (cKey) {
return this.fields.filter(field => field.name === cKey || field.alias === cKey)[0];
return this.fields.filter(field =>
field.name === cKey ||
field.alias === cKey ||
`${field.table}.${field.name}` === cKey ||
`${field.table}.${field.alias}` === cKey)[0];
},
isNull (value) {
return value === null ? ' is-null' : '';
Expand Down

0 comments on commit 78965d2

Please sign in to comment.