未验证 提交 e14de988 编写于 作者: O openharmony_ci 提交者: Gitee

!9379 RDB 修复示例代码问题

Merge pull request !9379 from ltdong/master
...@@ -1724,9 +1724,10 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -1724,9 +1724,10 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
**示例:** **示例:**
```js ```js
let predicates = new data_rdb.RdbPredicates('EPLOYEE') let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicates.greaterThan("id", 0) predicates.greaterThan("id", 0)
rdbStore.remoteQuery("deviceId", "EPLOYEE", predicates, function(err, resultSet){ rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
function(err, resultSet){
if (err) { if (err) {
console.info("Failed to remoteQuery, err: " + err) console.info("Failed to remoteQuery, err: " + err)
return return
...@@ -1762,9 +1763,9 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A ...@@ -1762,9 +1763,9 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A
**示例:** **示例:**
```js ```js
let predicates = new data_rdb.RdbPredicates('EPLOYEE') let predicates = new data_rdb.RdbPredicates('EMPLOYEE')
predicates.greaterThan("id", 0) predicates.greaterThan("id", 0)
let promise = rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates) let promise = rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => { promise.then((resultSet) => {
console.info("ResultSet column names: " + resultSet.columnNames) console.info("ResultSet column names: " + resultSet.columnNames)
console.info("ResultSet column count: " + resultSet.columnCount) console.info("ResultSet column count: " + resultSet.columnCount)
...@@ -1908,15 +1909,20 @@ beginTransaction():void ...@@ -1908,15 +1909,20 @@ beginTransaction():void
**示例:** **示例:**
```js ```js
rdbStore.beginTransaction() import featureAbility from '@ohos.ability.featureAbility'
const valueBucket = { var context = featureAbility.getContext()
"name": "lisi", const STORE_CONFIG = { name: "RdbTest.db"}
"age": 18, data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
"salary": 100.5, rdbStore.beginTransaction()
"blobType": new Uint8Array([1, 2, 3]), const valueBucket = {
} "name": "lisi",
await rdbStore.insert("test", valueBucket) "age": 18,
rdbStore.commit() "salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]),
}
await rdbStore.insert("test", valueBucket)
rdbStore.commit()
})
``` ```
### commit<sup>8+</sup> ### commit<sup>8+</sup>
...@@ -1930,16 +1936,20 @@ commit():void ...@@ -1930,16 +1936,20 @@ commit():void
**示例:** **示例:**
```js ```js
rdbStore.beginTransaction() import featureAbility from '@ohos.ability.featureAbility'
const valueBucket = { var context = featureAbility.getContext()
"name": "lisi", const STORE_CONFIG = { name: "RdbTest.db"}
"age": 18, data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
"salary": 100.5, rdbStore.beginTransaction()
"blobType": new Uint8Array([1, 2, 3]), const valueBucket = {
} "name": "lisi",
"age": 18,
await rdbStore.insert("test", valueBucket) "salary": 100.5,
rdbStore.commit() "blobType": new Uint8Array([1, 2, 3]),
}
await rdbStore.insert("test", valueBucket)
rdbStore.commit()
})
``` ```
### rollBack<sup>8+</sup> ### rollBack<sup>8+</sup>
...@@ -1953,20 +1963,25 @@ rollBack():void ...@@ -1953,20 +1963,25 @@ rollBack():void
**示例:** **示例:**
```js ```js
try { import featureAbility from '@ohos.ability.featureAbility'
rdbStore.beginTransaction() var context = featureAbility.getContext()
const valueBucket = { const STORE_CONFIG = { name: "RdbTest.db"}
"id": 1, data_rdb.getRdbStore(context, STORE_CONFIG, 1, async function (err, rdbStore) {
"name": "lisi", try {
"age": 18, rdbStore.beginTransaction()
"salary": 100.5, const valueBucket = {
"blobType": new Uint8Array([1, 2, 3]), "id": 1,
} "name": "lisi",
await rdbStore.insert("test", valueBucket) "age": 18,
rdbStore.commit() "salary": 100.5,
} catch (e) { "blobType": new Uint8Array([1, 2, 3]),
rdbStore.rollBack() }
} await rdbStore.insert("test", valueBucket)
rdbStore.commit()
} catch (e) {
rdbStore.rollBack()
}
})
``` ```
### backup<sup>9+</sup> ### backup<sup>9+</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册