From 04d639b60133077ba65d324b310cfa1ca8f346d4 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 13 Jun 2024 09:02:01 +0200 Subject: [PATCH] [sqflite] fix blob doc fix #1109 --- .../sqflite_common_ffi_web/example/main.dart | 4 +- sqflite/doc/supported_types.md | 39 ------------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/packages_web/sqflite_common_ffi_web/example/main.dart b/packages_web/sqflite_common_ffi_web/example/main.dart index 428fd95f..382f3fa1 100644 --- a/packages_web/sqflite_common_ffi_web/example/main.dart +++ b/packages_web/sqflite_common_ffi_web/example/main.dart @@ -181,7 +181,7 @@ Future incrementVarInSharedWorker() async { write('var after $value'); } -Future incrementVarInBasicdWorker() async { +Future incrementVarInBasicWorker() async { var context = await webBasicContextRegisterAndReady(); write('basic worker ready'); var value = await getTestValue(context); @@ -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(); diff --git a/sqflite/doc/supported_types.md b/sqflite/doc/supported_types.md index 4f7a359a..65e27f30 100644 --- a/sqflite/doc/supported_types.md +++ b/sqflite/doc/supported_types.md @@ -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); -```