• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# DataAbilityResult
2
3The **DataAbilityResult** module defines the operation result on DataAbilities. When you call [executeBatch](js-apis-inner-ability-dataAbilityHelper.md#dataabilityhelperexecutebatch) to operate the database, the operation result is returned through the **DataAbilityResult** object.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs of this module can be used only in the FA model.
9
10**System capability**: SystemCapability.Ability.AbilityRuntime.FAModel
11
12| Name      | Type |     Mandatory   |       Description  |
13| --------  | --------  | --------    | --------    |
14| uri?      | string    |      No   | URI of the DataAbility. Example: 'dataability:///com.example.xxx.xxxx'. |
15| count?     | number    |      No   | Number of rows affected by the operation. |
16
17**Example**
18
19```ts
20import featureAbility from '@ohos.ability.featureAbility';
21
22let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility');
23let DAHelper;
24try {
25    DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
26    if (DAHelper == null) {
27        console.error('DAHelper is null');
28    }
29} catch (err) {
30    console.error('acquireDataAbilityHelper fail, error:' + JSON.stringify(err));
31}
32
33let valueBucket = {
34    'name': 'DataAbilityHelperTest',
35    'age': 24,
36    'salary': 2024.20,
37};
38let operations = [
39{
40    uri: dataAbilityUri,
41    type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
42    valuesBucket: valueBucket,
43    predicates: null,
44    expectedCount: 1,
45    PredicatesBackReferences: {},
46    interrupted: true,
47},
48{
49    uri: dataAbilityUri,
50    type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
51    valuesBucket: valueBucket,
52    predicates: null,
53    expectedCount: 1,
54    PredicatesBackReferences: {},
55    interrupted: true,
56}
57];
58
59try {
60    let promise = DAHelper.executeBatch(dataAbilityUri, operations).then((data) => {
61        for (let i = 0; i < data.length; i++) {
62            let dataAbilityResult = data[i];
63            console.log('dataAbilityResult.uri: ' + dataAbilityResult.uri);
64            console.log('dataAbilityResult.count: ' + dataAbilityResult.count);
65        }
66    }).catch(err => {
67        console.error('executeBatch error: ' + JSON.stringify(err));
68    });
69} catch (err) {
70    console.error('executeBatch error: ' + JSON.stringify(err));
71}
72```
73