fix parsing of nested cte's

This commit is contained in:
Fabian Freund 2023-02-15 10:18:26 +01:00
parent 21ff422f19
commit dc9a9e2db3
2 changed files with 32 additions and 1 deletions

View File

@ -5,6 +5,37 @@ import 'package:test/test.dart';
import '../../test_utils.dart';
void main() {
test('parse nested CTE', () async {
final backend = TestBackend.inTest({
'a|lib/test.drift': '''
test:
SELECT
*
FROM
(
WITH cte AS (
SELECT 1 AS val
)
SELECT * from cte
);
'''
});
final file = await backend.analyze('package:a/test.drift');
backend.expectNoErrors();
final query =
file.fileAnalysis!.resolvedQueries.values.single as SqlSelectQuery;
expect(query.variables, isEmpty);
expect(query.readsFrom, isEmpty);
final resultSet = query.resultSet;
expect(resultSet.singleColumn, isTrue);
expect(resultSet.needsOwnClass, isFalse);
expect(resultSet.scalarColumns.map((c) => c.sqlType), [DriftSqlType.int]);
});
test('recognizes CTE clause', () async {
final backend = TestBackend.inTest({
'a|lib/test.drift': '''

View File

@ -1350,7 +1350,7 @@ class Parser {
return tableRef;
} else if (_matchOne(TokenType.leftParen)) {
final first = _previous;
final innerStmt = select()!;
final innerStmt = _fullSelect()!;
_consume(TokenType.rightParen,
'Expected a right bracket to terminate the inner select');