js-apis-inner-ability-dataAbilityResult.md 2.3 KB
Newer Older
Z
zengyawen 已提交
1
# DataAbilityResult
M
m00512953 已提交
2

D
dy_study 已提交
3
定义DataAbility数据操作结果,通过[executeBatch](js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperexecutebatch)操作数据库时,操作结果使用DataAbilityResult对象返回。
M
m00512953 已提交
4 5 6 7 8 9 10 11

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

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

D
merge  
donglin 已提交
12 13
| 名称       | 类型  |     必填    |       说明   |
| --------  | --------  | --------    | --------    |
D
dy_study 已提交
14 15
| uri?      | string    |      否    | 指示待处理的DataAbility。例:"dataability:///com.example.xxx.xxxx"。  |
| count?     | number    |      否    | 指示受操作影响的数据数量。  |
M
m00512953 已提交
16 17

**示例:**
Z
zhongjianfei 已提交
18

M
m00512953 已提交
19 20 21 22 23 24 25
```ts
import featureAbility from '@ohos.ability.featureAbility'

let dataAbilityUri = ("dataability:///com.example.myapplication.TestDataAbility");
let DAHelper;
try {
    DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
Z
zhongjianfei 已提交
26
    if (DAHelper == null) {
M
m00512953 已提交
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
        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 {
D
dy_study 已提交
62
    DAHelper.executeBatch(dataAbilityUri, operations).then((data) => {
M
m00512953 已提交
63 64 65 66 67 68 69 70 71 72 73 74
        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));
}
```