From a80a0e4c635ddc2632dcb46f05d00eadd32a2974 Mon Sep 17 00:00:00 2001 From: songruirui Date: Mon, 13 Jun 2022 09:30:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songruirui --- ...s-application-DataShareExtensionAbility.md | 84 +++++-------- .../reference/apis/js-apis-data-dataShare.md | 111 ++++-------------- 2 files changed, 55 insertions(+), 140 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md b/zh-cn/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md index 9e3ad40655..49c1719a5f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md +++ b/zh-cn/application-dev/reference/apis/js-apis-application-DataShareExtensionAbility.md @@ -40,21 +40,19 @@ 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; -onCreate(want, callback) { - console.log('DataShareExtAbility onCreate, want:' + want.abilityName); - console.log('DataShareExtAbility onCreate, this.context:' + this.context); +onCreate(want: Want, callback: AsyncCallback<void>) { rdb.getRdbStore(this.context, { name: DB_NAME }, 1, function (err, data) { - console.log('getRdbStore fail, error message : ' + err); console.log('getRdbStore done, data : ' + data); - let rdbStore = data; + rdbStore = data; rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { - console.log('executeSql fail, error message : ' + err); + console.log('executeSql done, error message : ' + err); }); + callback(); }); - callback(); } ``` @@ -64,7 +62,7 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<numbe 在数据库插入时回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -77,11 +75,7 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<numbe **示例:** ```ts -import rdb from '@ohos.data.rdb'; -let TBL_NAME = "TBL00"; -let rdbStore; - -insert(uri, value, callback) { +insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>) { if (value == null) { console.info('invalid valueBuckets'); return; @@ -101,7 +95,7 @@ update?(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, 在数据库更新时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -115,11 +109,7 @@ update?(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, **示例:** ```ts -import rdb from '@ohos.data.rdb'; -let TBL_NAME = "TBL00"; -let rdbStore; - -update(uri, predicates, value, callback) { +update(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>) { if (predicates == null || predicates == undefined) { return; } @@ -137,7 +127,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array<string> 在查询数据库时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -151,11 +141,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array<string> **示例:** ```ts -import rdb from '@ohos.data.rdb'; -let TBL_NAME = "TBL00"; -let rdbStore; - -query(uri, predicates, columns, callback) { +query(uri: string, predicates: DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>) { if (predicates == null || predicates == undefined) { return; } @@ -176,7 +162,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback< 在删除数据库记录时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -189,11 +175,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback< **示例:** ```ts -import rdb from '@ohos.data.rdb'; -let TBL_NAME = "TBL00"; -let rdbStore; - -delete(uri, predicates, callback) { +delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback<number>) { if (predicates == null || predicates == undefined) { return; } @@ -211,7 +193,7 @@ BatchInsert?(uri: string, valueBuckets: Array<ValuesBucket>, callback: Asy 在数据库批量插入时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -224,11 +206,7 @@ BatchInsert?(uri: string, valueBuckets: Array<ValuesBucket>, callback: Asy **示例:** ```ts -import rdb from '@ohos.data.rdb'; -let TBL_NAME = "TBL00"; -let rdbStore; - -batchInsert(uri: string, valueBuckets, callback) { +batchInsert(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>) { if (valueBuckets == null || valueBuckets.length == undefined) { console.info('invalid valueBuckets'); return; @@ -250,7 +228,7 @@ getType?(uri: string, callback: AsyncCallback<string>): void 获取给定URI对应的MIME类型时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -262,8 +240,8 @@ getType?(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -getType(uri: string, callback) { - let err; +getType(uri: string, callback: AsyncCallback<string>) { + let err = {"code":0}; let ret = "image"; callback(err, ret); } @@ -275,7 +253,7 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Ar 获取支持文件的MIME类型时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -288,8 +266,8 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Ar **示例:** ```ts -getFileTypes(uri: string, mimeTypeFilter: string,callback) { - let err; +getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>) { + let err = {"code":0}; let ret = new Array("type01", "type02", "type03"); callback(err, ret); } @@ -301,7 +279,7 @@ normalizeUri?(uri: string, callback: AsyncCallback<string>): void 用户给定的URI转换为服务端使用的URI时回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -313,8 +291,8 @@ normalizeUri?(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -normalizeUri(uri: string, callback) { - let err; +normalizeUri(uri: string, callback: AsyncCallback<string>) { + let err = {"code":0}; let ret = "normalize+" + uri; callback(err, ret); } @@ -326,7 +304,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback<string>): void 服务端使用的URI转换为用户传入的初始URI时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -338,8 +316,8 @@ denormalizeUri?(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -denormalizeUri(uri: string, callback) { - let err; +denormalizeUri(uri: string, callback: AsyncCallback<string>) { + let err = {"code":0}; let ret = "denormalize+" + uri; callback(err, ret); } @@ -351,7 +329,7 @@ openFile?(uri: string, mode: string, callback: AsyncCallback<number>): voi 在打开文件时服务端回调此接口,该方法可以选择性重写。 -**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider。 +**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **参数:** @@ -364,9 +342,9 @@ openFile?(uri: string, mode: string, callback: AsyncCallback<number>): voi **示例:** ```ts -openFile(uri: string, mode, callback) { - let err; +openFile(uri: string, mode: string, callback: AsyncCallback<number>) { + let err = {"code":0}; let fd = 0; callback(err,fd); } -``` +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md index aad8ed3f27..125b7cf10e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md @@ -36,13 +36,14 @@ createDataShareHelper(context: Context, uri: string, callback: AsyncCallback< ```ts import dataShare from '@ohos.data.dataShare' -let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShare.createDataShareHelper(this.context, dseUri, (err, data) => { +let uri = ("datashare:///com.samples.datasharetest.DataShare"); +let dataShareHelper; +dataShare.createDataShareHelper(this.context, uri, (err, data) => { if (err != undefined) { console.info("createDataShareHelper failed, error message : " + err); } else { console.info("createDataShareHelper succeed, data : " + data); - let dataShareHelper = data; + dataShareHelper = data; } }); ``` @@ -73,10 +74,11 @@ createDataShareHelper(context: Context, uri: string): Promise<DataShareHelper ```ts import dataShare from '@ohos.data.dataShare' -let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShare.createDataShareHelper(this.context, dseUri).then((data) => { +let uri = ("datashare:///com.samples.datasharetest.DataShare"); +let dataShareHelper; +dataShare.createDataShareHelper(this.context, uri).then((data) => { console.info("createDataShareHelper succeed, data : " + data); - let dataShareHelper = data; + dataShareHelper = data; }).catch((err) => { console.info("createDataShareHelper failed, error message : " + err); }) @@ -84,7 +86,7 @@ dataShare.createDataShareHelper(this.context, dseUri).then((data) => { ## DataShareHelper -DataShare管理工具实例,可使用此实例访问或管理服务端的数据。在调用DataShareHelper提供的方法前,需要先通过[createDataShareHelper](#datashare.createdatasharehelper)构建一个实例。 +DataShare管理工具实例,可使用此实例访问或管理服务端的数据。在调用DataShareHelper提供的方法前,需要先通过[createDataShareHelper](#datasharecreatedatasharehelper)构建一个实例。 ### openFile @@ -105,8 +107,6 @@ openFile(uri: string, mode: string, callback: AsyncCallback<number>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.openFile(uri, "rwt", (err, data) => { if (err != undefined) { console.info("openFile failed, error message : " + err); @@ -141,8 +141,6 @@ openFile(uri: string, mode: string): Promise<number> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.openFile(uri, "rwt").then((data) => { console.info("openFile succeed, data : " + data); let fd = data; @@ -170,13 +168,10 @@ on(type: 'dataChange', uri: string, callback: AsyncCallback<void>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShareHelper.on("dataChange", uri, onCallback); - -export function onCallback() { +function onCallback() { console.info("**** Observer on callback ****"); } +dataShareHelper.on("dataChange", uri, onCallback); ``` ### off('dataChange') @@ -198,13 +193,10 @@ off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShareHelper.off("dataChange", uri, offCallback); - -export function offCallback() { +function offCallback() { console.info("**** Observer off callback ****"); } +dataShareHelper.off("dataChange", uri, offCallback); ``` ### notifyChange @@ -225,8 +217,6 @@ notifyChange(uri: string, callback: AsyncCallback<void>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.notifyChange(uri, () => { console.log("***** notifyChange *****"); }); @@ -255,17 +245,6 @@ notifyChange(uri: string): Promise<void> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShare.createDataShareHelper(this.context, uri, (err, data) => { - if (err != undefined) { - console.info("createDataShareHelper failed, error message : " + err); - } else { - console.info("createDataShareHelper succeed, data : " + data); - dataShareHelper = data; - } -}); - dataShareHelper.notifyChange(uri); ``` @@ -287,15 +266,13 @@ getType(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.getType(uri, (err, data)=>{ if (err != undefined) { console.log("getType failed, error message : " + err); }else{ console.log("getType succeed, data : " + data); let result = data; - } + } }); ``` @@ -322,8 +299,6 @@ getType(uri: string): Promise<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.getType(uri).then((data) => { console.log("getType succeed, data : " + data); }).catch((err) => { @@ -350,8 +325,6 @@ getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Arr **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let mimeTypeFilter = "image/*"; dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => { if (err != undefined) { @@ -362,8 +335,6 @@ dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => { }); ``` - - ### getFileTypes getFileTypes(uri: string, mimeTypeFilter: string): Promise<Array<string>> @@ -388,8 +359,6 @@ getFileTypes(uri: string, mimeTypeFilter: string): Promise<Array<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let mimeTypeFilter = "image/*"; dataShareHelper.getFileTypes(uri, mimeTypeFilter).then((data) => { console.log("getFileTypes succeed, data : " + data); @@ -416,8 +385,6 @@ normalizeUri(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.normalizeUri(uri, (err, data) => { if (err != undefined) { console.log("normalizeUri failed, error message : " + err); @@ -450,8 +417,6 @@ normalizeUri(uri: string): Promise<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.normalizeUri(uri).then((data) => { console.log("normalizeUri = " + data); }).catch((err) => { @@ -477,8 +442,6 @@ denormalizeUri(uri: string, callback: AsyncCallback<string>): void **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.denormalizeUri(uri, (err, data) => { if (err != undefined) { console.log("denormalizeUri failed, error message : " + err); @@ -511,8 +474,6 @@ denormalizeUri(uri: string): Promise<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); dataShareHelper.denormalizeUri(uri).then((data) => { console.log("denormalizeUri = " + data); }).catch((err) => { @@ -539,13 +500,10 @@ insert(uri: string, value: ValuesBucket, callback: AsyncCallback<number>): **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); const valueBucket = { "name": "rose", "age": 22, "salary": 200.5, - "blobType": u8, } dataShareHelper.insert(uri, valueBucket, (err, data) => { if (err != undefined) { @@ -580,13 +538,10 @@ insert(uri: string, value: ValuesBucket): Promise<number> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); const valueBucket = { "name": "rose1", "age": 221, "salary": 20.5, - "blobType": u8, } dataShareHelper.insert(uri, valueBucket).then((data) => { console.log("insert succeed, data : " + data); @@ -614,11 +569,9 @@ batchInsert(uri: string, values: Array<ValuesBucket>, callback: AsyncCallb **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); -let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) +let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, + {"name": "roe12", "age": 21, "salary": 20.5,}, + {"name": "roe13", "age": 21, "salary": 20.5,}) dataShareHelper.batchInsert(uri, vbs, (err, data) => { if (err != undefined) { console.log("batchInsert failed, error message : " + err); @@ -652,11 +605,9 @@ batchInsert(uri: string, values: Array<ValuesBucket>): Promise<number&g **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); -let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) +let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, + {"name": "roe12", "age": 21, "salary": 20.5,}, + {"name": "roe13", "age": 21, "salary": 20.5,}) dataShareHelper.batchInsert(uri, vbs).then((data) => { console.log("batchInsert succeed, data : " + data); }).catch((err) => { @@ -683,8 +634,6 @@ delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback< **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); dataShareHelper.delete(uri, da, (err, data) => { @@ -720,8 +669,6 @@ delete(uri: string, predicates: DataSharePredicates): Promise<number> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); dataShareHelper.delete(uri, da).then((data) => { @@ -751,15 +698,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket, callba **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); const va = { "name": "roe1", "age": 21, "salary": 20.5, - "blobType": u8, + } dataShareHelper.update(uri, da, va, (err, data) => { if (err != undefined) { @@ -795,15 +740,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket): Promi **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); const va = { "name": "roe1", "age": 21, "salary": 20.5, - "blobType": u8, + } dataShareHelper.update(uri, da, va).then((data) => { console.log("update succeed, data : " + data); @@ -832,8 +775,6 @@ query(uri: string, predicates: DataSharePredicates, columns: Array<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let columns = ["*"]; let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); @@ -841,13 +782,11 @@ dataShareHelper.query(uri, da, columns, (err, data) => { if (err != undefined) { console.log("query failed, error message : " + err); }else{ - console.log("query succeed, data : " + data); + console.log("query succeed, ret : " + data.rowCount); } }); ``` - - ### query query(uri: string, predicates: DataSharePredicates, columns: Array<string>): Promise<DataShareResultSet> @@ -873,13 +812,11 @@ query(uri: string, predicates: DataSharePredicates, columns: Array<string> **示例:** ```ts -let dataShareHelper; -let uri = ("datashare:///com.samples.datasharetest.DataShare"); let columns = ["*"]; let da = new dataShare.DataSharePredicates(); da.equalTo("name", "ZhangSan"); dataShareHelper.query(uri, da, columns).then((data) => { - console.log("query succeed, data : " + data); + console.log("query succeed, ret : " + data.rowCount); }).catch((err) => { console.log("query failed, error message : " + err); }); -- GitLab