Escape column names in updates

This commit is contained in:
Simon Binder 2020-05-04 20:15:23 +02:00
parent 348fb655ce
commit 79294e248a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,7 @@
## 3.0.2
- Fix update statements not escaping column names ([#539](https://github.com/simolus3/moor/issues/539))
## 3.0.1
- Fix `mapFromRowOrNull` not working without a prefix ([#534](https://github.com/simolus3/moor/pull/534))

View File

@ -23,7 +23,7 @@ class UpdateStatement<T extends Table, D extends DataClass> extends Query<T, D>
first = false;
}
ctx.buffer..write(columnName)..write(' = ');
ctx.buffer..write(escapeIfNeeded(columnName))..write(' = ');
variable.writeInto(ctx);
});

View File

@ -1,6 +1,6 @@
name: moor
description: Moor is a safe and reactive persistence library for Dart applications
version: 3.0.1
version: 3.0.2
repository: https://github.com/simolus3/moor
homepage: https://moor.simonbinder.eu/
issue_tracker: https://github.com/simolus3/moor/issues

View File

@ -52,7 +52,7 @@ void main() {
'INSERT INTO todos (content) VALUES (?)',
'UPDATE users SET name = ?;',
'UPDATE users SET name = ? WHERE name = ?;',
'UPDATE categories SET desc = ? WHERE id = ?;',
'UPDATE categories SET `desc` = ? WHERE id = ?;',
'DELETE FROM categories WHERE 1;',
'DELETE FROM todos WHERE id = ?;',
],

View File

@ -54,6 +54,15 @@ void main() {
[1, 3],
));
});
test('with escaped column names', () async {
await db
.update(db.pureDefaults)
.write(const PureDefaultsCompanion(txt: Value('foo')));
verify(executor
.runUpdate('UPDATE pure_defaults SET `insert` = ?;', ['foo']));
});
});
group('generates replace statements', () {