mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
MSSQL/MySQL: Fix variable interpolation (#56879)
* MSSQL/MySQL: Fix variable interpolation * Escape string vars
This commit is contained in:
@@ -55,10 +55,9 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
interpolateVariable = (value: string | string[] | number, variable: VariableWithMultiSupport) => {
|
||||
if (typeof value === 'string') {
|
||||
if (variable.multi || variable.includeAll) {
|
||||
const result = this.getQueryModel().quoteLiteral(value);
|
||||
return result;
|
||||
return this.getQueryModel().quoteLiteral(value);
|
||||
} else {
|
||||
return value;
|
||||
return String(value).replace(/'/g, "''");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,20 +97,14 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
target: SQLQuery,
|
||||
scopedVars: ScopedVars
|
||||
): Record<string, string | DataSourceRef | SQLQuery['format']> {
|
||||
const queryModel = this.getQueryModel(target, this.templateSrv, scopedVars);
|
||||
const rawSql = this.clean(queryModel.interpolate());
|
||||
return {
|
||||
refId: target.refId,
|
||||
datasource: this.getRef(),
|
||||
rawSql,
|
||||
rawSql: this.templateSrv.replace(target.rawSql, scopedVars, this.interpolateVariable),
|
||||
format: target.format,
|
||||
};
|
||||
}
|
||||
|
||||
clean(value: string) {
|
||||
return value.replace(/''/g, "'");
|
||||
}
|
||||
|
||||
async metricFindQuery(query: string, optionalOptions?: MetricFindQueryOptions): Promise<MetricFindValue[]> {
|
||||
const rawSql = this.templateSrv.replace(
|
||||
query,
|
||||
|
||||
Reference in New Issue
Block a user