diff --git a/src/containers/Tenant/Query/Preview/components/TablePreview.test.tsx b/src/containers/Tenant/Query/Preview/components/TablePreview.test.tsx new file mode 100644 index 0000000000..e0237c79b3 --- /dev/null +++ b/src/containers/Tenant/Query/Preview/components/TablePreview.test.tsx @@ -0,0 +1,41 @@ +import {prepareQueryWithPragmas} from '../../../../../store/reducers/query/utils'; + +describe('TablePreview - Pragma Integration', () => { + test('should correctly prepare query with pragmas for table preview', () => { + const baseQuery = 'select * from `test-table` limit 101'; + const pragmas = 'PRAGMA OrderedColumns;'; + + const result = prepareQueryWithPragmas(baseQuery, pragmas); + + expect(result).toBe('PRAGMA OrderedColumns;\n\nselect * from `test-table` limit 101'); + }); + + test('should handle empty pragmas correctly in table preview', () => { + const baseQuery = 'select * from `test-table` limit 101'; + const pragmas = ''; + + const result = prepareQueryWithPragmas(baseQuery, pragmas); + + expect(result).toBe('select * from `test-table` limit 101'); + }); + + test('should handle multiple pragmas correctly in table preview', () => { + const baseQuery = 'select * from `test-table` limit 101'; + const pragmas = 'PRAGMA OrderedColumns;\nPRAGMA AnsiOptionalAS;'; + + const result = prepareQueryWithPragmas(baseQuery, pragmas); + + expect(result).toBe( + 'PRAGMA OrderedColumns;\nPRAGMA AnsiOptionalAS;\n\nselect * from `test-table` limit 101', + ); + }); + + test('should handle pragmas without semicolon correctly in table preview', () => { + const baseQuery = 'select * from `test-table` limit 101'; + const pragmas = 'PRAGMA OrderedColumns'; + + const result = prepareQueryWithPragmas(baseQuery, pragmas); + + expect(result).toBe('PRAGMA OrderedColumns;\n\nselect * from `test-table` limit 101'); + }); +}); diff --git a/src/containers/Tenant/Query/Preview/components/TablePreview.tsx b/src/containers/Tenant/Query/Preview/components/TablePreview.tsx index c8df79abaf..927d02cd65 100644 --- a/src/containers/Tenant/Query/Preview/components/TablePreview.tsx +++ b/src/containers/Tenant/Query/Preview/components/TablePreview.tsx @@ -1,5 +1,7 @@ import {QueryResultTable} from '../../../../../components/QueryResultTable'; import {previewApi} from '../../../../../store/reducers/preview'; +import {prepareQueryWithPragmas} from '../../../../../store/reducers/query/utils'; +import {useQueryExecutionSettings} from '../../../../../utils/hooks/useQueryExecutionSettings'; import {isExternalTableType} from '../../../utils/schema'; import type {PreviewContainerProps} from '../types'; @@ -8,7 +10,11 @@ import {Preview} from './PreviewView'; const TABLE_PREVIEW_LIMIT = 100; export function TablePreview({database, path, type}: PreviewContainerProps) { - const query = `select * from \`${path}\` limit 101`; + const [querySettings] = useQueryExecutionSettings(); + + const baseQuery = `select * from \`${path}\` limit 101`; + const query = prepareQueryWithPragmas(baseQuery, querySettings.pragmas); + const {currentData, isFetching, error} = previewApi.useSendQueryQuery( { database,