提交 12011e13 编写于 作者: W wanning.fang

修改示例代码

Signed-off-by: Nwanning.fang <songruirui1@huawei.com>
上级 84d79b77
...@@ -44,20 +44,22 @@ let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " ...@@ -44,20 +44,22 @@ let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ " (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;
onCreate(want: Want, callback: AsyncCallback<void>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
rdb.getRdbStore(this.context, { onCreate(want: Want, callback: AsyncCallback<void>) {
name: DB_NAME rdb.getRdbStore(this.context, {
}, 1, function (err, data) { name: DB_NAME
console.log('getRdbStore done, data : ' + data); }, 1, function (err, data) {
rdbStore = data; console.log('getRdbStore done, data : ' + data);
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { rdbStore = data;
console.log('executeSql done, error message : ' + err); rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.log('executeSql done, error message : ' + err);
});
if (callback) {
callback();
}
}); });
if (callback) { }
callback(); };
}
});
}
``` ```
## getFileTypes ## getFileTypes
...@@ -79,11 +81,13 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar ...@@ -79,11 +81,13 @@ getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Ar
**示例:** **示例:**
```ts ```ts
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
let err = {"code":0}; getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>) {
let ret = new Array("type01", "type02", "type03"); let err = {"code":0};
callback(err, ret); let ret = new Array("type01", "type02", "type03");
} callback(err, ret);
}
};
``` ```
## openFile ## openFile
...@@ -105,11 +109,13 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi ...@@ -105,11 +109,13 @@ openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): voi
**示例:** **示例:**
```ts ```ts
openFile(uri: string, mode: string, callback: AsyncCallback<number>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
let err = {"code":0}; openFile(uri: string, mode: string, callback: AsyncCallback<number>) {
let fd = 0; let err = {"code":0};
callback(err,fd); let fd = 0;
} callback(err,fd);
}
};
``` ```
## insert ## insert
...@@ -131,18 +137,20 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe ...@@ -131,18 +137,20 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe
**示例:** **示例:**
```ts ```ts
insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
if (value == null) { insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
console.info('invalid valueBuckets'); if (value == null) {
return; console.info('invalid valueBuckets');
} return;
rdbStore.insert(TBL_NAME, value, function (err, ret) {
console.info('callback ret:' + ret);
if (callback != undefined) {
callback(err, ret);
} }
}); rdbStore.insert(TBL_NAME, value, function (err, ret) {
} console.info('callback ret:' + ret);
if (callback != undefined) {
callback(err, ret);
}
});
}
};
``` ```
## update ## update
...@@ -165,16 +173,18 @@ update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueB ...@@ -165,16 +173,18 @@ update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueB
**示例:** **示例:**
```ts ```ts
update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
if (predicates == null || predicates == undefined) { update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
return; if (predicates == null || predicates == undefined) {
} return;
rdbStore.update(TBL_NAME, value, predicates, function (err, ret) {
if (callback != undefined) {
callback(err, ret);
} }
}); rdbStore.update(TBL_NAME, value, predicates, function (err, ret) {
} if (callback != undefined) {
callback(err, ret);
}
});
}
};
``` ```
## delete ## delete
...@@ -196,16 +206,18 @@ delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callba ...@@ -196,16 +206,18 @@ delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callba
**示例:** **示例:**
```ts ```ts
delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
if (predicates == null || predicates == undefined) { delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>) {
return; if (predicates == null || predicates == undefined) {
} return;
rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
if (callback != undefined) {
callback(err, ret);
} }
}); rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
} if (callback != undefined) {
callback(err, ret);
}
});
}
};
``` ```
## query ## query
...@@ -228,19 +240,21 @@ query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns ...@@ -228,19 +240,21 @@ query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns
**示例:** **示例:**
```ts ```ts
query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
if (predicates == null || predicates == undefined) { query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>) {
return; if (predicates == null || predicates == undefined) {
} return;
rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
if (resultSet != undefined) {
console.info('resultSet.rowCount: ' + resultSet.rowCount);
} }
if (callback != undefined) { rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
callback(err, resultSet); if (resultSet != undefined) {
} console.info('resultSet.rowCount: ' + resultSet.rowCount);
}); }
} if (callback != undefined) {
callback(err, resultSet);
}
});
}
};
``` ```
## getType ## getType
...@@ -261,11 +275,13 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -261,11 +275,13 @@ getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
getType(uri: string, callback: AsyncCallback<string>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
let err = {"code":0}; getType(uri: string, callback: AsyncCallback<string>) {
let ret = "image"; let err = {"code":0};
callback(err, ret); let ret = "image";
} callback(err, ret);
}
};
``` ```
## BatchInsert ## BatchInsert
...@@ -287,20 +303,22 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy ...@@ -287,20 +303,22 @@ BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy
**示例:** **示例:**
```ts ```ts
batchInsert(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
if (valueBuckets == null || valueBuckets.length == undefined) { batchInsert(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>) {
console.info('invalid valueBuckets'); if (valueBuckets == null || valueBuckets.length == undefined) {
return; console.info('invalid valueBuckets');
} return;
let resultNum = valueBuckets.length }
valueBuckets.forEach(vb => { let resultNum = valueBuckets.length
rdbStore.insert(TBL_NAME, vb, function (err, ret) { valueBuckets.forEach(vb => {
if (callback != undefined) { rdbStore.insert(TBL_NAME, vb, function (err, ret) {
callback(err, resultNum); if (callback != undefined) {
} callback(err, resultNum);
}
});
}); });
}); }
} };
``` ```
## normalizeUri ## normalizeUri
...@@ -321,11 +339,13 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -321,11 +339,13 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
normalizeUri(uri: string, callback: AsyncCallback<string>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
let err = {"code":0}; normalizeUri(uri: string, callback: AsyncCallback<string>) {
let ret = "normalize+" + uri; let err = {"code":0};
callback(err, ret); let ret = "normalize+" + uri;
} callback(err, ret);
}
};
``` ```
## denormalizeUri ## denormalizeUri
...@@ -346,9 +366,11 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -346,9 +366,11 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```ts ```ts
denormalizeUri(uri: string, callback: AsyncCallback<string>) { export default class DataShareExtAbility extends DataShareExtensionAbility {
let err = {"code":0}; denormalizeUri(uri: string, callback: AsyncCallback<string>) {
let ret = "denormalize+" + uri; let err = {"code":0};
callback(err, ret); let ret = "denormalize+" + uri;
} callback(err, ret);
}
};
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册