mirror of https://github.com/AMT-Cheif/drift.git
Merge pull request #1564 from boyan01/develop
Fix unknown function cause SQL generator crash
This commit is contained in:
commit
61c2fff4e2
|
@ -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'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -564,6 +564,7 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
|
|||
session.context.reportError(AnalysisError(
|
||||
type: AnalysisErrorType.unknownFunction,
|
||||
message: 'Function ${e.name} could not be found',
|
||||
relevantNode: e,
|
||||
));
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue