Skip to content

Commit

Permalink
Warn instead of bailing on unparseable queries
Browse files Browse the repository at this point in the history
  • Loading branch information
cachapa committed Jan 8, 2023
1 parent f57cd4d commit 50c20b3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.4

* Warn instead of bailing on unparseable queries

## 0.0.3

* Refactor entire project to fix transaction deadlocks
Expand Down
3 changes: 2 additions & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Future<void> main() async {
VALUES (?1, ?2)
''', [4, 'Grandma Doe']);
});
final timestamps = await crdt.query('SELECT id, hlc, modified FROM users WHERE id > 2');
final timestamps =
await crdt.query('SELECT id, hlc, modified FROM users WHERE id > 2');
printRecords('SELECT id, hlc, modified FROM users WHERE id > 2', timestamps);

// Create a changeset to synchronize with another node
Expand Down
13 changes: 11 additions & 2 deletions lib/src/base_crdt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ class BaseCrdt {
Future<void> execute(String sql, [List<Object?>? args]) async {
final result = _sqlEngine.parse(sql);

// Bail if the query can't be parsed
// Warn if the query can't be parsed
if (result.rootNode is InvalidStatement) {
throw 'Unable to parse SQL statement\n$sql';
print('Warning: unable to parse SQL statement.');
if (sql.contains(';')) {
print('The parser can only interpret single statements.');
}
print(sql);
}

// Bail on "manual" transaction statements
if (result.rootNode is BeginTransactionStatement ||
result.rootNode is CommitStatement) {
throw 'Unsupported statement: $sql.\nUse SqliteCrdt.transaction() instead.';
Expand All @@ -46,6 +52,9 @@ class BaseCrdt {
await _update(result.rootNode as UpdateStatement, args);
} else if (result.rootNode is DeleteStatement) {
await _delete(result.rootNode as DeleteStatement, args);
} else {
// Run the query unchanged
await _executor.execute(sql, args?.map(_convert).toList());
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sqlite_crdt
description: Dart implementation of Conflict-free Replicated Data Types (CRDTs) using Sqlite as storage
version: 0.0.3
version: 0.0.4
homepage: https://github.com/cachapa/sqlite_crdt
repository: https://github.com/cachapa/sqlite_crdt
issue_tracker: https://github.com/cachapa/sqlite_crdt/issues
Expand Down

0 comments on commit 50c20b3

Please sign in to comment.