Make rowid aliases non-nullable (#1128)

This commit is contained in:
Simon Binder 2021-04-02 21:54:31 +02:00
parent 0692182829
commit 9b6b5d1b69
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@
- New analysis checks for `RETURNING`: Disallow `table.*` syntax and aggregate expressions
- Fix resolving columns when `RETURNING` is used in an `UPDATE FROM` statement
- Fix aliases to rowid being reported as nullable
## 0.15.0

View File

@ -53,6 +53,9 @@ class Table extends NamedResultSet with HasMetaMixin implements HumanReadable {
if (_rowIdColumn == null && column.isAliasForRowId()) {
_rowIdColumn = column;
// By design, the rowid is non-nullable, even if there isn't a NOT NULL
// constraint set on the column definition.
column._type = const ResolvedType(type: BasicType.int, nullable: false);
}
}
}

View File

@ -127,4 +127,14 @@ void main() {
final table = engine.schemaReader.read(stmt as CreateTableStatement);
expect(table.resolvedColumns.single.type.type, BasicType.blob);
});
test('aliases to rowid are non-nullable', () {
final engine = SqlEngine();
final stmt =
engine.parse('CREATE TABLE foo (id INTEGER PRIMARY KEY);').rootNode;
final table = engine.schemaReader.read(stmt as CreateTableStatement);
expect(table.resolvedColumns.single.type,
const ResolvedType(type: BasicType.int, nullable: false));
});
}