提交 76cfa1db 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 64e7a410
# Data Share Extension Ability
**DataShareExtensionAbility** provides extension abilities for data share services based on the ExtensionAbility framework.
The **DataShareExtensionAbility** module provides Extension abilities for data share services.
>**NOTE**
>
......@@ -17,11 +17,19 @@
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'
```
## Attributes
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| context | [ExtensionContext](js-apis-extension-context.md) | Yes| No|Context of the DataShare Extension ability.|
## onCreate
onCreate?(want: Want, callback: AsyncCallback&lt;void&gt;): void
Called to initialize service logic of the server when the DataShare client connects to the DataShareExtensionAbility server. This API can be overridden as required.
Called by the server to initialize service logic when the DataShare client connects to the DataShareExtensionAbility server. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -45,7 +53,7 @@ let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
onCreate(want: Want, callback: AsyncCallback<void>) {
onCreate(want, callback) {
rdb.getRdbStore(this.context, {
name: DB_NAME
}, 1, function (err, data) {
......@@ -66,7 +74,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Called by the server to obtain the Multipurpose Internet Mail Extensions (MIME) types supported by a file. This API can be overridden as required.
Obtains the Multipurpose Internet Mail Extensions (MIME) types supported by a file. This API is called by the server and can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -82,7 +90,7 @@ Called by the server to obtain the Multipurpose Internet Mail Extensions (MIME)
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>) {
getFileTypes(uri, mimeTypeFilter, callback) {
let err = {"code":0};
let ret = new Array("type01", "type02", "type03");
callback(err, ret);
......@@ -94,7 +102,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): void
Called by the server to open a file. This method can be overridden as required.
Opens a file. This API is called by the server and can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -103,14 +111,14 @@ Called by the server to open a file. This method can be overridden as required.
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------ |
| uri | string | Yes | URI of the file to open. |
| mode | string | Yes | File open mode, including read-only mode and read/write mode.|
| mode | string | Yes | File open mode, which can be read-only or read/write.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the file descriptor. |
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
openFile(uri: string, mode: string, callback: AsyncCallback<number>) {
openFile(uri, mode, callback) {
let err = {"code":0};
let fd = 0;
callback(err,fd);
......@@ -122,7 +130,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void
Called to insert data into the database. This API can be overridden as required.
Inserts data into the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -137,13 +145,22 @@ Called to insert data into the database. This API can be overridden as required.
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
if (value == null) {
insert(uri, valueBucket, callback) {
if (valueBucket == null) {
console.info('invalid valueBuckets');
return;
}
rdbStore.insert(TBL_NAME, value, function (err, ret) {
rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) {
console.info('callback ret:' + ret);
if (callback != undefined) {
callback(err, ret);
......@@ -157,7 +174,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void
Called by the server to update data in the database. This API can be overridden as required.
Updates data in the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -173,12 +190,21 @@ Called by the server to update data in the database. This API can be overridden
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
update(uri, predicates, valueBucket, callback) {
if (predicates == null || predicates == undefined) {
return;
}
rdbStore.update(TBL_NAME, value, predicates, function (err, ret) {
rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) {
if (callback != undefined) {
callback(err, ret);
}
......@@ -191,7 +217,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;): void
Called by the server to delete data from the database. This API can be overridden as required.
Deletes data from the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -206,8 +232,17 @@ Called by the server to delete data from the database. This API can be overridde
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>) {
delete(uri, predicates, callback) {
if (predicates == null || predicates == undefined) {
return;
}
......@@ -224,7 +259,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;Object&gt;): void
Called by the server to query data from the database. This API can be overridden as required.
Queries data from the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -240,8 +275,17 @@ Called by the server to query data from the database. This API can be overridden
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>) {
query(uri, predicates, columns, callback) {
if (predicates == null || predicates == undefined) {
return;
}
......@@ -261,7 +305,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to obtain the MIME type corresponding to the given URI. This API can be overridden as required.
Obtains the MIME type corresponding to the given URI. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -276,7 +320,7 @@ Called by the server to obtain the MIME type corresponding to the given URI. Thi
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
getType(uri: string, callback: AsyncCallback<string>) {
getType(uri, callback) {
let err = {"code":0};
let ret = "image";
callback(err, ret);
......@@ -284,11 +328,11 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
};
```
## BatchInsert
## batchInsert
BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;): void
batchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;): void
Called by the server to insert batch data into the database. This API can be overridden as required.
Batch inserts data into the database. This API is called by the server and can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -303,8 +347,17 @@ Called by the server to insert batch data into the database. This API can be ove
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
batchInsert(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>) {
batchInsert(uri, valueBuckets, callback) {
if (valueBuckets == null || valueBuckets.length == undefined) {
console.info('invalid valueBuckets');
return;
......@@ -325,7 +378,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to normalize the specified URI. This API can be overridden as required.
Normalizes a URI. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -340,7 +393,7 @@ Called by the server to normalize the specified URI. This API can be overridden
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri(uri: string, callback: AsyncCallback<string>) {
normalizeUri(uri, callback) {
let err = {"code":0};
let ret = "normalize+" + uri;
callback(err, ret);
......@@ -352,7 +405,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to denormalize the specified URI. This method can be overridden as required.
Denormalizes a URI. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
......@@ -361,13 +414,13 @@ Called by the server to denormalize the specified URI. This method can be overri
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ----------------------- |
| uri | string | Yes | [URI](js-apis-uri.md#uri) to denormalize.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If the operation is successful, the URI obtained is returned. If the URI passed in is returned, denormalization is not required. If denormalization is not supported, **null** is returned.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If the operation is successful, the denormalized URI is returned. If the URI passed in is returned, denormalization is not required. If denormalization is not supported, **null** is returned.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri(uri: string, callback: AsyncCallback<string>) {
denormalizeUri(uri, callback) {
let err = {"code":0};
let ret = "denormalize+" + uri;
callback(err, ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册