在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

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

    瀏覽量

    17828
  • 鴻蒙
    +關注

    關注

    57

    文章

    2352

    瀏覽量

    42859
收藏 人收藏

    評論

    相關推薦

    鴻蒙開發Ability Kit程序框架服務:DataAbility切換 組件切換

    FA模型中的DataAbility對應Stage模型中的DataShareExtensionAbility。
    的頭像 發表于 06-28 14:08 ?257次閱讀
    <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 ?533次閱讀
    <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 ?344次閱讀
    <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 ?444次閱讀

    鴻蒙開發組件:創建DataAbility

    實現DataAbility中Insert、Query、Update、Delete接口的業務內容。保證能夠滿足數據庫存儲業務的基本需求。BatchInsert與ExecuteBatch接口已經在系統中實現遍歷邏輯,依賴Insert、Query、Update、Delete接口邏輯,來實現數據的批量處理。
    的頭像 發表于 06-19 21:41 ?286次閱讀
    <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 ?846次閱讀
    <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 ?1169次閱讀

    鴻蒙實戰開發Camera組件:【相機】

    相機組件支持相機業務的開發開發者可以通過已開放的接口實現相機硬件的訪問、操作和新功能開發,最常見的操作如:預覽、拍照和錄像等。
    的頭像 發表于 03-08 16:20 ?624次閱讀
    <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 ?1128次閱讀

    淘寶正式啟動華為鴻蒙原生應用開發

    華為與淘寶近日宣布,淘寶已正式啟動鴻蒙原生應用開發。這一合作標志著鴻蒙生態在電商領域的布局進一步擴大,將為用戶帶來全新的全場景購物體驗。
    的頭像 發表于 01-26 15:59 ?793次閱讀

    多家頭部企業宣布「啟動鴻蒙原生應用開發」,你看好鴻蒙系統走向「獨立」嗎?

    鴻蒙生態迎「關鍵一戰」,多家頭部企業宣布「啟動鴻蒙原生應用開發」,你看好鴻蒙系統走向「獨立」嗎?
    的頭像 發表于 01-24 11:47 ?571次閱讀
    多家頭部企業宣布「<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 ?1910次閱讀
    <b class='flag-5'>鴻蒙</b>ArkUI<b class='flag-5'>開發</b>-Tabs<b class='flag-5'>組件</b>的使用

    京東正式啟動鴻蒙原生應用開發

    華為與京東于近日宣布達成一項重要合作,正式啟動鴻蒙原生應用開發。這一合作旨在利用HarmonyOS NEXT的獨特優勢,為消費者提供更出色的購物體驗。
    的頭像 發表于 01-18 15:02 ?787次閱讀

    鴻蒙開發OpenHarmony組件復用案例

    ) } }, item => item) } } } 本文主要是對鴻蒙開發基礎當中的OpenHarmony技術組件復用示例, 更多鴻蒙開發
    發表于 01-15 17:37

    鴻蒙開發基礎-Web組件之cookie操作

    }) ... } ... 本文章主要是對鴻蒙開發當中ArkTS語言的基礎應用實戰,Web組件里的cookie操作。更多的鴻蒙應用開發
    發表于 01-14 21:31
    主站蜘蛛池模板: 日韩在线一区二区| 婷婷爱爱| 欧美性受一区二区三区| 97伊人网| 午夜啪啪免费视频| 亚洲va久久久噜噜噜久久| 韩国三级床戏合集| 免费观看成年欧美1314www色| 男女一进一出抽搐免费视频| 日韩电影中文字幕| 羞羞影院男女午夜爽爽影视| sss华人在线play| 日韩种子| 天天草狠狠干| 激情久久婷婷| 久久久久青草| 国产精品一区牛牛影视| 性欧美精品久久久久久久| 国产精品资源网| 欧美黄色tv| 日本一级黄色毛片| 国内视频一区| 韩国朴银狐诱感在线观看| 国产午夜小视频| 日日做夜夜爽夜夜爽| 在线国产高清| 东莞a级毛片| 中文字幕一二三区| 免费人成在线观看网站品爱网| 欧美高清激情毛片| 亚洲国产婷婷香蕉久久久久久 | 久久久久国产一级毛片高清板| 明星三级国产免费播放| 青青伊人91久久福利精品| 亚洲无色| 午夜影吧| 一级特黄aaa大片免色| 97大香伊在人人线色| 男人j进入女人j视频大全| 国产乱码一区二区三区四川人| 五月婷婷六月丁香激情|