Skip to content

Commit

Permalink
[sqflite] fix blob doc fix #1109
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Jun 13, 2024
1 parent 3309d39 commit 04d639b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages_web/sqflite_common_ffi_web/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Future<void> incrementVarInSharedWorker() async {
write('var after $value');
}

Future<void> incrementVarInBasicdWorker() async {
Future<void> incrementVarInBasicWorker() async {
var context = await webBasicContextRegisterAndReady();
write('basic worker ready');
var value = await getTestValue(context);
Expand Down Expand Up @@ -246,7 +246,7 @@ void initUi() {
await incrementVarInSharedWorker();
});
addButton('increment var in basic worker', () async {
await incrementVarInBasicdWorker();
await incrementVarInBasicWorker();
});
addButton('increment sqflite value in main thread', () async {
await incrementNoWebWorker();
Expand Down
39 changes: 0 additions & 39 deletions sqflite/doc/supported_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,3 @@ int (millisSinceEpoch) or string (iso8601). SQLite `TIMESTAMP` type sometimes re

* SQLite typ: `BLOB`
* Dart type: `Uint8List`

On Android blob lookup does not work when using `Uint8List` as dart type in a query such as:

```dart
final id = Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
await db.insert('test', {'id': id, 'value': 1});
var result = await db.query('test', where: 'id = ?', whereArgs: [id]);
```

This would lead to an empty result on Android. Native implementation can not handle this in a proper way.
The solution is to use the [`hex()` SQLite function](https://sqlite.org/lang_corefunc.html#hex).

```dart
import 'package:sqflite_common/utils/utils.dart' as utils;
result = await db.query('test', where: 'hex(id) = ?', whereArgs: [utils.hex(id)]);
```

```dart
final db = await openDatabase(
inMemoryDatabasePath,
version: 1,
onCreate: (db, version) async {
await db.execute(
'CREATE TABLE test (id BLOB, value INTEGER)',
);
},
);
final id = Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
await db.insert('test', {'id': id, 'value': 1});
var result = await db.query('test', where: 'id = ?', whereArgs: [id]);
print('regular blob lookup (failing on Android)): $result');
// The compatible way to lookup for BLOBs (even work on Android) using the hex function
result = await db.query('test', where: 'hex(id) = ?', whereArgs: [utils.hex(id)]);
print('correct blob lookup: $result');
expect(result.first['value'], 1);
```

0 comments on commit 04d639b

Please sign in to comment.