From 174c1cca118d77950eb6ca7eea0e255b4518b6ee Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Sun, 11 Aug 2024 18:29:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0readonly?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2、修复关闭数据库无效问题。 3、只读类型数据库错误信息特殊处理 Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../main/ets/io/flutter/plugins/sqflite/Database.ets | 5 ++++- .../ets/io/flutter/plugins/sqflite/SqflitePlugin.ets | 2 +- .../ets/io/flutter/plugins/sqflite/sqflite_helper.ets | 10 +++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/Database.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/Database.ets index db9fb2d..b758748 100644 --- a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/Database.ets +++ b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/Database.ets @@ -57,7 +57,10 @@ export class Database { private static handleException(operation: Operation, err: BusinessError) { let code = err.code; let message = err.message; - operation.error(Constant.SQLITE_ERROR, message + '' + code, ''); + if (code == 801) { + message = message + " Database is readonly" + } + operation.error(Constant.SQLITE_ERROR, 'error code:' + code + '。' + message, ''); } private static async executeOrError(operation: Operation, db: relationalStore.RdbStore, callback?: HandleCallback): Promise { diff --git a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/SqflitePlugin.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/SqflitePlugin.ets index 4c843ed..8ee7ad1 100644 --- a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/SqflitePlugin.ets +++ b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/SqflitePlugin.ets @@ -276,7 +276,7 @@ export default class SqflitePlugin extends SqfliteApi implements FlutterPlugin, if (rdbStore == null) { return; } - SqfLiteHelper.closeDataBase(call, result); + await SqfLiteHelper.closeDataBase(call, result); } diff --git a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/sqflite_helper.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/sqflite_helper.ets index d13224f..6ccc241 100644 --- a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/sqflite_helper.ets +++ b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/sqflite_helper.ets @@ -103,13 +103,13 @@ export class SqfLiteHelper { name: dbName, // 数据库文件名 securityLevel: relationalStore.SecurityLevel.S1, // 数据库安全级别 customDir: customDir, - // isReadOnly:readOnly + isReadOnly:readOnly }; } else { config = { name: dbName, // 数据库文件名 securityLevel: relationalStore.SecurityLevel.S1, // 数据库安全级别 - // isReadOnly:readOnly + isReadOnly:readOnly } } @@ -215,11 +215,15 @@ export class SqfLiteHelper { } /// 关闭一个数据库 - public static closeDataBase(call: MethodCall, result: MethodResult): void { + public static async closeDataBase(call: MethodCall, result: MethodResult): Promise { let databaseId: number = call.argument(Constant.PARAM_ID); let dataBaseName: string | undefined = SqfLiteHelper.dBIdList.get(databaseId); if (dataBaseName == undefined) return; if (SqfLiteHelper.dataBaseList.has(dataBaseName)) { + let local: relationalStore.RdbStore | null = SqfLiteHelper.getOnlyLocal(dataBaseName); + if (local != null) { + await local.close(); + } SqfLiteHelper.dataBaseList.delete(dataBaseName); let id: number = -1; SqfLiteHelper.dBIdList.forEach((value, key) => { -- Gitee From 82899b16448ac06dc66f0dc3f038de69fd33cd15 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Mon, 12 Aug 2024 22:21:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbatch=E6=93=8D=E4=BD=9CNo?= =?UTF-8?q?Result=E4=B8=BAtrue=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=8F=8A=E5=A2=9E=E5=8A=A0double=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- sqflite/example/lib/open_test_page.dart | 4 ++- sqflite/example/lib/type_test_page.dart | 28 +++++++++++++++++++ .../sqflite/operation/BaseReadOperation.ets | 10 +++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/sqflite/example/lib/open_test_page.dart b/sqflite/example/lib/open_test_page.dart index c6587da..7fd4d3d 100644 --- a/sqflite/example/lib/open_test_page.dart +++ b/sqflite/example/lib/open_test_page.dart @@ -621,6 +621,7 @@ class OpenTestPage extends TestPage { // Copy from asset final data = await rootBundle.load(join('assets', 'example.db')); final bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); + //这里有问题,无法正确写进去 await writeFileAsBytes(path, bytes); // open the database @@ -827,6 +828,7 @@ class OpenTestPage extends TestPage { { late Database db; try { + //这里有问题,14800030 db = await factory.openDatabase(path, options: OpenDatabaseOptions(readOnly: true)); } catch (e) { print('open error'); @@ -842,7 +844,7 @@ class OpenTestPage extends TestPage { expect(await readFileAsString(path), 'dummy'); } - //这里有问题,要用到readonly接口才能解决 + expect(await isDatabase(path), isFalse); // try read-write const minExpectedSize = 1000; diff --git a/sqflite/example/lib/type_test_page.dart b/sqflite/example/lib/type_test_page.dart index e20ddf4..5fcdb13 100644 --- a/sqflite/example/lib/type_test_page.dart +++ b/sqflite/example/lib/type_test_page.dart @@ -67,6 +67,29 @@ class TypeTestPage extends TestPage { await data.db.close(); }); + test('double', () async { + //await Sqflite.devSetDebugModeOn(true); + final path = await initDeleteDb('type_double.db'); + data.db = await openDatabase(path, version: 1, + onCreate: (Database db, int version) async { + await db + .execute('CREATE TABLE Test (id INTEGER PRIMARY KEY, value double)'); + }); + var id = await insertValue(-1.1); + expect(await getValue(id), -1.1); + + id = await insertValue(198379342429.1); + final num = await getValue(id) as double; + expect(num, 198379342429.1); + + id = await insertValue(pow(2, 32) + .1); + final num1 = await getValue(id) as double; + final num2 = await getValue(id) as double; + expect(num1, num2); + + await data.db.close(); + }); + test('real', () async { //await Sqflite.devSetDebugModeOn(true); final path = await initDeleteDb('type_real.db'); @@ -77,6 +100,11 @@ class TypeTestPage extends TestPage { }); var id = await insertValue(-1.1); expect(await getValue(id), -1.1); + + id = await insertValue(198379342429.1); + double num = await getValue(id) as double; + expect(await getValue(id), 198379342429.1); + // big float id = await insertValue(1 / 3); expect(await getValue(id), 1 / 3); diff --git a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/operation/BaseReadOperation.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/operation/BaseReadOperation.ets index 9715e4b..c590edd 100644 --- a/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/operation/BaseReadOperation.ets +++ b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/operation/BaseReadOperation.ets @@ -45,17 +45,15 @@ export abstract class BaseReadOperation implements Operation { } getNoResult(): boolean { - if(this.getArgument(Constant.PARAM_NO_RESULT) instanceof Boolean) { - let result: boolean = this.getArgument(Constant.PARAM_NO_RESULT); - return result; + if(this.getArgument(Constant.PARAM_NO_RESULT)) { + return true; } return false; } getContinueOnError(): boolean { - if(this.getArgument(Constant.PARAM_CONTINUE_OR_ERROR) instanceof Boolean) { - let result: boolean = this.getArgument(Constant.PARAM_CONTINUE_OR_ERROR); - return result; + if(this.getArgument(Constant.PARAM_CONTINUE_OR_ERROR)) { + return true; } return false; } -- Gitee