types2: Inference for upsert clauses

This commit is contained in:
Simon Binder 2020-02-03 21:54:49 +01:00
parent 0c171c3b81
commit 8839ec75a8
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,7 @@
to `enabledExtensions` instead.
- Parse `rowid` as a valid reference when needed (`SELECT rowid FROM tbl` is now parsed correctly)
- Parse `CURRENT_TIME`, `CURRENT_DATE` and `CURRENT_TIMESTAMP`
- Parse `UPSERT` clauses for insert statements
## 0.6.0

View File

@ -85,6 +85,8 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
}
},
);
visitNullable(e.upsert, const NoTypeExpectation());
}
@override
@ -540,6 +542,18 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
return visited;
}
@override
void visitUpsertClause(UpsertClause e, TypeExpectation arg) {
_handleWhereClause(e);
visitExcept(e, e.where, arg);
}
@override
void visitDoUpdate(DoUpdate e, TypeExpectation arg) {
_handleWhereClause(e);
visitExcept(e, e.where, arg);
}
void _handleColumn(Column column) {
if (session.graph.knowsType(column)) return;
@ -561,12 +575,12 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
}
}
void _handleWhereClause(StatementWithWhere stmt) {
if (stmt.where != null) {
void _handleWhereClause(HasWhereClause e) {
if (e.where != null) {
// assume that a where statement is a boolean expression. Sqlite
// internally casts (https://www.sqlite.org/lang_expr.html#booleanexpr),
// so be lax
visit(stmt.where, const ExactTypeExpectation.laxly(ResolvedType.bool()));
visit(e.where, const ExactTypeExpectation.laxly(ResolvedType.bool()));
}
}

View File

@ -30,6 +30,10 @@ const Map<String, ResolvedType> _types = {
'SELECT (3 * 4) = ?': ResolvedType(type: BasicType.int),
'SELECT (3 / 4) = ?': ResolvedType(type: BasicType.int),
'SELECT CURRENT_TIMESTAMP = ?': ResolvedType(type: BasicType.text),
'INSERT INTO demo DEFAULT VALUES ON CONFLICT (id) WHERE ? DO NOTHING':
ResolvedType.bool(),
'INSERT INTO demo DEFAULT VALUES ON CONFLICT DO UPDATE SET id = id WHERE ?':
ResolvedType.bool(),
};
SqlEngine _spawnEngine() {