未验证 提交 7bca58f1 编写于 作者: O openharmony_ci 提交者: Gitee

!15444 [翻译完成】#I6GMUI

Merge pull request !15444 from Annie_wang/PR14943
# @ohos.application.DataShareExtensionAbility (DataShare Extension Ability) # @ohos.application.DataShareExtensionAbility (DataShare Extension Ability)
The **DataShareExtensionAbility** module provides data share services based on the Extension ability. The **DataShareExtensionAbility** module provides data share services based on the ExtensionAbility.
>**NOTE** >**NOTE**
> >
...@@ -14,7 +14,7 @@ The **DataShareExtensionAbility** module provides data share services based on t ...@@ -14,7 +14,7 @@ The **DataShareExtensionAbility** module provides data share services based on t
## Modules to Import ## Modules to Import
```ts ```ts
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility' import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility';
``` ```
## URI Naming Rule ## URI Naming Rule
...@@ -65,11 +65,11 @@ Called by the server to initialize service logic when the DataShare client conne ...@@ -65,11 +65,11 @@ Called by the server to initialize service logic when the DataShare client conne
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
...@@ -112,22 +112,22 @@ Inserts data into the database. This API can be overridden as required. ...@@ -112,22 +112,22 @@ Inserts data into the database. This API can be overridden as required.
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
insert(uri, valueBucket, callback) { insert(uri, valueBucket, callback) {
if (valueBucket == null) { if (valueBucket === null) {
console.info('invalid valueBuckets'); console.info('invalid valueBuckets');
return; return;
} }
rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) { rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) {
console.info('callback ret:' + ret); console.info('callback ret:' + ret);
if (callback != undefined) { if (callback !== undefined) {
callback(err, ret); callback(err, ret);
} }
}); });
...@@ -157,20 +157,20 @@ Updates data in the database. This API can be overridden as required. ...@@ -157,20 +157,20 @@ Updates data in the database. This API can be overridden as required.
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
update(uri, predicates, valueBucket, callback) { update(uri, predicates, valueBucket, callback) {
if (predicates == null || predicates == undefined) { if (predicates === null || predicates === undefined) {
return; return;
} }
rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) { rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) {
if (callback != undefined) { if (callback !== undefined) {
callback(err, ret); callback(err, ret);
} }
}); });
...@@ -199,20 +199,20 @@ Deletes data from the database. This API can be overridden as required. ...@@ -199,20 +199,20 @@ Deletes data from the database. This API can be overridden as required.
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
delete(uri, predicates, callback) { delete(uri, predicates, callback) {
if (predicates == null || predicates == undefined) { if (predicates === null || predicates === undefined) {
return; return;
} }
rdbStore.delete(TBL_NAME, predicates, function (err, ret) { rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
if (callback != undefined) { if (callback !== undefined) {
callback(err, ret); callback(err, ret);
} }
}); });
...@@ -235,30 +235,30 @@ Queries data from the database. This API can be overridden as required. ...@@ -235,30 +235,30 @@ Queries data from the database. This API can be overridden as required.
| uri | string | Yes | URI of the data to query.| | uri | string | Yes | URI of the data to query.|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for querying data.| | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for querying data.|
| columns | Array<string> | Yes| Columns to query. If this parameter is empty, all columns will be queried.| | columns | Array<string> | Yes| Columns to query. If this parameter is empty, all columns will be queried.|
| callback | AsyncCallback<Object> | Yes| Callback invoked to return the result set.| | callback | AsyncCallback<Object> | Yes| Callback invoked to return the result set obtained.|
**Example** **Example**
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
query(uri, predicates, columns, callback) { query(uri, predicates, columns, callback) {
if (predicates == null || predicates == undefined) { if (predicates === null || predicates === undefined) {
return; return;
} }
rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) { rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
if (resultSet != undefined) { if (resultSet !== undefined) {
console.info('resultSet.rowCount: ' + resultSet.rowCount); console.info('resultSet.rowCount: ' + resultSet.rowCount);
} }
if (callback != undefined) { if (callback !== undefined) {
callback(err, resultSet); callback(err, resultSet);
} }
}); });
...@@ -287,23 +287,23 @@ Batch inserts data into the database. This API is called by the server and can b ...@@ -287,23 +287,23 @@ Batch inserts data into the database. This API is called by the server and can b
```ts ```ts
import rdb from '@ohos.data.relationalStore'; import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db"; let DB_NAME = 'DB00.db';
let TBL_NAME = "TBL00"; let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME + TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; + ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore; let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
batchInsert(uri, valueBuckets, callback) { batchInsert(uri, valueBuckets, callback) {
if (valueBuckets == null || valueBuckets.length == undefined) { if (valueBuckets === null || valueBuckets.length === undefined) {
console.info('invalid valueBuckets'); console.info('invalid valueBuckets');
return; return;
} }
let resultNum = valueBuckets.length let resultNum = valueBuckets.length;
valueBuckets.forEach(vb => { valueBuckets.forEach(vb => {
rdbStore.insert(TBL_NAME, vb, function (err, ret) { rdbStore.insert(TBL_NAME, vb, function (err, ret) {
if (callback != undefined) { if (callback !== undefined) {
callback(err, resultNum); callback(err, resultNum);
} }
}); });
...@@ -332,8 +332,8 @@ Normalizes a URI. This API can be overridden as required. ...@@ -332,8 +332,8 @@ Normalizes a URI. This API can be overridden as required.
```ts ```ts
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri(uri, callback) { normalizeUri(uri, callback) {
let err = {"code":0}; let err = {'code':0};
let ret = "normalize+" + uri; let ret = 'normalize+' + uri;
callback(err, ret); callback(err, ret);
} }
}; };
...@@ -359,8 +359,8 @@ Denormalizes a URI. This API can be overridden as required. ...@@ -359,8 +359,8 @@ Denormalizes a URI. This API can be overridden as required.
```ts ```ts
export default class DataShareExtAbility extends DataShareExtensionAbility { export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri(uri, callback) { denormalizeUri(uri, callback) {
let err = {"code":0}; let err = {'code':0};
let ret = "denormalize+" + uri; let ret = 'denormalize+' + uri;
callback(err, ret); callback(err, ret);
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册