mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 07:11:51 +08:00

Valid MSSQL database names can contain characters like `-`, which need to be escaped when used in queries. This PR wraps database names in `[]`, and fixes Grafana issue #58757.
19 lines
538 B
TypeScript
19 lines
538 B
TypeScript
import { SQLQuery, QueryEditorExpressionType } from '@grafana/sql';
|
|
|
|
import { toRawSql } from './sqlUtil';
|
|
|
|
describe('toRawSql should escape database names', () => {
|
|
const query: SQLQuery = {
|
|
dataset: 'foo',
|
|
sql: {
|
|
columns: [{ name: 'a', alias: 'lol', type: QueryEditorExpressionType.Function }],
|
|
},
|
|
refId: 'lolsob',
|
|
table: 'table',
|
|
};
|
|
const queryString = toRawSql(query);
|
|
it('should escapte database names', () => {
|
|
expect(queryString).toContain(`FROM [${query.dataset}].${query.table}`);
|
|
});
|
|
});
|