mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
properly quote where constraint parts
This commit is contained in:
parent
340f679d0f
commit
1d8540ac69
@ -130,7 +130,7 @@ export default class PostgresQuery {
|
|||||||
this.updatePersistedParts();
|
this.updatePersistedParts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderTagCondition(tag, index, interpolate) {
|
private renderWhereConstraint(tag, index, interpolate) {
|
||||||
var str = '';
|
var str = '';
|
||||||
var operator = tag.operator;
|
var operator = tag.operator;
|
||||||
var value = tag.value;
|
var value = tag.value;
|
||||||
@ -138,27 +138,11 @@ export default class PostgresQuery {
|
|||||||
str = (tag.condition || 'AND') + ' ';
|
str = (tag.condition || 'AND') + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!operator) {
|
if (interpolate) {
|
||||||
if (/^\/.*\/$/.test(value)) {
|
value = this.templateSrv.replace(value, this.scopedVars);
|
||||||
operator = '=~';
|
|
||||||
} else {
|
|
||||||
operator = '=';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// quote value unless regex
|
return str + this.quoteIdentifier(tag.key) + ' ' + operator + ' ' + this.quoteLiteral(value);
|
||||||
if (operator !== '=~' && operator !== '!~') {
|
|
||||||
if (interpolate) {
|
|
||||||
value = this.templateSrv.replace(value, this.scopedVars);
|
|
||||||
}
|
|
||||||
if (operator !== '>' && operator !== '<') {
|
|
||||||
value = "'" + value.replace(/\\/g, '\\\\') + "'";
|
|
||||||
}
|
|
||||||
} else if (interpolate) {
|
|
||||||
value = this.templateSrv.replace(value, this.scopedVars, 'regex');
|
|
||||||
}
|
|
||||||
|
|
||||||
return str + '"' + tag.key + '" ' + operator + ' ' + value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interpolateQueryStr(value, variable, defaultFormatFn) {
|
interpolateQueryStr(value, variable, defaultFormatFn) {
|
||||||
@ -223,7 +207,7 @@ export default class PostgresQuery {
|
|||||||
|
|
||||||
query += ' FROM ' + this.quoteIdentifier(target.schema) + '.' + this.quoteIdentifier(target.table) + ' WHERE ';
|
query += ' FROM ' + this.quoteIdentifier(target.schema) + '.' + this.quoteIdentifier(target.table) + ' WHERE ';
|
||||||
var conditions = _.map(target.where, (tag, index) => {
|
var conditions = _.map(target.where, (tag, index) => {
|
||||||
return this.renderTagCondition(tag, index, interpolate);
|
return this.renderWhereConstraint(tag, index, interpolate);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (conditions.length > 0) {
|
if (conditions.length > 0) {
|
||||||
@ -260,7 +244,7 @@ export default class PostgresQuery {
|
|||||||
|
|
||||||
renderAdhocFilters(filters) {
|
renderAdhocFilters(filters) {
|
||||||
var conditions = _.map(filters, (tag, index) => {
|
var conditions = _.map(filters, (tag, index) => {
|
||||||
return this.renderTagCondition(tag, index, false);
|
return this.renderWhereConstraint(tag, index, false);
|
||||||
});
|
});
|
||||||
return conditions.join(' ');
|
return conditions.join(' ');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user