提交 bd6fb839 编写于 作者: D dy_study

Description:DataAbility示例代码问题修复

Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source: No
Signed-off-by: Ndy_study <dingyao5@huawei.com>
Change-Id: Iba52d352d946e35e57e09b0a2698e6aef5b7e16c
上级 1886f753
......@@ -19,56 +19,59 @@
```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');
// 批量执行数据库操作
function executeBatchOperation() {
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;
}
} 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,
}
];
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 {
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 => {
try {
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));
});
} catch (err) {
console.error('executeBatch error: ' + JSON.stringify(err));
}
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册