提交 8e219ebe 编写于 作者: S srr101

datashare文档修改

Signed-off-by: Nsrr101 <songruirui1@huawei.com>
上级 ca03218b
...@@ -17,26 +17,6 @@ ...@@ -17,26 +17,6 @@
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'; import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility';
``` ```
## uri命名规则
标准uri定义结构如下:
**Scheme://authority/path**
- Scheme: 协议名,对于data share统一为datashare
- authority: [userinfo@]host[:port]
- userinfo: 登录信息,不需要填写。
- host: 服务器地址,如果跨设备访问则为目标设备的ID,如果为本设备则为空。
- port: 服务器端口,不需要填写。
- path: data share的标识信息和资源的路径信息,需要包含data share的标识信息,资源的路径信息可以不填写。
uri示例:
- 不包含资源路径: `datashare:///com.samples.datasharetest.DataShare`
- 包含资源路径: `datashare:///com.samples.datasharetest.DataShare/DB00/TBL00`
其中,data share的标识信息为`com.samples.datasharetest.DataShare`,资源路径为`DB00/TBL00`
## 属性 ## 属性
**系统能力**:SystemCapability.DistributedDataManager.DataShare.Provider **系统能力**:SystemCapability.DistributedDataManager.DataShare.Provider
...@@ -78,7 +58,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -78,7 +58,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
name: DB_NAME, name: DB_NAME,
securityLevel: rdb.SecurityLevel.S1 securityLevel: rdb.SecurityLevel.S1
}, function (err, data) { }, function (err, data) {
console.log('getRdbStore done, data : ${data}'); console.info(`getRdbStore done, data : ${data}`);
rdbStore = data; rdbStore = data;
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.error('executeSql done, error message : ${err}'); console.error('executeSql done, error message : ${err}');
...@@ -126,7 +106,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -126,7 +106,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
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);
} }
...@@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -256,7 +236,7 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
} }
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);
...@@ -300,11 +280,9 @@ export default class DataShareExtAbility extends DataShareExtensionAbility { ...@@ -300,11 +280,9 @@ export default class DataShareExtAbility extends DataShareExtensionAbility {
console.info('invalid valueBuckets'); console.info('invalid valueBuckets');
return; return;
} }
let resultNum = valueBuckets.length; rdbStore.batchInsert(TBL_NAME, valueBuckets, function (err, ret) {
valueBuckets.forEach(vb => {
rdbStore.insert(TBL_NAME, vb, function (err, ret) {
if (callback !== undefined) { if (callback !== undefined) {
callback(err, resultNum); callback(err, ret);
} }
}); });
}); });
...@@ -333,7 +311,7 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -333,7 +311,7 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
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);
} }
}; };
...@@ -360,7 +338,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -360,7 +338,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
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);
} }
}; };
......
...@@ -593,7 +593,7 @@ let data : Array<dataShare.PublishedItem> = [ ...@@ -593,7 +593,7 @@ let data : Array<dataShare.PublishedItem> = [
{key:"empty", subscriberId:"11", data:"nobody sub"}]; {key:"empty", subscriberId:"11", data:"nobody sub"}];
let nums:number[] = [1,2,3]; let nums:number[] = [1,2,3];
function publishCallback(err, result: Array<dataShare.OperationResult>) { function publishCallback(err, result: Array<dataShare.OperationResult>) {
console.log("publishCallback " + JSON.stringify(result)); console.info("publishCallback " + JSON.stringify(result));
ashmem.closeAshmem(); ashmem.closeAshmem();
} }
try { try {
...@@ -605,10 +605,10 @@ try { ...@@ -605,10 +605,10 @@ try {
"data" : ashmem, "data" : ashmem,
"subscriberId" : "11", "subscriberId" : "11",
}); });
console.log("data length is:", data.length); console.info("data length is:", data.length);
dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback);
} catch (e) { } catch (e) {
console.log("publish error " + JSON.stringify(e)); console.info("publish error " + JSON.stringify(e));
} }
``` ```
...@@ -640,7 +640,7 @@ publish(data: Array&lt;PublishedItem&gt;, bundleName: string, callback: AsyncCal ...@@ -640,7 +640,7 @@ publish(data: Array&lt;PublishedItem&gt;, bundleName: string, callback: AsyncCal
```ts ```ts
function publishCallback(err, result: Array<dataShare.OperationResult>) { function publishCallback(err, result: Array<dataShare.OperationResult>) {
console.log("publishCallback " + JSON.stringify(result)); console.info("publishCallback " + JSON.stringify(result));
} }
let data : Array<dataShare.PublishedItem> = [ let data : Array<dataShare.PublishedItem> = [
{key:"city", subscriberId:"11", data:"xian"}, {key:"city", subscriberId:"11", data:"xian"},
...@@ -825,7 +825,7 @@ const valueBucket = { ...@@ -825,7 +825,7 @@ const valueBucket = {
} }
try { try {
dataShareHelper.insert(uri, valueBucket).then((data) => { dataShareHelper.insert(uri, valueBucket).then((data) => {
console.log("insert succeed, data : " + data); console.info("insert succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`insert error: code: ${err.code}, message: ${err.message} `); console.error(`insert error: code: ${err.code}, message: ${err.message} `);
}); });
...@@ -902,7 +902,7 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -902,7 +902,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.delete(uri, da).then((data) => { dataShareHelper.delete(uri, da).then((data) => {
console.log("delete succeed, data : " + data); console.info("delete succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`delete error: code: ${err.code}, message: ${err.message} `); console.error(`delete error: code: ${err.code}, message: ${err.message} `);
}); });
...@@ -943,7 +943,7 @@ try { ...@@ -943,7 +943,7 @@ try {
console.error(`query error: code: ${err.code}, message: ${err.message} `); console.error(`query error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("query succeed, rowCount : " + data.rowCount); console.info("query succeed, rowCount : " + data.rowCount);
}); });
} catch (err) { } catch (err) {
console.error(`query error: code: ${err.code}, message: ${err.message} `); console.error(`query error: code: ${err.code}, message: ${err.message} `);
...@@ -983,7 +983,7 @@ let da = new dataSharePredicates.DataSharePredicates(); ...@@ -983,7 +983,7 @@ let da = new dataSharePredicates.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
try { try {
dataShareHelper.query(uri, da, columns).then((data) => { dataShareHelper.query(uri, da, columns).then((data) => {
console.log("query succeed, rowCount : " + data.rowCount); console.info("query succeed, rowCount : " + data.rowCount);
}). catch((err) => { }). catch((err) => {
console.error(`query error: code: ${err.code}, message: ${err.message} `); console.error(`query error: code: ${err.code}, message: ${err.message} `);
}); });
...@@ -1029,7 +1029,7 @@ try { ...@@ -1029,7 +1029,7 @@ try {
console.error(`update error: code: ${err.code}, message: ${err.message} `); console.error(`update error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("update succeed, data : " + data); console.info("update succeed, data : " + data);
}); });
} catch (err) { } catch (err) {
console.error(`update error: code: ${err.code}, message: ${err.message} `); console.error(`update error: code: ${err.code}, message: ${err.message} `);
...@@ -1074,7 +1074,7 @@ const va = { ...@@ -1074,7 +1074,7 @@ const va = {
} }
try { try {
dataShareHelper.update(uri, da, va).then((data) => { dataShareHelper.update(uri, da, va).then((data) => {
console.log("update succeed, data : " + data); console.info("update succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`update error: code: ${err.code}, message: ${err.message} `); console.error(`update error: code: ${err.code}, message: ${err.message} `);
}); });
...@@ -1112,7 +1112,7 @@ try { ...@@ -1112,7 +1112,7 @@ try {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `);
return; return;
} }
console.log("batchInsert succeed, data : " + data); console.info("batchInsert succeed, data : " + data);
}); });
} catch (err) { } catch (err) {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `);
...@@ -1149,7 +1149,7 @@ let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,}, ...@@ -1149,7 +1149,7 @@ let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
{"name": "roe13", "age": 21, "salary": 20.5,}) {"name": "roe13", "age": 21, "salary": 20.5,})
try { try {
dataShareHelper.batchInsert(uri, vbs).then((data) => { dataShareHelper.batchInsert(uri, vbs).then((data) => {
console.log("batchInsert succeed, data : " + data); console.info("batchInsert succeed, data : " + data);
}). catch((err) => { }). catch((err) => {
console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `); console.error(`batchInsert error: code: ${err.code}, message: ${err.message} `);
}); });
...@@ -1179,9 +1179,9 @@ normalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -1179,9 +1179,9 @@ normalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri, (err, data) => { dataShareHelper.normalizeUri(uri, (err, data) => {
if (err !== undefined) { if (err !== undefined) {
console.log("normalizeUri failed, error message : " + err); console.info("normalizeUri failed, error message : " + err);
}else{ }else{
console.log("normalizeUri = " + data); console.info("normalizeUri = " + data);
} }
}); });
``` ```
...@@ -1211,9 +1211,9 @@ normalizeUri(uri: string): Promise&lt;string&gt; ...@@ -1211,9 +1211,9 @@ normalizeUri(uri: string): Promise&lt;string&gt;
```ts ```ts
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri).then((data) => { dataShareHelper.normalizeUri(uri).then((data) => {
console.log("normalizeUri = " + data); console.info("normalizeUri = " + data);
}).catch((err) => { }).catch((err) => {
console.log("normalizeUri failed, error message : " + err); console.info("normalizeUri failed, error message : " + err);
}); });
``` ```
...@@ -1238,9 +1238,9 @@ denormalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -1238,9 +1238,9 @@ denormalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri, (err, data) => { dataShareHelper.denormalizeUri(uri, (err, data) => {
if (err !== undefined) { if (err !== undefined) {
console.log("denormalizeUri failed, error message : " + err); console.info("denormalizeUri failed, error message : " + err);
}else{ }else{
console.log("denormalizeUri = " + data); console.info("denormalizeUri = " + data);
} }
}); });
``` ```
...@@ -1270,9 +1270,9 @@ denormalizeUri(uri: string): Promise&lt;string&gt; ...@@ -1270,9 +1270,9 @@ denormalizeUri(uri: string): Promise&lt;string&gt;
```ts ```ts
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri).then((data) => { dataShareHelper.denormalizeUri(uri).then((data) => {
console.log("denormalizeUri = " + data); console.info("denormalizeUri = " + data);
}).catch((err) => { }).catch((err) => {
console.log("denormalizeUri failed, error message : " + err); console.info("denormalizeUri failed, error message : " + err);
}); });
``` ```
...@@ -1296,7 +1296,7 @@ notifyChange(uri: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -1296,7 +1296,7 @@ notifyChange(uri: string, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
let uri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri, () => { dataShareHelper.notifyChange(uri, () => {
console.log("***** notifyChange *****"); console.info("***** notifyChange *****");
}); });
``` ```
......
...@@ -19,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates'; ...@@ -19,7 +19,7 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
## DataSharePredicates ## DataSharePredicates
提供用于不同实现不同查询方法的数据共享谓词。该类型不是多线程安全的,如果应用中存在多线程同时操作该类派生出的实例,注意加锁保护。 提供用于不同实现不同查询方法的数据共享谓词。该类型不是多线程安全的,如果应用中存在多线程同时操作该类派生出的实例,注意加锁保护。
### equalTo ### equalTo<sup>10+</sup>
equalTo(field: string, value: ValueType): DataSharePredicates equalTo(field: string, value: ValueType): DataSharePredicates
...@@ -168,7 +168,7 @@ predicates.equalTo("NAME", "lisi") ...@@ -168,7 +168,7 @@ predicates.equalTo("NAME", "lisi")
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
``` ```
### and ### and<sup>10+</sup>
and(): DataSharePredicates and(): DataSharePredicates
...@@ -641,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -641,7 +641,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.lessThanOrEqualTo("AGE", 50) predicates.lessThanOrEqualTo("AGE", 50)
``` ```
### orderByAsc ### orderByAsc<sup>10+</sup>
orderByAsc(field: string): DataSharePredicates orderByAsc(field: string): DataSharePredicates
...@@ -670,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -670,7 +670,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.orderByAsc("AGE") predicates.orderByAsc("AGE")
``` ```
### orderByDesc ### orderByDesc<sup>10+</sup>
orderByDesc(field: string): DataSharePredicates orderByDesc(field: string): DataSharePredicates
...@@ -724,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -724,7 +724,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.equalTo("NAME", "Rose").distinct() predicates.equalTo("NAME", "Rose").distinct()
``` ```
### limit ### limit<sup>10+</sup>
limit(total: number, offset: number): DataSharePredicates limit(total: number, offset: number): DataSharePredicates
...@@ -816,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates() ...@@ -816,7 +816,7 @@ let predicates = new dataSharePredicates.DataSharePredicates()
predicates.indexedBy("SALARY_INDEX") predicates.indexedBy("SALARY_INDEX")
``` ```
### in ### in<sup>10+</sup>
in(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates in(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册