Fix analysis for views with CTEs

This commit is contained in:
Simon Binder 2021-02-14 16:36:01 +01:00
parent 61d5b7897a
commit 968af8f56e
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 17 additions and 3 deletions

View File

@ -1,3 +1,7 @@
## 0.14.0-dev
- Fix views using common table expressions
## 0.13.0-nullsafety.0
- Parse ordering in table key constraints

View File

@ -39,10 +39,11 @@ class AstPreparingVisitor extends RecursiveVisitor<void, void> {
if (registeredView != null) {
scope.availableColumns = registeredView.resolvedColumns;
for (final column in registeredView.resolvedColumns) {
print(column.name);
scope.register(column.name, column);
}
}
visitChildren(e, arg);
}
@override

View File

@ -83,10 +83,11 @@ void main() {
});
group('can read views', () {
final engine = SqlEngine()..registerTable(demoTable);
View readView(String sql) {
final engine = SqlEngine()..registerTable(demoTable);
final context = engine.analyze(sql);
expect(context.errors, isEmpty);
final stmt = context.root as CreateViewStatement;
return const SchemaFromCreateTable().readView(context, stmt);
}
@ -109,6 +110,14 @@ void main() {
expect(view.name, 'another_view');
expect(view.resolvedColumns.map((e) => e.name), ['foo', 'bar']);
});
test('with WITH clause', () {
final view = readView('CREATE VIEW my_view AS '
'WITH foo AS (SELECT * FROM demo) SELECT * FROM foo;');
expect(view.name, 'my_view');
expect(view.resolvedColumns.map((e) => e.name), ['id', 'content']);
});
});
test('can read columns without type name', () {