Resolve columns in CREATE TRIGGER declaration (#751)

This commit is contained in:
Simon Binder 2020-08-07 20:38:32 +02:00
parent cd61c5ad16
commit 0d9196dca8
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,11 @@
## 0.10.1
- Scan identifiers with `[bracket syntax]`
- `NumericToken` now contains individual lexemes making up the number
- Improve error messages in some scenarios
- Fix type inference for binary expressions where the operands have incompatible types
- Improve type inference around `NULL`
## 0.10.0
- Breaking: Made `RecursiveVisitor.visit`, `visitList` and `visitExcept` an extension on `AstVisitor`.

View File

@ -98,6 +98,10 @@ class ColumnResolver extends RecursiveVisitor<void, void> {
}
final scope = e.scope;
// Add columns of the target table for when and update of clauses
scope.availableColumns = table.resolvedColumns;
if (e.target.introducesNew) {
scope.register('new', TableAlias(table, 'new'));
}
@ -260,7 +264,8 @@ class ColumnResolver extends RecursiveVisitor<void, void> {
// merge all columns at each position into a CompoundSelectColumn
for (var i = 0; i < amount; i++) {
final columnsAtThisIndex = [
for (var set in columnSets) if (set.length > i) set[i]
for (var set in columnSets)
if (set.length > i) set[i]
];
resolved.add(CompoundSelectColumn(columnsAtThisIndex));

View File

@ -1,6 +1,6 @@
name: sqlparser
description: Parses sqlite statements and performs static analysis on them
version: 0.10.0
version: 0.10.1
homepage: https://github.com/simolus3/moor/tree/develop/sqlparser
#homepage: https://moor.simonbinder.eu/
issue_tracker: https://github.com/simolus3/moor/issues

View File

@ -73,6 +73,26 @@ END;
''');
expect(context.errors, isEmpty);
});
test('can refer to column in UPDATE OF', () {
final context = engine.analyze('''
CREATE TRIGGER my_trigger BEFORE UPDATE OF content ON DEMO BEGIN
SELECT * FROM demo;
END;
''');
expect(context.errors, isEmpty);
});
test('can refer to column in UPDATE OF', () {
final context = engine.analyze('''
CREATE TRIGGER my_trigger BEFORE DELETE ON DEMO WHEN id < 10 BEGIN
SELECT * FROM demo;
END;
''');
expect(context.errors, isEmpty);
});
});
test("DO UPDATE action in upsert can refer to 'exluded'", () {