最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

鴻蒙ArkTS Rdb學習

2023-04-02 00:46 作者:起個名好難還被占用  | 我要投稿

import Rdb from '@ohos.data.rdb';
import CommonConstants from '../common/constants/CommonConstants';

@Entry
@Component
struct Index {
?@State message: string = 'Hello World';
?private context = getContext(this);
?private rdbStore: Rdb.RdbStore;
?private tableName = 'student';
?private columns: Array<string> = ['id', 'name', 'age', 'gender']

?createRdbStore() {
? ?const STORE_CONFIG = { name: "RdbTest.db"}
? ?Rdb.getRdbStore(this.context, STORE_CONFIG, 1)
? ? ?.then((rdbStore) => {
? ? ? ?this.rdbStore = rdbStore;
? ? ? ?console.log("Get RdbStore successfully.")
? ? ?}).catch((err) => {
? ? ? ?console.log("Get RdbStore failed, err: " + `${err.code} + ${err.message}`)
? ? ?})
?}

?createTable() {
? ?let sqlCreate = 'CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY AUTOINCREMENT, name string, ' +
? ?'gender boolean, age INTEGER)';
? ?this.rdbStore.executeSql(sqlCreate)
? ? ?.then(() => {
? ? ? ?console.info('Create table done.')
? ? ?}).catch((error) => {
? ? ? ?console.log(`createTable failed ${error.code} ? ${error.message}`);
? ? ?})
?}

?insert() {
? ?const valueBucket = {
? ? ?"name": "Lisa",
? ? ?"age": 18,
? ? ?"gender": true
? ?}
? ?this.rdbStore.insert(this.tableName, valueBucket)
? ? ?.then((rowId) => {
? ? ? ?console.log("Insert is successful, rowId = " + JSON.stringify(rowId));
? ? ?}).catch((error) => {
? ? ? ?console.log(`insert failed ${error.code} ? ${error.message}`);
? ? ?})
?}

?query() {
? ?let predicates = new Rdb.RdbPredicates(this.tableName)
? ?this.rdbStore.query(predicates, this.columns)
? ? ?.then((resultSet) => {
? ? ? ?console.log("ResultSet column names: " + resultSet.columnNames)
? ? ? ?console.log("ResultSet column count: " + resultSet.columnCount)
? ? ? ?this.dealWithResultSet(resultSet)
? ? ?}).catch((error) => {
? ? ? ?console.log(`query failed ${error.code} ? ${error.message}`);
? ? ?})
?}

?dealWithResultSet(resultSet) {
? ?let count = resultSet.rowCount;
? ?if (count === 0 || typeof count === 'string') {
? ? ?console.log(`${CommonConstants.TABLE_TAG}` + 'Query no results!');
? ?} else {
? ? ?resultSet.goToFirstRow();
? ? ?const result = [];
? ? ?for (let i = 0; i < count; i++) {
? ? ? ?let tmp = {'id': 0, 'name': '', 'age': 0, 'gender': true}
? ? ? ?tmp.id = resultSet.getDouble(resultSet.getColumnIndex('id'));
? ? ? ?tmp.name = resultSet.getDouble(resultSet.getColumnIndex('name'));
? ? ? ?tmp.age = resultSet.getString(resultSet.getColumnIndex('age'));
? ? ? ?tmp.gender = resultSet.getDouble(resultSet.getColumnIndex('gender'));
? ? ? ?result[i] = tmp;
? ? ? ?resultSet.goToNextRow();
? ? ?}
? ? ?console.info(JSON.stringify(result))
? ?}
?}

?build() {
? ?Row() {
? ? ?Column() {
? ? ? ?Text(this.message)
? ? ? ? ?.fontSize(50)
? ? ? ? ?.fontWeight(FontWeight.Bold)
? ? ? ?Button('createRdbStore')
? ? ? ? ?.onClick(() => {
? ? ? ? ? ?this.createRdbStore();
? ? ? ? ?})
? ? ? ?Button('createTable')
? ? ? ? ?.onClick(() => {
? ? ? ? ? ?this.createTable();
? ? ? ? ?})
? ? ? ?Button('insert')
? ? ? ? ?.onClick(() => {
? ? ? ? ? ?this.insert();
? ? ? ? ?})
? ? ? ?Button('query')
? ? ? ? ?.onClick(() => {
? ? ? ? ? ?this.query();
? ? ? ? ?})
? ? ?}
? ? ?.width('100%')
? ?}
? ?.height('100%')
?}
}

鴻蒙ArkTS Rdb學習的評論 (共 條)

分享到微博請遵守國家法律
宝兴县| 镶黄旗| 青川县| 醴陵市| 博乐市| 德清县| 崇文区| 景德镇市| 柞水县| 同江市| 鹤庆县| 张家港市| 乡城县| 潼南县| 天等县| 榆社县| 万源市| 江达县| 大理市| 社会| 益阳市| 株洲市| 任丘市| 沁水县| 古丈县| 深州市| 浮山县| 吉安县| 渝中区| 龙泉市| 栾川县| 宁海县| 论坛| 屯留县| 镇康县| 南康市| 安泽县| 广水市| 潢川县| 灵寿县| 涿鹿县|