harmony 鸿蒙DataAbilityResult

  • 2022-12-13
  • 浏览 (606)

DataAbilityResult

定义DataAbility数据操作结果,通过executeBatch操作数据库时,操作结果使用DataAbilityResult对象返回。

说明:

本接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 本接口仅可在FA模型下使用

导入模块

import ability from '@ohos.ability.ability';

属性

系统能力:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.FAModel

名称 类型 必填 说明
uri? string 指示待处理的DataAbility。例:’dataability:///com.example.xxx.xxxx’。
count? number 指示受操作影响的数据数量。

示例:

import ability from '@ohos.ability.ability';
import featureAbility from '@ohos.ability.featureAbility';
import rdb from '@ohos.data.rdb';

// 批量执行数据库操作
function executeBatchOperation() {
    let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility');
    let DAHelper: ability.DataAbilityHelper;
    DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);

    let valueBucket: rdb.ValuesBucket = {
        'name': 'DataAbilityHelperTest',
        'age': 24,
        'salary': 2024.20,
    };
    let predicateBackReferences = new Map<number, number>()
    predicateBackReferences.set(1, 1)

    let operations: Array<ability.DataAbilityOperation> = [
        {
            uri: dataAbilityUri,
            type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
            valuesBucket: valueBucket,
            expectedCount: 1,
            predicatesBackReferences: predicateBackReferences,
            interrupted: true,
        },
        {
            uri: dataAbilityUri,
            type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
            valuesBucket: valueBucket,
            expectedCount: 1,
            predicatesBackReferences: predicateBackReferences,
            interrupted: true,
        }
    ];
    try {
        DAHelper.executeBatch(dataAbilityUri, operations).then((data) => {
            for (let i = 0; i < data.length; i++) {
                let dataAbilityResult: ability.DataAbilityResult = data[i];
                console.log('dataAbilityResult.uri: ${dataAbilityResult.uri}');
                console.log('dataAbilityResult.count: ${dataAbilityResult.count}');
            }
        }).catch((err: BusinessError) => {
            console.error(`executeBatch error: ${JSON.stringify(err)}`);
        });
    } catch (err) {
        console.error(`executeBatch error: ${JSON.stringify(err)}`);
    }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

0  赞