diff --git a/ohos/sqflite_test/.gitignore b/ohos/sqflite_test/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..24476c5d1eb55824c76d8b01a3965f94abad1ef8 --- /dev/null +++ b/ohos/sqflite_test/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/ohos/sqflite_test/README.md b/ohos/sqflite_test/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e40901918f8d00f85d30ed64aeb6119a7ea71d92 --- /dev/null +++ b/ohos/sqflite_test/README.md @@ -0,0 +1,16 @@ +# sqflite_test + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/ohos/sqflite_test/analysis_options.yaml b/ohos/sqflite_test/analysis_options.yaml new file mode 100644 index 0000000000000000000000000000000000000000..61b6c4de17c96863d24279f06b85e01b6ebbdb34 --- /dev/null +++ b/ohos/sqflite_test/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/ohos/sqflite_test/lib/big_int_test.dart b/ohos/sqflite_test/lib/big_int_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..a96dfd0930c3c8ba7559dd64bfe408aa2455e831 --- /dev/null +++ b/ohos/sqflite_test/lib/big_int_test.dart @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:sqflite/sqflite.dart'; + +import 'info_button.dart'; + +class BigIntTest extends StatefulWidget { + const BigIntTest({super.key}); + + @override + State createState() => _BigIntTestState(); +} + +class _BigIntTestState extends State { + Database? _database; + String? _openDbResult; + String? _createTableResult; + String? _insertResult; + String? _queryResult; + String? _updateResult; + String? _updateResultByRaw; + String? _updateResultByRaw1; + String? _deleteResult; + String? _deleteResult1; + final String _tableName = "users"; + late String _dbName; + + void _openDB() async { + try { + _database = await openDatabase( + _dbName, + onCreate: (db, version) async { + await db.execute("CREATE TABLE $_tableName(id INTEGER PRIMARY KEY, name TEXT, age INTEGER, create_t UNLIMITED INT)"); + }, + version: 1, + ); + final path = await getDatabasesPath(); + setState(() { + _openDbResult = "打开数据成功:$path"; + }); + } catch (error) { + setState(() { + _openDbResult = error.toString(); + }); + } + } + + @override + void initState() { + _dbName = "${Random().nextInt(36000)}.db"; + _openDB(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: const Text("BigIntTest"), + ), + body: ListView( + children: [ + //数据库打开状态 + Text(_openDbResult ?? '数据库未打开'), + const SizedBox(height: 10), + + //插入数据 + _insertDataWidget(), + + //查询数据 + _queryWidget(), + ], + ), + ); + } + + ///插入数据 + Widget _insertDataWidget() { + return InfoButton( + title: "插入数据", + info: _insertResult, + onTap: () async { + if (_database != null) { + try { + //获取当前时间戳 + int now = DateTime.now().millisecondsSinceEpoch; + //插入数据 + final Map data = { + 'name': 'Jack', + 'age': Random().nextInt(30000), + 'create_t': now, + }; + final id = await _database!.insert(_tableName, data); + setState(() { + _insertResult = "插入数据成功:id=$id"; + }); + } catch (error) { + setState(() { + _insertResult = error.toString(); + }); + } + } + }, + ); + } + + ///查询数据 + Widget _queryWidget() { + return InfoButton( + title: "查询数据", + info: _queryResult, + onTap: () async { + if (_database != null) { + final maps = await _database!.query(_tableName); + setState(() { + _queryResult = maps.map((map) => map.toString()).join("\n"); + }); + } + }, + ); + } +} diff --git a/ohos/sqflite_test/lib/info_button.dart b/ohos/sqflite_test/lib/info_button.dart new file mode 100644 index 0000000000000000000000000000000000000000..2fa903e5459606ccaa0f85db084088a6a5ff60bd --- /dev/null +++ b/ohos/sqflite_test/lib/info_button.dart @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'package:flutter/material.dart'; + +class InfoButton extends StatelessWidget { + const InfoButton({required this.title, this.info, this.onTap, super.key}); + + final String title; + final String? info; + final VoidCallback? onTap; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onTap, + child: Container( + decoration: const BoxDecoration( + color: Color.fromARGB(255, 214, 214, 214), + borderRadius: BorderRadius.all(Radius.circular(5)), + ), + margin: const EdgeInsets.all(10), + padding: const EdgeInsets.symmetric(vertical: 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text(title), + Visibility( + visible: info != null, + child: const SizedBox( + height: 6, + )), + Visibility( + visible: info != null, + child: Text(info ?? ''), + ), + ], + ), + ), + ); + } +} diff --git a/ohos/sqflite_test/lib/main.dart b/ohos/sqflite_test/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..a2b731e2284141ebb25be9c3abca0e15260cee25 --- /dev/null +++ b/ohos/sqflite_test/lib/main.dart @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'package:flutter/material.dart'; +import './big_int_test.dart'; +import './info_button.dart'; +import './table_name_test.dart'; +import './update_test.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Flutter Demo Home Page'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: ListView(children: [ + InfoButton( + title: "表名检查", + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const TableNameTest(); + })); + }, + ), + InfoButton( + title: "触发器", + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const UpateTest(); + })); + }, + ), + InfoButton( + title: "BigInt", + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) { + return const BigIntTest(); + })); + }, + ), + ]), + ); + } +} diff --git a/ohos/sqflite_test/lib/table_name_test.dart b/ohos/sqflite_test/lib/table_name_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..a870f531406f5013269d03e7d9042eb0094906e0 --- /dev/null +++ b/ohos/sqflite_test/lib/table_name_test.dart @@ -0,0 +1,277 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:sqflite/sqflite.dart'; + +import 'info_button.dart'; + +class TableNameTest extends StatefulWidget { + const TableNameTest({super.key}); + + @override + State createState() => _TableNameTestState(); +} + +class _TableNameTestState extends State { + Database? _database; + String? _openDbResult; + String? _createTableResult; + String? _insertResult; + String? _queryResult; + String? _updateResult; + String? _updateResultByRaw; + String? _updateResultByRaw1; + String? _deleteResult; + String? _deleteResult1; + final String _tableName = "users"; + late String _dbName; + + @override + void initState() { + _dbName = "${Random().nextInt(36000)}.db"; + super.initState(); + } + + ///打开数据库 + Widget _openDbWidget() { + return InfoButton( + title: "打开数据库", + info: _openDbResult, + onTap: () async { + try { + _database = await openDatabase(_dbName); + final path = await getDatabasesPath(); + setState(() { + _openDbResult = "打开数据成功:$path"; + }); + } catch (error) { + setState(() { + _openDbResult = error.toString(); + }); + } + }, + ); + } + + ///创建表 + Widget _createTableWidget() { + return InfoButton( + title: "创建表", + info: _createTableResult, + onTap: () async { + if (_database != null) { + try { + await _database!.execute("CREATE TABLE $_tableName(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)"); + setState(() { + _createTableResult = "创建表成功"; + }); + } catch (error) { + setState(() { + _createTableResult = error.toString(); + }); + } + } + }, + ); + } + + ///插入数据 + Widget _insertDataWidget() { + return InfoButton( + title: "插入数据", + info: _insertResult, + onTap: () async { + if (_database != null) { + try { + final id = await _database!.insert(_tableName, {'name': 'John', 'age': 25}); + setState(() { + _insertResult = "插入数据成功:id=$id"; + }); + } catch (error) { + setState(() { + _insertResult = error.toString(); + }); + } + } + }, + ); + } + + ///查询数据 + Widget _queryWidget() { + return InfoButton( + title: "查询数据", + info: _queryResult, + onTap: () async { + if (_database != null) { + final maps = await _database!.query(_tableName); + setState(() { + _queryResult = maps.map((map) => map.toString()).join("\n"); + }); + } + }, + ); + } + + ///更新数据 + Widget _updateDataWidget() { + return InfoButton( + title: "更新数据", + info: _updateResult, + onTap: () async { + if (_database != null) { + try { + final changeRows = await _database!.update(_tableName, {'name': 'Jack', 'age': 25}, where: 'id = ?', whereArgs: [2]); + setState(() { + _updateResult = "更新了$changeRows行数据"; + }); + } catch (error) { + setState(() { + _updateResult = error.toString(); + }); + } + } + }, + ); + } + + ///更新数据 + Widget _updateDataByRawWidget() { + return InfoButton( + title: "更新数据-raw", + info: _updateResultByRaw, + onTap: () async { + if (_database != null) { + try { + final changeRows = + await _database!.rawUpdate('UPDATE $_tableName SET name = ?, age = ? WHERE id = ?', ['Jack', 25, 1]); + setState(() { + _updateResultByRaw = "更新了$changeRows行数据"; + }); + } catch (error) { + setState(() { + _updateResultByRaw = error.toString(); + }); + } + } + }, + ); + } + + ///更新数据 + Widget _updateDataByRawWidget1() { + return InfoButton( + title: "更新数据-raw", + info: _updateResultByRaw1, + onTap: () async { + if (_database != null) { + try { + final changeRows = await _database! + .rawUpdate('UPDATE OR ROLLBACK $_tableName Set name = ?, age = ? WHERE name = ?', ['Marco', 25, "Jack"]); + setState(() { + _updateResultByRaw1 = "更新了$changeRows行数据"; + }); + } catch (error) { + setState(() { + _updateResultByRaw1 = error.toString(); + }); + } + } + }, + ); + } + + Widget _deleteDataByRawWidget() { + return InfoButton( + title: "删除数据-raw", + info: _deleteResult, + onTap: () async { + if (_database != null) { + try { + int count = await _database!.rawDelete("DELETE FROM $_tableName WHERE id = ?", [2]); + setState(() { + _deleteResult = "删除成功,删除了$count行数据"; + }); + } catch (e) { + setState(() { + _deleteResult = e.toString(); + }); + } + } + }, + ); + } + + Widget _deleteDataByRawWidget1() { + return InfoButton( + title: "删除数据-raw-1", + info: _deleteResult1, + onTap: () async { + try { + if (_database != null) { + int count = await _database!.rawDelete("DELETE OR ROLLBACK FROM $_tableName WHERE id = ?", [3, 4]); + setState(() { + _deleteResult1 = "删除成功,删除了$count行数据"; + }); + } + } catch (e) { + setState(() { + _deleteResult1 = e.toString(); + }); + } + }, + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: const Text("表名检查"), + ), + body: ListView( + children: [ + //打开数据库 + _openDbWidget(), + + //创建表 + _createTableWidget(), + + //插入数据 + _insertDataWidget(), + + //查询数据 + _queryWidget(), + + //更新数据 + _updateDataWidget(), + //更新数据-raw + _updateDataByRawWidget(), + //更新数据-raw + _updateDataByRawWidget1(), + + //删除数据 + _deleteDataByRawWidget(), + // //删除数据 + // _deleteDataByRawWidget1(), + ], + ), + ); + } +} diff --git a/ohos/sqflite_test/lib/update_test.dart b/ohos/sqflite_test/lib/update_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..5957fd391b488e148073dad1678ffc00886bd756 --- /dev/null +++ b/ohos/sqflite_test/lib/update_test.dart @@ -0,0 +1,352 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:sqflite/sqflite.dart'; + +import 'info_button.dart'; + +class UpateTest extends StatefulWidget { + const UpateTest({super.key}); + + @override + State createState() => _UpateTestState(); +} + +class _UpateTestState extends State { + List btnArray = []; + Database? _database; + String? _openDbResult; + String? _createTableResult; + String? _insertResult; + String? _queryResult; + String? _updateResult; + String? _updateResultByRaw; + String? _updateResultByRaw1; + String? _deleteResult; + String? _deleteResult1; + final String _tableName = "mh_habits"; + late String _dbName; + String uuid = ''; + + @override + void initState() { + _dbName = "${Random().nextInt(36000)}.db"; + _openDB(); + super.initState(); + } + + void _openDB() async { + try { + _database = await openDatabase( + _dbName, + onCreate: (db, version) async { + await db.execute('''CREATE TABLE IF NOT EXISTS $_tableName ( + id_ INTEGER PRIMARY KEY AUTOINCREMENT, + type_ INTEGER NOT NULL, + create_t INTEGER NOT NULL DEFAULT (cast(strftime('%s','now') as int)), + modify_t INTEGER NOT NULL DEFAULT (cast(strftime('%s','now') as int)), + uuid TEXT NOT NULL UNIQUE, + status INTEGER NOT NULL, + name TEXT, + desc TEXT, + color INTEGER, + daily_goal REAL NOT NULL, + daily_goal_unit TEXT NOT NULL, + daily_goal_extra REAL, + freq_type INTEGER, + freq_custom TEXT, + start_date INTEGER NOT NULL, + target_days INTEGER, + remind_cutsom TEXT, + remind_question TEXT, + sort_position REAL NOT NULL DEFAULT 9e999 +)'''); + await db.execute( + ''' + CREATE TRIGGER item_update_trigger + AFTER UPDATE ON $_tableName + BEGIN + UPDATE $_tableName + SET name = '触发器更改名称' + WHERE uuid = NEW.uuid; + END + ''', + ); + }, + version: 1, + ); + final path = await getDatabasesPath(); + setState(() { + _openDbResult = "打开数据成功:$path"; + }); + } catch (error) { + setState(() { + _openDbResult = error.toString(); + }); + } + } + + ///打开数据库 + Widget _openDbWidget() { + return InfoButton( + title: "打开数据库", + info: _openDbResult, + onTap: () async {}, + ); + } + + ///创建表 + Widget _createTableWidget() { + return InfoButton( + title: "创建表", + info: _createTableResult, + onTap: () async { + if (_database != null) { + try { + await _database!.execute('''CREATE TABLE IF NOT EXISTS $_tableName ( + id_ INTEGER PRIMARY KEY AUTOINCREMENT, + type_ INTEGER NOT NULL, + create_t INTEGER NOT NULL DEFAULT (cast(strftime('%s','now') as int)), + modify_t INTEGER NOT NULL DEFAULT (cast(strftime('%s','now') as int)), + uuid TEXT NOT NULL UNIQUE, + status INTEGER NOT NULL, + name TEXT, + desc TEXT, + color INTEGER, + daily_goal REAL NOT NULL, + daily_goal_unit TEXT NOT NULL, + daily_goal_extra REAL, + freq_type INTEGER, + freq_custom TEXT, + start_date INTEGER NOT NULL, + target_days INTEGER, + remind_cutsom TEXT, + remind_question TEXT, + sort_position REAL NOT NULL DEFAULT 9e999 +)'''); + setState(() { + _createTableResult = "创建表成功"; + }); + } catch (error) { + setState(() { + _createTableResult = error.toString(); + }); + } + } + }, + ); + } + + ///插入数据 + Widget _insertDataWidget() { + return InfoButton( + title: "插入数据", + info: _insertResult, + onTap: () async { + if (_database != null) { + try { + //获取当前时间戳 + int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; + //插入数据 + final Map data = { + 'type_': Random().nextInt(30000), + 'create_t': now, + 'modify_t': now, + 'uuid': Random().nextInt(30000).toInt().toString(), + 'status': 1, + 'name': 'Jack', + 'desc': 'uewoqiusjkashdwqioeuasdjkh', + 'color': 1, + 'daily_goal': 1.968, + 'daily_goal_unit': 2.3679, + 'daily_goal_extra': 1.2345, + 'freq_type': 1, + 'freq_custom': '1,2,3', + 'start_date': now, + 'target_days': 30, + 'remind_cutsom': '1,2,3', + 'remind_question': '你好', + 'sort_position': 1.2345 + }; + final id = await _database!.insert(_tableName, data); + setState(() { + _insertResult = "插入数据成功:id=$id"; + }); + } catch (error) { + setState(() { + _insertResult = error.toString(); + }); + } + } + }, + ); + } + + ///查询数据 + Widget _queryWidget() { + return InfoButton( + title: "查询数据", + info: _queryResult, + onTap: () async { + if (_database != null) { + final maps = await _database!.query(_tableName); + uuid = maps.first["uuid"] as String; + print("uuid--------------:$uuid"); + setState(() { + _queryResult = maps.map((map) => map.toString()).join("\n"); + }); + } + }, + ); + } + + ///更新数据 + Widget _updateDataWidget() { + return InfoButton( + title: "更新数据", + info: _updateResult, + onTap: () async { + if (_database != null) { + try { + final changeRows = + await _database!.update(_tableName, {'name': 'Maco', 'desc': '这是更新后的描述'}, where: 'uuid = ?', whereArgs: [uuid]); + setState(() { + _updateResult = "更新了$changeRows行数据"; + }); + } catch (error) { + setState(() { + _updateResult = error.toString(); + }); + } + } + }, + ); + } + + ///更新数据 + Widget _updateDataByRawWidget() { + //触发器 + final trgger = ''' + CREATE TRIGGER item_update_trigger + AFTER UPDATE ON $_tableName + BEGIN + UPDATE $_tableName SET name = '触发器更改名称' WHERE uuid = $uuid; + END; + '''; + return InfoButton( + title: "更新数据-raw- 触发器方式", + info: _updateResultByRaw, + onTap: () async { + if (_database != null) { + try { + final changeRows = await _database! + .rawUpdate('UPDATE $_tableName SET name = ?, desc = ? WHERE uuid = ?', ['Marry', '这是不带回滚操作的描述更新', uuid]); + // await _database!.execute(trgger); + setState(() { + _updateResultByRaw = "更新了$changeRows行数据"; + // _updateResultByRaw = "更新了数据"; + }); + } catch (error) { + setState(() { + _updateResultByRaw = error.toString(); + }); + } + } + }, + ); + } + + ///更新数据 + Widget _updateDataByRawWidget1() { + return InfoButton( + title: "更新数据-raw", + info: _updateResultByRaw1, + onTap: () async { + if (_database != null) { + try { + final changeRows = await _database!.rawUpdate( + 'UPDATE OR ROLLBACK $_tableName SET name = ?, desc = ? WHERE uuid = ?', ['Marry', '这是带回滚操作的描述更新', uuid]); + setState(() { + _updateResultByRaw1 = "更新了$changeRows行数据"; + }); + } catch (error) { + setState(() { + _updateResultByRaw1 = error.toString(); + }); + } + } + }, + ); + } + + Widget _deleteDataByRawWidget() { + return InfoButton( + title: "删除数据-raw", + info: _deleteResult, + onTap: () async { + if (_database != null) { + try { + int count = await _database!.rawDelete("DELETE FROM $_tableName WHERE id_ = ?", [2]); + setState(() { + _deleteResult = "删除成功,删除了$count行数据"; + }); + } catch (e) { + setState(() { + _deleteResult = e.toString(); + }); + } + } + }, + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: const Text("触发器"), + ), + body: ListView( + children: [ + // //打开数据库 + // _openDbWidget(), + + // //创建表 + // _createTableWidget(), + + //插入数据 + _insertDataWidget(), + + //查询数据 + _queryWidget(), + + //更新数据 + _updateDataWidget(), + //更新数据-raw + // _updateDataByRawWidget(), + //更新数据-raw + // _updateDataByRawWidget1(), + + //删除数据 + _deleteDataByRawWidget(), + ], + ), + ); + } +} diff --git a/ohos/sqflite_test/ohos/.gitignore b/ohos/sqflite_test/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6ca13b3170eec5dd5ac5ad7f1c4dd0118845f473 --- /dev/null +++ b/ohos/sqflite_test/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/ohos/sqflite_test/ohos/AppScope/app.json5 b/ohos/sqflite_test/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..babfa1faf62d91b1e2a01cf35adc23cc64c203d0 --- /dev/null +++ b/ohos/sqflite_test/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.sqflite_test", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ohos/sqflite_test/ohos/AppScope/resources/base/element/string.json b/ohos/sqflite_test/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..880fe26fe4d4150901f07f2f38301874a3a49c81 --- /dev/null +++ b/ohos/sqflite_test/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "sqflite_test" + } + ] +} diff --git a/ohos/sqflite_test/ohos/AppScope/resources/base/media/app_icon.png b/ohos/sqflite_test/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/sqflite_test/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/ohos/sqflite_test/ohos/build-profile.json5 b/ohos/sqflite_test/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0d8b167e6cea7b597c49097ab38d3e9ff785a24f --- /dev/null +++ b/ohos/sqflite_test/ohos/build-profile.json5 @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/.gitignore b/ohos/sqflite_test/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2795a1c5b1fe53659dd1b71d90ba0592eaf7e043 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/.gitignore @@ -0,0 +1,7 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/build-profile.json5 b/ohos/sqflite_test/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..633d360fbc91a3186a23b66ab71b27e5618944cb --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/hvigorfile.ts b/ohos/sqflite_test/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/ohos/sqflite_test/ohos/entry/oh-package.json5 b/ohos/sqflite_test/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..803b25293388deda7b9a05a21b5aeadeb716b4d5 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/ohos/sqflite_test/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8bc48be8773196f34cccb15cf517f87f5c6b94d2 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + } +} diff --git a/ohos/sqflite_test/ohos/entry/src/main/ets/pages/Index.ets b/ohos/sqflite_test/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets b/ohos/sqflite_test/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee53fcd55db4e012a3d9e964ac553e523afecc70 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FlutterEngine, Log } from '@ohos/flutter_ohos'; + +/** + * Generated file. Do not edit. + * This file is generated by the Flutter tool based on the + * plugins that support the Ohos platform. + */ + +const TAG = "GeneratedPluginRegistrant"; + +export class GeneratedPluginRegistrant { + + static registerWith(flutterEngine: FlutterEngine) { + try { + } catch (e) { + Log.e( + TAG, + "Tried to register plugins with FlutterEngine (" + + flutterEngine + + ") failed."); + Log.e(TAG, "Received exception while registering", e); + } + } +} diff --git a/ohos/sqflite_test/ohos/entry/src/main/module.json5 b/ohos/sqflite_test/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7bbf78b18f39991b1404061c7437538c7d532bb7 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/module.json5 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + {"name" : "ohos.permission.INTERNET"}, + ] + } +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/color.json b/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/string.json b/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e48133d507935f2073f7b8a851df9a0258c46b5d --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "sqflite_test" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/base/media/icon.png b/ohos/sqflite_test/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/sqflite_test/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/base/profile/main_pages.json b/ohos/sqflite_test/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/en_US/element/string.json b/ohos/sqflite_test/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e48133d507935f2073f7b8a851df9a0258c46b5d --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "sqflite_test" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/main/resources/zh_CN/element/string.json b/ohos/sqflite_test/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..21a2c0e6cf6313d8f0ef8c8fdb9c941684ae93a8 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "sqflite_test" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..25d4c71ff3cd584f5d64f6f8c0ac864928c234c4 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain',0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc' + let b = 'b' + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/List.test.ets b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4140030e65d20df6af30a6bf51e464dea8f8aa6 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ca645e6013cfce8e7dbb728313cb8840c4da660 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cef0447cd2f137ef82d223ead2e156808878ab90 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1def08f2e9dcbfa3454a07b7a3b82b173bb90d02 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/module.json5 b/ohos/sqflite_test/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fab77ce2e0c61e3ad010bab5b27ccbd15f9a8c96 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/color.json b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/string.json b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/media/icon.png b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ohos/sqflite_test/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ohos/sqflite_test/ohos/hvigor/hvigor-config.json5 b/ohos/sqflite_test/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..541ba35711b75986f9295410ee38fdb8f2572878 --- /dev/null +++ b/ohos/sqflite_test/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/hvigorfile.ts b/ohos/sqflite_test/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f2d2aafe6d6a3a71a9944ebd0c91fbc308ac9d1 --- /dev/null +++ b/ohos/sqflite_test/ohos/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ohos/sqflite_test/ohos/oh-package.json5 b/ohos/sqflite_test/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f1e7062375f243c7de3ccba0c1d49448b2564916 --- /dev/null +++ b/ohos/sqflite_test/ohos/oh-package.json5 @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "modelVersion": "5.0.0", + "name": "sqflite_test", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} diff --git a/ohos/sqflite_test/pubspec.yaml b/ohos/sqflite_test/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..641e74c3c5689ce1be74eff9491e2a79fa0cee33 --- /dev/null +++ b/ohos/sqflite_test/pubspec.yaml @@ -0,0 +1,94 @@ +name: sqflite_test +description: A new Flutter project. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=2.19.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + sqflite: + git: + url: https://gitee.com/openharmony-sig/flutter_sqflite.git + path: sqflite + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages