diff --git a/public/app/features/plugins/sql/datasource/SqlDatasource.ts b/public/app/features/plugins/sql/datasource/SqlDatasource.ts index 3adf02b4944..3ea0c6d5401 100644 --- a/public/app/features/plugins/sql/datasource/SqlDatasource.ts +++ b/public/app/features/plugins/sql/datasource/SqlDatasource.ts @@ -55,10 +55,9 @@ export abstract class SqlDatasource extends DataSourceWithBackend { 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 { - 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 { const rawSql = this.templateSrv.replace( query, diff --git a/public/app/features/plugins/sql/types.ts b/public/app/features/plugins/sql/types.ts index ad649fe03e4..c3e1e55769b 100644 --- a/public/app/features/plugins/sql/types.ts +++ b/public/app/features/plugins/sql/types.ts @@ -166,7 +166,6 @@ export interface ValidationResults { } export interface SqlQueryModel { - interpolate: () => string; quoteLiteral: (v: string) => string; } diff --git a/public/app/plugins/datasource/mssql/MSSqlQueryModel.ts b/public/app/plugins/datasource/mssql/MSSqlQueryModel.ts index e74eb112f67..45754ed51c9 100644 --- a/public/app/plugins/datasource/mssql/MSSqlQueryModel.ts +++ b/public/app/plugins/datasource/mssql/MSSqlQueryModel.ts @@ -2,7 +2,6 @@ import { ScopedVars } from '@grafana/data'; import { TemplateSrv } from '@grafana/runtime'; import { applyQueryDefaults } from 'app/features/plugins/sql/defaults'; import { SQLQuery, SqlQueryModel } from 'app/features/plugins/sql/types'; -import { FormatRegistryID } from 'app/features/templating/formatRegistry'; export class MSSqlQueryModel implements SqlQueryModel { target: SQLQuery; @@ -15,10 +14,6 @@ export class MSSqlQueryModel implements SqlQueryModel { this.scopedVars = scopedVars; } - interpolate() { - return this.templateSrv?.replace(this.target.rawSql, this.scopedVars, FormatRegistryID.sqlString) || ''; - } - quoteLiteral(value: string) { return "'" + value.replace(/'/g, "''") + "'"; } diff --git a/public/app/plugins/datasource/mysql/MySqlQueryModel.ts b/public/app/plugins/datasource/mysql/MySqlQueryModel.ts index dbd0fee6895..c31ef7fcc0a 100644 --- a/public/app/plugins/datasource/mysql/MySqlQueryModel.ts +++ b/public/app/plugins/datasource/mysql/MySqlQueryModel.ts @@ -1,5 +1,3 @@ -import { map } from 'lodash'; - import { ScopedVars } from '@grafana/data'; import { TemplateSrv } from '@grafana/runtime'; @@ -33,28 +31,6 @@ export default class MySQLQueryModel { return "'" + value.replace(/'/g, "''") + "'"; } - escapeLiteral(value: string) { - return String(value).replace(/'/g, "''"); - } - - format = (value: string, variable: { multi: boolean; includeAll: boolean }) => { - // if no multi or include all do not regexEscape - if (!variable.multi && !variable.includeAll) { - return this.escapeLiteral(value); - } - - if (typeof value === 'string') { - return this.quoteLiteral(value); - } - - const escapedValues = map(value, this.quoteLiteral); - return escapedValues.join(','); - }; - - interpolate() { - return this.templateSrv!.replace(this.target.rawSql, this.scopedVars, this.format); - } - getDatabase() { return this.target.dataset; }