HarmonyOS/OpenHarmony应用开发API-DataAbilityResult能力

鸿蒙时代
发布于 2023-5-10 15:24
浏览
0收藏

HarmonyOS/OpenHarmony应用开发API-DataAbilityResult能力
说明:
定义dataAbility数据操作结果,通过executeBatch查询数据库信息时查询结果通过DataAbilityResult对象返回。

编译环境:
编译器版本:release3.0
Api:8
语言:js

HarmonyOS/OpenHarmony应用开发API-DataAbilityResult能力-鸿蒙开发者社区

代码示例:

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

let dataAbilityUri = ('dataability:///com.example.abilitydemo_js.DataAbility');
let DAHelper;
try {
    DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
    if (DAHelper == null) {
        console.error('DAHelper is null');
    }
} catch (err) {
    console.error('acquireDataAbilityHelper fail, error:' + JSON.stringify(err));
}

let valueBucket = {
    'name': 'DataAbilityHelper',
    'age': 18,
};
let operations = [
    {
        uri: dataAbilityUri,
        type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
        valuesBucket: valueBucket,
        predicates: null,
        expectedCount: 1,
        PredicatesBackReferences: {},
        interrupted: true,
    },
    {
        uri: dataAbilityUri,
        type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
        valuesBucket: valueBucket,
        predicates: null,
        expectedCount: 1,
        PredicatesBackReferences: {},
        interrupted: true,
    }
];

try {
    let promise = DAHelper.executeBatch(dataAbilityUri, operations).then((data) => {
        for (let i = 0; i < data.length; i++) {
            let dataAbilityResult = data[i];
            console.log('dataAbilityResult.uri: ' + dataAbilityResult.uri);
            console.log('dataAbilityResult.count: ' + dataAbilityResult.count);
        }
    }).catch(err => {
        console.error('executeBatch error: ' + JSON.stringify(err));
    });
} catch (err) {
    console.error('executeBatch error: ' + JSON.stringify(err));
}

标签
HarmonyOSOpenHarmony应用开发API-DataAbil.docx 19.29K 17次下载
收藏
回复
举报
回复
    相关推荐