diff --git a/en/application-dev/database/database-datashare-guidelines.md b/en/application-dev/database/database-datashare-guidelines.md index 95001df839e0d5ef56bc12126f0fdcd59c72db30..f0011c591effd0b65df7d1d7911c63907d6e73f8 100644 --- a/en/application-dev/database/database-datashare-guidelines.md +++ b/en/application-dev/database/database-datashare-guidelines.md @@ -13,7 +13,7 @@ The **DataShare** module allows an application to manage its own data and share |query?(uri: string, predicates: DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>): void|Queries data from the database.| |delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback<number>): void|Deletes data from the database.| -For more information, see [DataShareExtensionAbility](../reference/apis/js-apis-application-dataShareExtensionAbility.md). +For details about the data provider APIs, see [DataShareExtensionAbility](../reference/apis/js-apis-application-DataShareExtensionAbility.md). **Table 2** APIs of the data consumer @@ -29,7 +29,7 @@ For more information, see [DataShareHelper](../reference/apis/js-apis-data-dataS ## When to Use -There are two roles in **DataShare**: +There are two roles in **DataShare**: - Data provider: adds, deletes, modifies, and queries data, opens files, and shares data. - Data consumer: accesses the data provided by the provider using **DataShareHelper**. @@ -38,16 +38,16 @@ Examples are given below. ### Data Provider Application Development (Only for System Applications) -1. Import the dependencies. +1. Import dependencies. ```ts import Extension from '@ohos.application.DataShareExtensionAbility'; - import rdb from '@ohos.data.rdb'; + import rdb from '@ohos.data.relationalStore'; import fileIo from '@ohos.fileio'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; ``` -2. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only the **query()** API. +2. Override **DataShareExtensionAbility** APIs based on actual requirements. For example, if the data provider provides only data query, override only **query()**. 3. Implement the data provider services. For example, implement data storage of the data provider by using a database, reading and writing files, or accessing the network. @@ -64,13 +64,14 @@ Examples are given below. export default class DataShareExtAbility extends Extension { private rdbStore_; - // Override the onCreate() API. + // Override onCreate(). onCreate(want, callback) { result = this.context.cacheDir + '/datashare.txt' - // Create an RDB. + // Create an RDB store. rdb.getRdbStore(this.context, { - name: DB_NAME - }, 1, function (err, data) { + name: DB_NAME, + securityLevel: rdb.SecurityLevel.S1 + }, function (err, data) { rdbStore = data; rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { console.log('DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err)); @@ -79,7 +80,7 @@ Examples are given below. }); } - // Override the query() API. + // Override query(). query(uri, predicates, columns, callback) { if (predicates == null || predicates == undefined) { console.info('invalid predicates'); @@ -108,8 +109,8 @@ Examples are given below. | ------------ | ------------------------------------------------------------ | | "name" | Ability name, corresponding to the **ExtensionAbility** class name derived from **Ability**. | | "type" | Ability type. The value is **dataShare**, indicating the development is based on the **datashare** template.| - | "uri" | URI used for communication. It is the unique identifier for the data consumer to connect to the provider. | - | "visible" | Whether it is visible to other applications. Data sharing is allowed only when the value is **true**. | + | "uri" | URI used for communication. It is the unique identifier for the data consumer to connect to the provider. | + | "visible" | Whether it is visible to other applications. Data sharing is allowed only when the value is **true**.| **module.json5 example** @@ -132,7 +133,7 @@ Examples are given below. 1. Import dependencies. ```ts - import UIAbility from '@ohos.app.ability.UIAbility'; + import Ability from '@ohos.application.Ability'; import dataShare from '@ohos.data.dataShare'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; ``` @@ -150,7 +151,7 @@ Examples are given below. let dsHelper; let abilityContext; - export default class EntryAbility extends UIAbility { + export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { abilityContext = this.context; dataShare.createDataShareHelper(abilityContext, dseUri, (err, data)=>{ @@ -180,7 +181,7 @@ Examples are given below. dsHelper.query(dseUri, predicates, valArray, (err, data) => { console.log("dsHelper query result: " + data); }); - // Delete specified data. + // Delete data. dsHelper.delete(dseUri, predicates, (err, data) => { console.log("dsHelper delete result: " + data); }); diff --git a/en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md similarity index 96% rename from en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md rename to en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md index 9ecffc326e125b6e7dbe0ecd3cf03bfc3d2fa7dd..09ae7029ffe996209f75b3d8456697dce76adcd3 100644 --- a/en/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md +++ b/en/application-dev/reference/apis/js-apis-application-dataShareExtensionAbility.md @@ -1,4 +1,4 @@ -# @ohos.application.DataShareExtensionAbility +# @ohos.application.DataShareExtensionAbility (DataShare Extension Ability) The **DataShareExtensionAbility** module provides data share services based on the Extension ability. @@ -22,12 +22,11 @@ import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbili The URIs are in the following format: **Scheme://authority/path** - - *Scheme*: scheme name, which has a fixed value of **datashare** for the **DataShare** module. - *authority*: [userinfo@]host[:port] - - *userinfo*: login information, which can be left unspecified. - - *host*: server address. It is the target device ID for cross-device access and empty for local device access. - - *port*: port number of the server, which can be left unspecified. + - *userinfo*: login information, which can be left unspecified. + - *host*: server address. It is the target device ID for cross-device access and empty for local device access. + - *port*: port number of the server, which can be left unspecified. - *path*: **DataShare** identifier and the resource path. The **DataShare** identifier is mandatory, and the resource path is optional. Example: @@ -76,7 +75,8 @@ let rdbStore; export default class DataShareExtAbility extends DataShareExtensionAbility { onCreate(want, callback) { rdb.getRdbStore(this.context, { - name: DB_NAME + name: DB_NAME, + securityLevel: rdb.SecurityLevel.S1 }, function (err, data) { console.log('getRdbStore done, data : ' + data); rdbStore = data;