Report syntax error for WITH in trigger

This commit is contained in:
Simon Binder 2023-06-01 00:08:41 +02:00
parent e2fe4228ad
commit 07fe555753
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 28 additions and 0 deletions

View File

@ -1,3 +1,7 @@
## 0.30.1
- Report syntax error for `WITH` clauses in triggers.
## 0.30.0
- Add `previous` and `next` fields for tokens

View File

@ -544,4 +544,17 @@ class LintingVisitor extends RecursiveVisitor<void, void> {
visitChildren(e, arg);
}
@override
void visitWithClause(WithClause e, void arg) {
if (_isInTopLevelTriggerStatement) {
context.reportError(AnalysisError(
type: AnalysisErrorType.synctactic,
relevantNode: e.withToken ?? e,
message: 'WITH clauses cannot appear in triggers.',
));
}
visitChildren(e, arg);
}
}

View File

@ -80,6 +80,17 @@ void main() {
.expectError('DEFAULT VALUES', type: AnalysisErrorType.synctactic);
});
test('WITH clauses', () {
// https://sqlite.org/lang_with.html#limitations_and_caveats
engine.analyze('WITH x AS (SELECT 1) SELECT 2').expectNoError();
engine.analyze('''
CREATE TRIGGER tgr AFTER INSERT ON demo BEGIN
WITH x AS (SELECT 1) SELECT 2;
END;
''').expectError('WITH', type: AnalysisErrorType.synctactic);
});
group('aliased source tables', () {
test('insert', () {
engine.analyze('INSERT INTO demo AS d VALUES (?, ?)').expectNoError();