国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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學習的評論 (共 條)

分享到微博請遵守國家法律
吴旗县| 东方市| 崇仁县| 淮南市| 新绛县| 南开区| 五家渠市| 巴里| 涞水县| 台南县| 自贡市| 安福县| 沙田区| 苍梧县| 连云港市| 拉孜县| 繁昌县| 黄龙县| 容城县| 通榆县| 贵南县| 宁阳县| 宁河县| 大足县| 阳原县| 龙游县| 金川县| 扎兰屯市| 梓潼县| 汝城县| 雷波县| 怀远县| 大丰市| 南雄市| 察隅县| 乌兰浩特市| 广宁县| 博湖县| 海城市| 鸡东县| 缙云县|