From b5d32ee21a6895a25a49df94ad62ebf85e2f10d9 Mon Sep 17 00:00:00 2001 From: boyan <17426470+boyan01@users.noreply.github.com> Date: Fri, 26 Nov 2021 13:08:26 +0800 Subject: [PATCH] fix unknown function cause crash --- .../analyzer/moor/virtual_table_test.dart | 34 +++++++++++++++++-- .../src/analysis/types/resolving_visitor.dart | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drift_dev/test/analyzer/moor/virtual_table_test.dart b/drift_dev/test/analyzer/moor/virtual_table_test.dart index f41325a0..80a05d3f 100644 --- a/drift_dev/test/analyzer/moor/virtual_table_test.dart +++ b/drift_dev/test/analyzer/moor/virtual_table_test.dart @@ -1,5 +1,4 @@ import 'package:drift_dev/src/analyzer/options.dart'; -import 'package:test/scaffolding.dart'; import 'package:test/test.dart'; import '../utils.dart'; @@ -21,7 +20,6 @@ CREATE VIRTUAL TABLE example_table_search ); ''', 'a|lib/queries.moor': ''' -import 'table.moor'; exampleSearch: SELECT example_table.**, s.* FROM example_table INNER JOIN ( @@ -42,4 +40,36 @@ exampleSearch: SELECT example_table.**, s.* FROM example_table final result = await state.analyze('package:a/queries.moor'); expect(result.errors.errors, isEmpty); }); + + test('query virtual tables with unknown fucntion', () async { + final state = TestState.withContent( + { + 'a|lib/table.moor': ''' +CREATE TABLE example_table ( + json_column TEXT, + name TEXT, + content TEXT +); + +CREATE VIRTUAL TABLE example_table_search + USING fts5( + name, content, content='example_table', content_rowid='rowid' + ); + +exampleSearch: +SELECT rowid, highlight(example_table_search, 0, '[match]', '[match]') name, + snippet(example_table_search, 1, '[match]', '[match]', '...', 10) content, + bm25(example_table_search) AS rank + FROM example_table_search WHERE example_table_search MATCH simple_query(:search); + ''', + }, + enableAnalyzer: false, + options: const MoorOptions.defaults(modules: [SqlModule.fts5]), + ); + addTearDown(state.close); + final result = await state.analyze('package:a/table.moor'); + expect(result.errors.errors, hasLength(1)); + expect(result.errors.errors.single.message, + contains('Function simple_query could not be found')); + }); } diff --git a/sqlparser/lib/src/analysis/types/resolving_visitor.dart b/sqlparser/lib/src/analysis/types/resolving_visitor.dart index 01d08195..99d4b139 100644 --- a/sqlparser/lib/src/analysis/types/resolving_visitor.dart +++ b/sqlparser/lib/src/analysis/types/resolving_visitor.dart @@ -564,6 +564,7 @@ class TypeResolver extends RecursiveVisitor { session.context.reportError(AnalysisError( type: AnalysisErrorType.unknownFunction, message: 'Function ${e.name} could not be found', + relevantNode: e, )); return null; }