提交 a80a0e4c 编写于 作者: S songruirui

修改

Signed-off-by: Nsongruirui <songruirui1@huawei.com>
上级 44970dcb
...@@ -40,21 +40,19 @@ let TBL_NAME = "TBL00"; ...@@ -40,21 +40,19 @@ 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;
onCreate(want, callback) { onCreate(want: Want, callback: AsyncCallback&lt;void&gt;) {
console.log('DataShareExtAbility onCreate, want:' + want.abilityName);
console.log('DataShareExtAbility onCreate, this.context:' + this.context);
rdb.getRdbStore(this.context, { rdb.getRdbStore(this.context, {
name: DB_NAME name: DB_NAME
}, 1, function (err, data) { }, 1, function (err, data) {
console.log('getRdbStore fail, error message : ' + err);
console.log('getRdbStore done, data : ' + data); console.log('getRdbStore done, data : ' + data);
let rdbStore = data; rdbStore = data;
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { 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&lt;numbe ...@@ -64,7 +62,7 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe
在数据库插入时回调此接口,该方法可以选择性重写。 在数据库插入时回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -77,11 +75,7 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe ...@@ -77,11 +75,7 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe
**示例:** **示例:**
```ts ```ts
import rdb from '@ohos.data.rdb'; insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;) {
let TBL_NAME = "TBL00";
let rdbStore;
insert(uri, value, callback) {
if (value == null) { if (value == null) {
console.info('invalid valueBuckets'); console.info('invalid valueBuckets');
return; return;
...@@ -101,7 +95,7 @@ update?(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, ...@@ -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, ...@@ -115,11 +109,7 @@ update?(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket,
**示例:** **示例:**
```ts ```ts
import rdb from '@ohos.data.rdb'; update(uri: string, predicates: DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;) {
let TBL_NAME = "TBL00";
let rdbStore;
update(uri, predicates, value, callback) {
if (predicates == null || predicates == undefined) { if (predicates == null || predicates == undefined) {
return; return;
} }
...@@ -137,7 +127,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt ...@@ -137,7 +127,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt
在查询数据库时服务端回调此接口,该方法可以选择性重写。 在查询数据库时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -151,11 +141,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt ...@@ -151,11 +141,7 @@ query?(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt
**示例:** **示例:**
```ts ```ts
import rdb from '@ohos.data.rdb'; query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;Object&gt;) {
let TBL_NAME = "TBL00";
let rdbStore;
query(uri, predicates, columns, callback) {
if (predicates == null || predicates == undefined) { if (predicates == null || predicates == undefined) {
return; return;
} }
...@@ -176,7 +162,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt ...@@ -176,7 +162,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt
在删除数据库记录时服务端回调此接口,该方法可以选择性重写。 在删除数据库记录时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -189,11 +175,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt ...@@ -189,11 +175,7 @@ delete?(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt
**示例:** **示例:**
```ts ```ts
import rdb from '@ohos.data.rdb'; delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;number&gt;) {
let TBL_NAME = "TBL00";
let rdbStore;
delete(uri, predicates, callback) {
if (predicates == null || predicates == undefined) { if (predicates == null || predicates == undefined) {
return; return;
} }
...@@ -211,7 +193,7 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy ...@@ -211,7 +193,7 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy
在数据库批量插入时服务端回调此接口,该方法可以选择性重写。 在数据库批量插入时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -224,11 +206,7 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy ...@@ -224,11 +206,7 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy
**示例:** **示例:**
```ts ```ts
import rdb from '@ohos.data.rdb'; batchInsert(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;) {
let TBL_NAME = "TBL00";
let rdbStore;
batchInsert(uri: string, valueBuckets, callback) {
if (valueBuckets == null || valueBuckets.length == undefined) { if (valueBuckets == null || valueBuckets.length == undefined) {
console.info('invalid valueBuckets'); console.info('invalid valueBuckets');
return; return;
...@@ -250,7 +228,7 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -250,7 +228,7 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void
获取给定URI对应的MIME类型时服务端回调此接口,该方法可以选择性重写。 获取给定URI对应的MIME类型时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -262,8 +240,8 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -262,8 +240,8 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
getType(uri: string, callback) { getType(uri: string, callback: AsyncCallback&lt;string&gt;) {
let err; let err = {"code":0};
let ret = "image"; let ret = "image";
callback(err, ret); callback(err, ret);
} }
...@@ -275,7 +253,7 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar ...@@ -275,7 +253,7 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar
获取支持文件的MIME类型时服务端回调此接口,该方法可以选择性重写。 获取支持文件的MIME类型时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -288,8 +266,8 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar ...@@ -288,8 +266,8 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar
**示例:** **示例:**
```ts ```ts
getFileTypes(uri: string, mimeTypeFilter: string,callback) { getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) {
let err; let err = {"code":0};
let ret = new Array("type01", "type02", "type03"); let ret = new Array("type01", "type02", "type03");
callback(err, ret); callback(err, ret);
} }
...@@ -301,7 +279,7 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -301,7 +279,7 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
用户给定的URI转换为服务端使用的URI时回调此接口,该方法可以选择性重写。 用户给定的URI转换为服务端使用的URI时回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -313,8 +291,8 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -313,8 +291,8 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
normalizeUri(uri: string, callback) { normalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;) {
let err; let err = {"code":0};
let ret = "normalize+" + uri; let ret = "normalize+" + uri;
callback(err, ret); callback(err, ret);
} }
...@@ -326,7 +304,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -326,7 +304,7 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
服务端使用的URI转换为用户传入的初始URI时服务端回调此接口,该方法可以选择性重写。 服务端使用的URI转换为用户传入的初始URI时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -338,8 +316,8 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -338,8 +316,8 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
denormalizeUri(uri: string, callback) { denormalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;) {
let err; let err = {"code":0};
let ret = "denormalize+" + uri; let ret = "denormalize+" + uri;
callback(err, ret); callback(err, ret);
} }
...@@ -351,7 +329,7 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi ...@@ -351,7 +329,7 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi
在打开文件时服务端回调此接口,该方法可以选择性重写。 在打开文件时服务端回调此接口,该方法可以选择性重写。
**系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider **系统能力:** SystemCapability.DistributedDataManager.DataShare.Provider
**参数:** **参数:**
...@@ -364,9 +342,9 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi ...@@ -364,9 +342,9 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi
**示例:** **示例:**
```ts ```ts
openFile(uri: string, mode, callback) { openFile(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;) {
let err; let err = {"code":0};
let fd = 0; let fd = 0;
callback(err,fd); callback(err,fd);
} }
``` ```
\ No newline at end of file
...@@ -36,13 +36,14 @@ createDataShareHelper(context: Context, uri: string, callback: AsyncCallback&lt; ...@@ -36,13 +36,14 @@ createDataShareHelper(context: Context, uri: string, callback: AsyncCallback&lt;
```ts ```ts
import dataShare from '@ohos.data.dataShare' import dataShare from '@ohos.data.dataShare'
let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShare.createDataShareHelper(this.context, dseUri, (err, data) => { let dataShareHelper;
dataShare.createDataShareHelper(this.context, uri, (err, data) => {
if (err != undefined) { if (err != undefined) {
console.info("createDataShareHelper failed, error message : " + err); console.info("createDataShareHelper failed, error message : " + err);
} else { } else {
console.info("createDataShareHelper succeed, data : " + data); console.info("createDataShareHelper succeed, data : " + data);
let dataShareHelper = data; dataShareHelper = data;
} }
}); });
``` ```
...@@ -73,10 +74,11 @@ createDataShareHelper(context: Context, uri: string): Promise&lt;DataShareHelper ...@@ -73,10 +74,11 @@ createDataShareHelper(context: Context, uri: string): Promise&lt;DataShareHelper
```ts ```ts
import dataShare from '@ohos.data.dataShare' import dataShare from '@ohos.data.dataShare'
let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShare.createDataShareHelper(this.context, dseUri).then((data) => { let dataShareHelper;
dataShare.createDataShareHelper(this.context, uri).then((data) => {
console.info("createDataShareHelper succeed, data : " + data); console.info("createDataShareHelper succeed, data : " + data);
let dataShareHelper = data; dataShareHelper = data;
}).catch((err) => { }).catch((err) => {
console.info("createDataShareHelper failed, error message : " + err); console.info("createDataShareHelper failed, error message : " + err);
}) })
...@@ -84,7 +86,7 @@ dataShare.createDataShareHelper(this.context, dseUri).then((data) => { ...@@ -84,7 +86,7 @@ dataShare.createDataShareHelper(this.context, dseUri).then((data) => {
## DataShareHelper ## DataShareHelper
DataShare管理工具实例,可使用此实例访问或管理服务端的数据。在调用DataShareHelper提供的方法前,需要先通过[createDataShareHelper](#datashare.createdatasharehelper)构建一个实例。 DataShare管理工具实例,可使用此实例访问或管理服务端的数据。在调用DataShareHelper提供的方法前,需要先通过[createDataShareHelper](#datasharecreatedatasharehelper)构建一个实例。
### openFile ### openFile
...@@ -105,8 +107,6 @@ openFile(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): void ...@@ -105,8 +107,6 @@ openFile(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.openFile(uri, "rwt", (err, data) => { dataShareHelper.openFile(uri, "rwt", (err, data) => {
if (err != undefined) { if (err != undefined) {
console.info("openFile failed, error message : " + err); console.info("openFile failed, error message : " + err);
...@@ -141,8 +141,6 @@ openFile(uri: string, mode: string): Promise&lt;number&gt; ...@@ -141,8 +141,6 @@ openFile(uri: string, mode: string): Promise&lt;number&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.openFile(uri, "rwt").then((data) => { dataShareHelper.openFile(uri, "rwt").then((data) => {
console.info("openFile succeed, data : " + data); console.info("openFile succeed, data : " + data);
let fd = data; let fd = data;
...@@ -170,13 +168,10 @@ on(type: 'dataChange', uri: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -170,13 +168,10 @@ on(type: 'dataChange', uri: string, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper; function onCallback() {
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.on("dataChange", uri, onCallback);
export function onCallback() {
console.info("**** Observer on callback ****"); console.info("**** Observer on callback ****");
} }
dataShareHelper.on("dataChange", uri, onCallback);
``` ```
### off('dataChange') ### off('dataChange')
...@@ -198,13 +193,10 @@ off(type: 'dataChange', uri: string, callback?: AsyncCallback&lt;void&gt;): void ...@@ -198,13 +193,10 @@ off(type: 'dataChange', uri: string, callback?: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper; function offCallback() {
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.off("dataChange", uri, offCallback);
export function offCallback() {
console.info("**** Observer off callback ****"); console.info("**** Observer off callback ****");
} }
dataShareHelper.off("dataChange", uri, offCallback);
``` ```
### notifyChange ### notifyChange
...@@ -225,8 +217,6 @@ notifyChange(uri: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -225,8 +217,6 @@ notifyChange(uri: string, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.notifyChange(uri, () => { dataShareHelper.notifyChange(uri, () => {
console.log("***** notifyChange *****"); console.log("***** notifyChange *****");
}); });
...@@ -255,17 +245,6 @@ notifyChange(uri: string): Promise&lt;void&gt; ...@@ -255,17 +245,6 @@ notifyChange(uri: string): Promise&lt;void&gt;
**示例:** **示例:**
```ts ```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); dataShareHelper.notifyChange(uri);
``` ```
...@@ -287,15 +266,13 @@ getType(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -287,15 +266,13 @@ getType(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.getType(uri, (err, data)=>{ dataShareHelper.getType(uri, (err, data)=>{
if (err != undefined) { if (err != undefined) {
console.log("getType failed, error message : " + err); console.log("getType failed, error message : " + err);
}else{ }else{
console.log("getType succeed, data : " + data); console.log("getType succeed, data : " + data);
let result = data; let result = data;
} }
}); });
``` ```
...@@ -322,8 +299,6 @@ getType(uri: string): Promise&lt;string&gt; ...@@ -322,8 +299,6 @@ getType(uri: string): Promise&lt;string&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.getType(uri).then((data) => { dataShareHelper.getType(uri).then((data) => {
console.log("getType succeed, data : " + data); console.log("getType succeed, data : " + data);
}).catch((err) => { }).catch((err) => {
...@@ -350,8 +325,6 @@ getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Arr ...@@ -350,8 +325,6 @@ getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Arr
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let mimeTypeFilter = "image/*"; let mimeTypeFilter = "image/*";
dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => { dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => {
if (err != undefined) { if (err != undefined) {
...@@ -362,8 +335,6 @@ dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => { ...@@ -362,8 +335,6 @@ dataShareHelper.getFileTypes(uri, mimeTypeFilter, (err,data) => {
}); });
``` ```
### getFileTypes ### getFileTypes
getFileTypes(uri: string, mimeTypeFilter: string): Promise&lt;Array&lt;string&gt;&gt; getFileTypes(uri: string, mimeTypeFilter: string): Promise&lt;Array&lt;string&gt;&gt;
...@@ -388,8 +359,6 @@ getFileTypes(uri: string, mimeTypeFilter: string): Promise&lt;Array&lt;string&gt ...@@ -388,8 +359,6 @@ getFileTypes(uri: string, mimeTypeFilter: string): Promise&lt;Array&lt;string&gt
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let mimeTypeFilter = "image/*"; let mimeTypeFilter = "image/*";
dataShareHelper.getFileTypes(uri, mimeTypeFilter).then((data) => { dataShareHelper.getFileTypes(uri, mimeTypeFilter).then((data) => {
console.log("getFileTypes succeed, data : " + data); console.log("getFileTypes succeed, data : " + data);
...@@ -416,8 +385,6 @@ normalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -416,8 +385,6 @@ normalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
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.log("normalizeUri failed, error message : " + err);
...@@ -450,8 +417,6 @@ normalizeUri(uri: string): Promise&lt;string&gt; ...@@ -450,8 +417,6 @@ normalizeUri(uri: string): Promise&lt;string&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.normalizeUri(uri).then((data) => { dataShareHelper.normalizeUri(uri).then((data) => {
console.log("normalizeUri = " + data); console.log("normalizeUri = " + data);
}).catch((err) => { }).catch((err) => {
...@@ -477,8 +442,6 @@ denormalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -477,8 +442,6 @@ denormalizeUri(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
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.log("denormalizeUri failed, error message : " + err);
...@@ -511,8 +474,6 @@ denormalizeUri(uri: string): Promise&lt;string&gt; ...@@ -511,8 +474,6 @@ denormalizeUri(uri: string): Promise&lt;string&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
dataShareHelper.denormalizeUri(uri).then((data) => { dataShareHelper.denormalizeUri(uri).then((data) => {
console.log("denormalizeUri = " + data); console.log("denormalizeUri = " + data);
}).catch((err) => { }).catch((err) => {
...@@ -539,13 +500,10 @@ insert(uri: string, value: ValuesBucket, callback: AsyncCallback&lt;number&gt;): ...@@ -539,13 +500,10 @@ insert(uri: string, value: ValuesBucket, callback: AsyncCallback&lt;number&gt;):
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose", "name": "rose",
"age": 22, "age": 22,
"salary": 200.5, "salary": 200.5,
"blobType": u8,
} }
dataShareHelper.insert(uri, valueBucket, (err, data) => { dataShareHelper.insert(uri, valueBucket, (err, data) => {
if (err != undefined) { if (err != undefined) {
...@@ -580,13 +538,10 @@ insert(uri: string, value: ValuesBucket): Promise&lt;number&gt; ...@@ -580,13 +538,10 @@ insert(uri: string, value: ValuesBucket): Promise&lt;number&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
const valueBucket = { const valueBucket = {
"name": "rose1", "name": "rose1",
"age": 221, "age": 221,
"salary": 20.5, "salary": 20.5,
"blobType": u8,
} }
dataShareHelper.insert(uri, valueBucket).then((data) => { dataShareHelper.insert(uri, valueBucket).then((data) => {
console.log("insert succeed, data : " + data); console.log("insert succeed, data : " + data);
...@@ -614,11 +569,9 @@ batchInsert(uri: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallb ...@@ -614,11 +569,9 @@ batchInsert(uri: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallb
**示例:** **示例:**
```ts ```ts
let dataShareHelper; let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
let uri = ("datashare:///com.samples.datasharetest.DataShare"); {"name": "roe12", "age": 21, "salary": 20.5,},
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, {"name": "roe13", "age": 21, "salary": 20.5,})
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,})
dataShareHelper.batchInsert(uri, vbs, (err, data) => { dataShareHelper.batchInsert(uri, vbs, (err, data) => {
if (err != undefined) { if (err != undefined) {
console.log("batchInsert failed, error message : " + err); console.log("batchInsert failed, error message : " + err);
...@@ -652,11 +605,9 @@ batchInsert(uri: string, values: Array&lt;ValuesBucket&gt;): Promise&lt;number&g ...@@ -652,11 +605,9 @@ batchInsert(uri: string, values: Array&lt;ValuesBucket&gt;): Promise&lt;number&g
**示例:** **示例:**
```ts ```ts
let dataShareHelper; let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5,},
let uri = ("datashare:///com.samples.datasharetest.DataShare"); {"name": "roe12", "age": 21, "salary": 20.5,},
let vbs = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, {"name": "roe13", "age": 21, "salary": 20.5,})
{"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,},
{"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,})
dataShareHelper.batchInsert(uri, vbs).then((data) => { dataShareHelper.batchInsert(uri, vbs).then((data) => {
console.log("batchInsert succeed, data : " + data); console.log("batchInsert succeed, data : " + data);
}).catch((err) => { }).catch((err) => {
...@@ -683,8 +634,6 @@ delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt; ...@@ -683,8 +634,6 @@ delete(uri: string, predicates: DataSharePredicates, callback: AsyncCallback&lt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
dataShareHelper.delete(uri, da, (err, data) => { dataShareHelper.delete(uri, da, (err, data) => {
...@@ -720,8 +669,6 @@ delete(uri: string, predicates: DataSharePredicates): Promise&lt;number&gt; ...@@ -720,8 +669,6 @@ delete(uri: string, predicates: DataSharePredicates): Promise&lt;number&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
dataShareHelper.delete(uri, da).then((data) => { dataShareHelper.delete(uri, da).then((data) => {
...@@ -751,15 +698,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket, callba ...@@ -751,15 +698,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket, callba
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
const va = { const va = {
"name": "roe1", "name": "roe1",
"age": 21, "age": 21,
"salary": 20.5, "salary": 20.5,
"blobType": u8,
} }
dataShareHelper.update(uri, da, va, (err, data) => { dataShareHelper.update(uri, da, va, (err, data) => {
if (err != undefined) { if (err != undefined) {
...@@ -795,15 +740,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket): Promi ...@@ -795,15 +740,13 @@ update(uri: string, predicates: DataSharePredicates, value: ValuesBucket): Promi
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
const va = { const va = {
"name": "roe1", "name": "roe1",
"age": 21, "age": 21,
"salary": 20.5, "salary": 20.5,
"blobType": u8,
} }
dataShareHelper.update(uri, da, va).then((data) => { dataShareHelper.update(uri, da, va).then((data) => {
console.log("update succeed, data : " + data); console.log("update succeed, data : " + data);
...@@ -832,8 +775,6 @@ query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt; ...@@ -832,8 +775,6 @@ query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let columns = ["*"]; let columns = ["*"];
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
...@@ -841,13 +782,11 @@ dataShareHelper.query(uri, da, columns, (err, data) => { ...@@ -841,13 +782,11 @@ dataShareHelper.query(uri, da, columns, (err, data) => {
if (err != undefined) { if (err != undefined) {
console.log("query failed, error message : " + err); console.log("query failed, error message : " + err);
}else{ }else{
console.log("query succeed, data : " + data); console.log("query succeed, ret : " + data.rowCount);
} }
}); });
``` ```
### query ### query
query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;): Promise&lt;DataShareResultSet&gt; query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;): Promise&lt;DataShareResultSet&gt;
...@@ -873,13 +812,11 @@ query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt; ...@@ -873,13 +812,11 @@ query(uri: string, predicates: DataSharePredicates, columns: Array&lt;string&gt;
**示例:** **示例:**
```ts ```ts
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
let columns = ["*"]; let columns = ["*"];
let da = new dataShare.DataSharePredicates(); let da = new dataShare.DataSharePredicates();
da.equalTo("name", "ZhangSan"); da.equalTo("name", "ZhangSan");
dataShareHelper.query(uri, da, columns).then((data) => { dataShareHelper.query(uri, da, columns).then((data) => {
console.log("query succeed, data : " + data); console.log("query succeed, ret : " + data.rowCount);
}).catch((err) => { }).catch((err) => {
console.log("query failed, error message : " + err); console.log("query failed, error message : " + err);
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册