Files
beejeebus 8ce8c1635f Escape database names in MSSQL datasource (#99754)
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.
2025-01-30 15:36:45 -05:00

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}`);
});
});