diff --git a/sqflite/example/lib/open_test_page.dart b/sqflite/example/lib/open_test_page.dart index c6587da76355569d0787b2b87bb05b23d76df1fe..7fd4d3dac158dcf283c560a1e829a7da26d183ee 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 e20ddf4b40b64292faa88ceaa5c6f5b672a1dab6..5fcdb1388ee30535bfadf1f1ed966e517aa9101b 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/Database.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/Database.ets index db9fb2d93245a4d95e47e864cd5085be788f5683..b7587489dfbd70abbd7140521cb278bd5db06743 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 4c843ed1d28582747966350473b2973d2586bb1c..8ee7ad109d39d90ab3854b5ba7040878dbadd54d 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/operation/BaseReadOperation.ets b/sqflite/ohos/src/main/ets/io/flutter/plugins/sqflite/operation/BaseReadOperation.ets index 9715e4b52081d41e7bbe69b73bc8e9146b218014..c590eddbae417369feed87ef2d2e22c2b6c2c3d0 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; } 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 d13224f53c0c75e20d3b10cbb12eba2765b88b77..6ccc241e528ccf7eb4808e33629e724c62dd028b 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) => {