Support subquery expressions in types2 (#583)

This commit is contained in:
Markus Richter 2020-05-19 19:42:36 +02:00 committed by Simon Binder
parent 65f02cb22c
commit 5596c30cc7
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,20 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
} }
} }
@override
void visitSubQuery(SubQuery e, TypeExpectation arg) {
final columnsOfQuery = e.select.resolvedColumns;
if (columnsOfQuery.isEmpty) {
return super.visitSubQuery(e, arg);
}
// The query should return one column only, but this is not the right place
// to lint that. Just pick any column and resolve to that.
final columnForExpr = columnsOfQuery.first;
session._addRelation(CopyTypeFrom(e, columnForExpr));
visitChildren(e, arg);
}
@override @override
void visitInsertStatement(InsertStatement e, TypeExpectation arg) { void visitInsertStatement(InsertStatement e, TypeExpectation arg) {
if (e.withClause != null) visit(e.withClause, arg); if (e.withClause != null) visit(e.withClause, arg);

View File

@ -192,6 +192,11 @@ void main() {
expect(type, const ResolvedType(type: BasicType.int)); expect(type, const ResolvedType(type: BasicType.int));
}); });
test('resolves subqueries', () {
final type = _resolveResultColumn('SELECT (SELECT COUNT(*) FROM demo);');
expect(type, const ResolvedType(type: BasicType.int));
});
test('infers types for dart placeholders', () { test('infers types for dart placeholders', () {
final resolver = _obtainResolver(r'SELECT * FROM demo WHERE $pred'); final resolver = _obtainResolver(r'SELECT * FROM demo WHERE $pred');
final type = resolver.session.typeOf(resolver final type = resolver.session.typeOf(resolver