grafana/public/app/plugins/datasource/mysql/MySqlQueryModel.ts
Victor Marin 902a230867
MSSQL/MySQL: Fix variable interpolation (#56879)
* MSSQL/MySQL: Fix variable interpolation

* Escape string vars
2022-10-14 11:52:08 +03:00

38 lines
979 B
TypeScript

import { ScopedVars } from '@grafana/data';
import { TemplateSrv } from '@grafana/runtime';
import { MySQLQuery } from './types';
export default class MySQLQueryModel {
target: Partial<MySQLQuery>;
templateSrv?: TemplateSrv;
scopedVars?: ScopedVars;
constructor(target: Partial<MySQLQuery>, templateSrv?: TemplateSrv, scopedVars?: ScopedVars) {
this.target = target;
this.templateSrv = templateSrv;
this.scopedVars = scopedVars;
}
// remove identifier quoting from identifier to use in metadata queries
unquoteIdentifier(value: string) {
if (value[0] === '"' && value[value.length - 1] === '"') {
return value.substring(1, value.length - 1).replace(/""/g, '"');
} else {
return value;
}
}
quoteIdentifier(value: string) {
return '"' + value.replace(/"/g, '""') + '"';
}
quoteLiteral(value: string) {
return "'" + value.replace(/'/g, "''") + "'";
}
getDatabase() {
return this.target.dataset;
}
}