0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

鸿蒙开发组件:启动与访问DataAbility

jf_46214456 来源:jf_46214456 作者:jf_46214456 2024-06-20 15:03 次阅读

启动DataAbility

启动DataAbility会获取一个工具接口类对象(DataAbilityHelper)。启动DataAbility的示例代码如下:

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

let uri: string = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(uri);

访问DataAbility

访问DataAbility需导入基础依赖包,以及获取与DataAbility子模块通信的URI字符串。

其中,基础依赖包包括: 开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

搜狗高速浏览器截图20240326151547.png

  • @ohos.ability.featureAbility
  • @ohos.data.dataAbility

访问DataAbility的示例代码如下:

  1. 创建工具接口类对象。

    import featureAbility from '@ohos.ability.featureAbility';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import ability from '@ohos.ability.ability';
    // 作为参数传递的URI,与config中定义的URI的区别是多了一个"/",有三个"/"
    let uri: string = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
    let DAHelper: ability.DataAbilityHelper = featureAbility.acquireDataAbilityHelper(uri);
    
  2. 构建数据库相关的RDB数据。

    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    let valuesBucket_insert: rdb.ValuesBucket = { name: 'Rose', introduction: 'insert' };
    let valuesBucket_update: rdb.ValuesBucket = { name: 'Rose', introduction: 'update' };
    let crowd = new Array({ name: 'Rose', introduction: 'batchInsert_one' } as rdb.ValuesBucket,
      { name: 'Rose', introduction: 'batchInsert_two' } as rdb.ValuesBucket);
    let columnArray = new Array('id', 'name', 'introduction');
    let predicates = new ohos_data_ability.DataAbilityPredicates();
    

    注:关于DataAbilityPredicates的详细内容,请参考[DataAbility谓词]。

  3. 调用insert方法向指定的DataAbility子模块插入数据。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    
    // callback方式调用:
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private valuesBucket_insert: rdb.ValuesBucket = { name: 'Rose', introduction: 'insert' };
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  this.DAHelper.insert(this.uri, this.valuesBucket_insert, (error: BusinessError, data: number) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.insert_failed_toast')
                      });
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.insert_success_toast')
                      });
                    }
                    hilog.info(domain, TAG, 'DAHelper insert result: ' + data + ', error: ' + JSON.stringify(error));
                  }
                  );
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private valuesBucket_insert: rdb.ValuesBucket = { name: 'Rose', introduction: 'insert' };
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  this.DAHelper.insert(this.uri, this.valuesBucket_insert).then((datainsert) = > {
                    promptAction.showToast({
                      message: $r('app.string.insert_success_toast')
                    });
                    hilog.info(domain, TAG, 'DAHelper insert result: ' + datainsert);
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.insert_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper insert failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
  4. 调用delete方法删除DataAbility子模块中指定的数据。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  this.DAHelper.delete(this.uri, this.predicates, (error, data) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.delete_failed_toast')
                      });
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.delete_success_toast')
                      });
                    }
                    hilog.info(domain, TAG, 'DAHelper delete result: ' + data + ', error: ' + JSON.stringify(error));
                  }
                  );
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  this.DAHelper.delete(this.uri, this.predicates).then((datadelete) = > {
                    promptAction.showToast({
                      message: $r('app.string.delete_success_toast')
                    });
                    hilog.info(domain, TAG, 'DAHelper delete result: ' + datadelete);
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.delete_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper delete failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
  5. 调用update方法更新指定DataAbility子模块中的数据。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private valuesBucket_update: rdb.ValuesBucket = { name: 'Rose', introduction: 'update' };
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  this.predicates.equalTo('name', 'Rose');
                  this.DAHelper.update(this.uri, this.valuesBucket_update, this.predicates, (error, data) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.update_failed_toast')
                      });
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.update_success_toast')
                      });
                    }
                    hilog.info(domain, TAG, 'DAHelper update result: ' + data + ', error: ' + JSON.stringify(error));
                  }
                  );
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private valuesBucket_update: rdb.ValuesBucket = { name: 'Rose', introduction: 'update' };
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  this.predicates.equalTo('name', 'Rose');
                  this.DAHelper.update(this.uri, this.valuesBucket_update, this.predicates).then((dataupdate) = > {
                    promptAction.showToast({
                      message: $r('app.string.update_success_toast')
                    });
                    hilog.info(domain, TAG, 'DAHelper update result: ' + dataupdate);
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.update_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper update failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
  6. 调用query方法在指定的DataAbility子模块中查找数据。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private columnArray = new Array('id', 'name', 'introduction');
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  this.predicates.equalTo('name', 'Rose');
                  this.DAHelper.query(this.uri, this.columnArray, this.predicates, (error, data) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.query_failed_toast')
                      });
                      hilog.error(domain, TAG, `DAHelper query failed. Cause: ${error.message}`);
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.query_success_toast')
                      });
                    }
                    // ResultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
                    while (data.goToNextRow()) {
                      const id = data.getLong(data.getColumnIndex('id'));
                      const name = data.getString(data.getColumnIndex('name'));
                      const introduction = data.getString(data.getColumnIndex('introduction'));
                      hilog.info(domain, TAG, `DAHelper query result:id = [${id}], name = [${name}], introduction = [${introduction}]`);
                    }
                    // 释放数据集的内存
                    data.close();
                  }
                  );
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private columnArray = new Array('id', 'name', 'introduction');
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  this.predicates.equalTo('name', 'Rose');
                  this.DAHelper.query(this.uri, this.columnArray, this.predicates).then((dataquery) = > {
                    promptAction.showToast({
                      message: $r('app.string.query_success_toast')
                    });
                    // ResultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
                    while (dataquery.goToNextRow()) {
                      const id = dataquery.getLong(dataquery.getColumnIndex('id'));
                      const name = dataquery.getString(dataquery.getColumnIndex('name'));
                      const introduction = dataquery.getString(dataquery.getColumnIndex('introduction'));
                      hilog.info(domain, TAG, `DAHelper query result:id = [${id}], name = [${name}], introduction = [${introduction}]`);
                    }
                    // 释放数据集的内存
                    dataquery.close();
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.query_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper query failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
  7. 调用batchInsert方法向指定的DataAbility子模块批量插入数据。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private crowd = new Array({ name: 'Rose', introduction: 'batchInsert_one' } as rdb.ValuesBucket,
        { name: 'Rose', introduction: 'batchInsert_two' } as rdb.ValuesBucket);
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  this.DAHelper.batchInsert(this.uri, this.crowd, (error, data) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.batchInsert_failed_toast')
                      });
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.batchInsert_success_toast')
                      });
                    }
                    hilog.info(domain, TAG, 'DAHelper batchInsert result: ' + data + ', error: ' + JSON.stringify(error));
                  }
                  );
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private crowd = new Array({ name: 'Rose', introduction: 'batchInsert_one' } as rdb.ValuesBucket,
        { name: 'Rose', introduction: 'batchInsert_two' } as rdb.ValuesBucket);
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  this.DAHelper.batchInsert(this.uri, this.crowd).then((databatchInsert) = > {
                    promptAction.showToast({
                      message: $r('app.string.batchInsert_success_toast')
                    });
                    hilog.info(domain, TAG, 'DAHelper batchInsert result: ' + databatchInsert);
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.batchInsert_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper batchInsert failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    
  8. 调用executeBatch方法向指定的DataAbility子模块进行数据的批量处理。

    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // callback方式调用:
                  let operations: Array< ability.DataAbilityOperation > = [{
                    uri: this.uri,
                    type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
                    valuesBucket: { name: 'Rose', introduction: 'executeBatch' },
                    predicates: this.predicates,
                    expectedCount: 0,
                    predicatesBackReferences: undefined,
                    interrupted: true,
                  }];
                  this.DAHelper.executeBatch(this.uri, operations, (error, data) = > {
                    if (error && error.code !== 0) {
                      promptAction.showToast({
                        message: $r('app.string.executeBatch_failed_toast')
                      });
                    } else {
                      promptAction.showToast({
                        message: $r('app.string.executeBatch_success_toast')
                      });
                    }
                    hilog.info(domain, TAG, `DAHelper executeBatch, result: ` + JSON.stringify(data) + ', error: ' + JSON.stringify(error));
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
       }
     }
    
    import ability from '@ohos.ability.ability';
    import featureAbility from '@ohos.ability.featureAbility';
    import { BusinessError } from '@ohos.base';
    import ohos_data_ability from '@ohos.data.dataAbility';
    import rdb from '@ohos.data.rdb';
    import promptAction from '@ohos.promptAction';
    import hilog from '@ohos.hilog';
    
    const TAG: string = 'PageDataAbility';
    const domain: number = 0xFF00;
    
    @Entry
    @Component
    struct PageDataAbility {
      private predicates = new ohos_data_ability.DataAbilityPredicates();
      private uri = 'dataability:///com.samples.famodelabilitydevelop.DataAbility';
      private DAHelper = featureAbility.acquireDataAbilityHelper(this.uri);
    
      build() {
        Column() {
          // ...
          List({ initialIndex: 0 }) {
            // ...
            ListItemGroup() {
              ListItem() {
                Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
                  // ...
                }
                .onClick(() = > {
                  // promise方式调用(await需要在async方法中使用):
                  let operations: Array< ability.DataAbilityOperation > = [{
                    uri: this.uri,
                    type: featureAbility.DataAbilityOperationType.TYPE_INSERT,
                    valuesBucket: { name: 'Rose', introduction: 'executeBatch' },
                    predicates: this.predicates,
                    expectedCount: 0,
                    predicatesBackReferences: undefined,
                    interrupted: true,
                  }];
                  this.DAHelper.executeBatch(this.uri, operations).then((dataquery) = > {
                    promptAction.showToast({
                      message: $r('app.string.executeBatch_success_toast')
                    });
                    hilog.info(domain, TAG, 'DAHelper executeBatch result: ' + JSON.stringify(dataquery));
                  }).catch((error: BusinessError) = > {
                    promptAction.showToast({
                      message: $r('app.string.executeBatch_failed_toast')
                    });
                    hilog.error(domain, TAG, `DAHelper executeBatch failed. Cause: ${error.message}`);
                  });
                })
              }
              // ...
            }
            // ...
          }
          // ...
        }
        // ...
      }
    }
    

审核编辑 黄宇

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 组件
    +关注

    关注

    1

    文章

    512

    浏览量

    17817
  • 鸿蒙
    +关注

    关注

    57

    文章

    2345

    浏览量

    42822
收藏 人收藏

    评论

    相关推荐

    鸿蒙开发Ability Kit程序框架服务:DataAbility切换 组件切换

    FA模型中的DataAbility对应Stage模型中的DataShareExtensionAbility。
    的头像 发表于 06-28 14:08 246次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>Ability Kit程序框架服务:<b class='flag-5'>DataAbility</b>切换 <b class='flag-5'>组件</b>切换

    鸿蒙开发Ability Kit程序框架服务:FA模型与Stage模型应用组件互通综述

    FA模型与Stage模型是两套不同的应用模型,他们拥有各自的组件。FA模型提供三种应用组件,分别是PageAbility、ServiceAbility和DataAbility。Stage模型提供了两种应用
    的头像 发表于 06-24 16:43 517次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>Ability Kit程序框架服务:FA模型与Stage模型应用<b class='flag-5'>组件</b>互通综述

    鸿蒙开发组件DataAbility权限控制

    DataAbility提供数据服务,并不是所有的Ability都有权限读写它,DataAbility有一套权限控制机制来保证数据安全。分为静态权限控制和动态权限控制两部分。
    的头像 发表于 06-21 10:30 336次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>组件</b>:<b class='flag-5'>DataAbility</b>权限控制

    鸿蒙开发组件DataAbility的生命周期

    应用开发者可以根据业务场景实现data.js/data.ets中的生命周期相关接口。DataAbility生命周期接口说明见下表。
    的头像 发表于 06-20 09:39 437次阅读

    鸿蒙开发组件:创建DataAbility

    实现DataAbility中Insert、Query、Update、Delete接口的业务内容。保证能够满足数据库存储业务的基本需求。BatchInsert与ExecuteBatch接口已经在系统中实现遍历逻辑,依赖Insert、Query、Update、Delete接口逻辑,来实现数据的批量处理。
    的头像 发表于 06-19 21:41 278次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>组件</b>:创建<b class='flag-5'>DataAbility</b>

    鸿蒙开发接口数据管理:【@ohos.data.dataAbility (DataAbility谓词)】

    DataAbility 谓词用于构造关系型数据库的谓词,提供用于实现不同查询方法的谓词。
    的头像 发表于 06-06 17:20 838次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>接口数据管理:【@ohos.data.<b class='flag-5'>dataAbility</b> (<b class='flag-5'>DataAbility</b>谓词)】

    哪吒汽车APP启动鸿蒙原生应用开发

    哪吒汽车正式签约,启动鸿蒙原生应用开发;在5月17日,在上海市经济和信息化委员会指导的“千帆竞发启航 共筑鸿蒙生态——HDD上海站·鸿蒙原生
    的头像 发表于 05-18 09:48 1163次阅读

    鸿蒙实战开发Camera组件:【相机】

    相机组件支持相机业务的开发开发者可以通过已开放的接口实现相机硬件的访问、操作和新功能开发,最常见的操作如:预览、拍照和录像等。
    的头像 发表于 03-08 16:20 614次阅读
    <b class='flag-5'>鸿蒙</b>实战<b class='flag-5'>开发</b>Camera<b class='flag-5'>组件</b>:【相机】

    淘宝与华为合作将基于HarmonyOS NEXT启动鸿蒙原生应用开发

    1月25日,淘宝与华为举办鸿蒙合作签约仪式,宣布将基于HarmonyOS NEXT启动鸿蒙原生应用开发
    的头像 发表于 01-26 16:14 1119次阅读

    淘宝正式启动华为鸿蒙原生应用开发

    华为与淘宝近日宣布,淘宝已正式启动鸿蒙原生应用开发。这一合作标志着鸿蒙生态在电商领域的布局进一步扩大,将为用户带来全新的全场景购物体验。
    的头像 发表于 01-26 15:59 784次阅读

    多家头部企业宣布「启动鸿蒙原生应用开发」,你看好鸿蒙系统走向「独立」吗?

    鸿蒙生态迎「关键一战」,多家头部企业宣布「启动鸿蒙原生应用开发」,你看好鸿蒙系统走向「独立」吗?
    的头像 发表于 01-24 11:47 562次阅读
    多家头部企业宣布「<b class='flag-5'>启动</b><b class='flag-5'>鸿蒙</b>原生应用<b class='flag-5'>开发</b>」,你看好<b class='flag-5'>鸿蒙</b>系统走向「独立」吗?

    鸿蒙ArkUI开发-Tabs组件的使用

    鸿蒙ArkUI开发-Tabs组件的使用
    的头像 发表于 01-19 16:01 1881次阅读
    <b class='flag-5'>鸿蒙</b>ArkUI<b class='flag-5'>开发</b>-Tabs<b class='flag-5'>组件</b>的使用

    京东正式启动鸿蒙原生应用开发

    华为与京东于近日宣布达成一项重要合作,正式启动鸿蒙原生应用开发。这一合作旨在利用HarmonyOS NEXT的独特优势,为消费者提供更出色的购物体验。
    的头像 发表于 01-18 15:02 779次阅读

    鸿蒙开发OpenHarmony组件复用案例

    ) } }, item => item) } } } 本文主要是对鸿蒙开发基础当中的OpenHarmony技术组件复用示例, 更多鸿蒙开发
    发表于 01-15 17:37

    鸿蒙开发基础-Web组件之cookie操作

    }) ... } ... 本文章主要是对鸿蒙开发当中ArkTS语言的基础应用实战,Web组件里的cookie操作。更多的鸿蒙应用开发
    发表于 01-14 21:31