js-apis-inner-ability-dataAbilityResult.md 2.2 KB
Newer Older
M
m00512953 已提交
1 2 3 4 5 6 7 8 9 10 11
## DataAbilityResult

定义dataAbility数据操作结果。

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

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

D
merge  
donglin 已提交
12 13 14 15
| 名称       | 类型  |     必填    |       说明   |
| --------  | --------  | --------    | --------    |
| uri?      | string    |      否    | 指定待处理的DataAbility。例:"dataability:///com.example.xxx.xxxx"。  | 
| count?     | number    |      否    | 指示受操作影响的行数。  | 
M
m00512953 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

**示例:**
```ts
import featureAbility from '@ohos.ability.featureAbility'

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

let valueBucket = {
    "name": "DataAbilityHelperTest",
    "age": 24,
    "salary": 2024.20,
};
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));
}
```