Commit 7c499ffd by Marcus Efraimsson Committed by GitHub

MySQL, Postgres: Update raw sql when query builder updates (#19209)

Raw sql now updates when changing query using 
graphical query editor for mysql and postgres.

Fixes #19063
parent 96046a7b
...@@ -82,7 +82,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -82,7 +82,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.target.timeColumnType = 'timestamp'; this.target.timeColumnType = 'timestamp';
this.target.select = [[{ type: 'column', params: [result[2].text] }]]; this.target.select = [[{ type: 'column', params: [result[2].text] }]];
this.updateProjection(); this.updateProjection();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
}); });
} }
...@@ -105,6 +105,14 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -105,6 +105,14 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope); this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
} }
updateRawSqlAndRefresh() {
if (!this.target.rawQuery) {
this.target.rawSql = this.queryModel.buildQuery();
}
this.panelCtrl.refresh();
}
updateProjection() { updateProjection() {
this.selectParts = _.map(this.target.select, (parts: any) => { this.selectParts = _.map(this.target.select, (parts: any) => {
return _.map(parts, sqlPart.create).filter(n => n); return _.map(parts, sqlPart.create).filter(n => n);
...@@ -205,7 +213,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -205,7 +213,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
}); });
this.$q.all([task1, task2]).then(() => { this.$q.all([task1, task2]).then(() => {
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
}); });
} }
...@@ -242,7 +250,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -242,7 +250,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.updatePersistedParts(); this.updatePersistedParts();
if (refresh !== false) { if (refresh !== false) {
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
}); });
} }
...@@ -256,7 +264,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -256,7 +264,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
metricColumnChanged() { metricColumnChanged() {
this.target.metricColumn = this.metricColumnSegment.value; this.target.metricColumn = this.metricColumnSegment.value;
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
onDataReceived(dataList: any) { onDataReceived(dataList: any) {
...@@ -391,7 +399,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -391,7 +399,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
removeSelectPart(selectParts: any, part: { def: { type: string } }) { removeSelectPart(selectParts: any, part: { def: { type: string } }) {
...@@ -427,12 +435,12 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -427,12 +435,12 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
case 'part-param-changed': { case 'part-param-changed': {
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
this.removeSelectPart(selectParts, part); this.removeSelectPart(selectParts, part);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -451,12 +459,12 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -451,12 +459,12 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
case 'part-param-changed': { case 'part-param-changed': {
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
this.removeGroup(part, index); this.removeGroup(part, index);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -550,14 +558,14 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -550,14 +558,14 @@ export class MysqlQueryCtrl extends QueryCtrl {
part.datatype = d[0].text; part.datatype = d[0].text;
} }
}); });
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
// remove element // remove element
whereParts.splice(index, 1); whereParts.splice(index, 1);
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -596,7 +604,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -596,7 +604,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.updatePersistedParts(); this.updatePersistedParts();
this.resetPlusButton(this.whereAdd); this.resetPlusButton(this.whereAdd);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
getGroupOptions() { getGroupOptions() {
...@@ -623,7 +631,7 @@ export class MysqlQueryCtrl extends QueryCtrl { ...@@ -623,7 +631,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
this.resetPlusButton(this.groupAdd); this.resetPlusButton(this.groupAdd);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
handleQueryError(err: any): any[] { handleQueryError(err: any): any[] {
......
...@@ -80,7 +80,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -80,7 +80,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.target.timeColumnType = 'timestamp'; this.target.timeColumnType = 'timestamp';
this.target.select = [[{ type: 'column', params: [result[2].text] }]]; this.target.select = [[{ type: 'column', params: [result[2].text] }]];
this.updateProjection(); this.updateProjection();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
}); });
} }
...@@ -103,6 +103,14 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -103,6 +103,14 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope); this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
} }
updateRawSqlAndRefresh() {
if (!this.target.rawQuery) {
this.target.rawSql = this.queryModel.buildQuery();
}
this.panelCtrl.refresh();
}
updateProjection() { updateProjection() {
this.selectParts = _.map(this.target.select, (parts: any) => { this.selectParts = _.map(this.target.select, (parts: any) => {
return _.map(parts, sqlPart.create).filter(n => n); return _.map(parts, sqlPart.create).filter(n => n);
...@@ -236,7 +244,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -236,7 +244,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
}); });
this.$q.all([task1, task2]).then(() => { this.$q.all([task1, task2]).then(() => {
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
}); });
} }
...@@ -273,7 +281,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -273,7 +281,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.updatePersistedParts(); this.updatePersistedParts();
if (refresh !== false) { if (refresh !== false) {
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
}); });
} }
...@@ -287,7 +295,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -287,7 +295,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
metricColumnChanged() { metricColumnChanged() {
this.target.metricColumn = this.metricColumnSegment.value; this.target.metricColumn = this.metricColumnSegment.value;
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
onDataReceived(dataList: any) { onDataReceived(dataList: any) {
...@@ -423,7 +431,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -423,7 +431,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
removeSelectPart(selectParts: any, part: { def: { type: string } }) { removeSelectPart(selectParts: any, part: { def: { type: string } }) {
...@@ -459,12 +467,12 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -459,12 +467,12 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
case 'part-param-changed': { case 'part-param-changed': {
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
this.removeSelectPart(selectParts, part); this.removeSelectPart(selectParts, part);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -483,12 +491,12 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -483,12 +491,12 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
case 'part-param-changed': { case 'part-param-changed': {
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
this.removeGroup(part, index); this.removeGroup(part, index);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -582,14 +590,14 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -582,14 +590,14 @@ export class PostgresQueryCtrl extends QueryCtrl {
part.datatype = d[0].text; part.datatype = d[0].text;
} }
}); });
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'action': { case 'action': {
// remove element // remove element
whereParts.splice(index, 1); whereParts.splice(index, 1);
this.updatePersistedParts(); this.updatePersistedParts();
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
break; break;
} }
case 'get-part-actions': { case 'get-part-actions': {
...@@ -628,7 +636,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -628,7 +636,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.updatePersistedParts(); this.updatePersistedParts();
this.resetPlusButton(this.whereAdd); this.resetPlusButton(this.whereAdd);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
getGroupOptions() { getGroupOptions() {
...@@ -655,7 +663,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -655,7 +663,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
this.resetPlusButton(this.groupAdd); this.resetPlusButton(this.groupAdd);
this.panelCtrl.refresh(); this.updateRawSqlAndRefresh();
} }
handleQueryError(err: any): any[] { handleQueryError(err: any): any[] {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment