提交 f85e1603 编写于 作者: L ltdong

update sample code

Signed-off-by: Nltdong <donglongtao@huawei.com>
上级 6f741790
......@@ -622,7 +622,7 @@ distinct(): DataAbilityPredicates
```
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME")
let resultSet = await rdbStore.query(predicates, ["NAME"])
rdbStore.query(predicates, ["NAME"])
```
......
......@@ -698,7 +698,7 @@ distinct(): RdbPredicates
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME")
let resultSet = await rdbStore.query(predicates, ["NAME"])
rdbStore.query(predicates, ["NAME"])
```
......
......@@ -14,8 +14,9 @@ let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("AGE", 18)
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => {
await console.log(TAG + "resultSet columnNames:" + resultSet.columnNames);
await console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);})
console.log("resultSet columnNames:" + resultSet.columnNames);
console.log("resultSet columnCount:" + resultSet.columnCount);
})
```
......@@ -114,10 +115,11 @@ goTo(offset:number): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goTo(1)
resultSet.close()
resultSet = null
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goTo(1);
resultSet.close();
resultSet = null;
})
```
......@@ -140,10 +142,11 @@ goToRow(position: number): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goToRow(1)
resultSet.close()
resultSet = null
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToRow(1);
resultSet.close();
resultSet = null
})
```
......@@ -163,10 +166,11 @@ goToFirstRow(): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goToFirstRow()
resultSet.close()
resultSet = null;
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToFirstRow();
resultSet.close();
resultSet = null;
})
```
......@@ -184,10 +188,11 @@ goToLastRow(): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goToLastRow()
resultSet.close()
resultSet = null;
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToLastRow();
resultSet.close();
resultSet = null;
})
```
......@@ -205,10 +210,11 @@ goToNextRow(): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goToNextRow()
resultSet.close()
resultSet = null;
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToNextRow()
resultSet.close()
resultSet = null;
})
```
......@@ -226,10 +232,11 @@ goToPreviousRow(): boolean
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.goToPreviousRow()
resultSet.close()
resultSet = null
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToPreviousRow();
resultSet.close();
resultSet = null
})
```
......@@ -353,7 +360,8 @@ close(): void
- 示例:
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
resultSet.close()
resultSet = null
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.close();
resultSet = null
})
```
......@@ -48,11 +48,13 @@ getStorageSync(path: string): Storage
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let storage = dataStorage.getStorageSync(path + '/mystore')
storage.putSync('startup', 'auto')
storage.flushSync()
(async () => {
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let storage = dataStorage.getStorageSync(path + '/mystore')
storage.putSync('startup', 'auto')
storage.flushSync()
})()
```
......@@ -73,16 +75,18 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
dataStorage.getStorage(path + '/mystore', function (err, storage) {
if (err) {
console.info("Get the storage failed, path: " + path + '/mystore')
return;
}
storage.putSync('startup', 'auto')
storage.flushSync()
})
(async () => {
var context = featureAbility.getContext()
var path = await context.getFilesDir()
dataStorage.getStorage(path + '/mystore', function (err, storage) {
if (err) {
console.info("Get the storage failed, path: " + path + '/mystore')
return;
}
storage.putSync('startup', 'auto')
storage.flushSync()
})
})()
```
......@@ -107,15 +111,17 @@ getStorage(path: string): Promise&lt;Storage&gt;
import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
promise.then((storage) => {
storage.putSync('startup', 'auto')
storage.flushSync()
}).catch((err) => {
console.info("Get the storage failed, path: " + path + '/mystore')
})
(async () => {
var context = featureAbility.getContext()
var path = await context.getFilesDir()
let promise = dataStorage.getStorage(path + '/mystore')
promise.then((storage) => {
storage.putSync('startup', 'auto')
storage.flushSync()
}).catch((err) => {
console.info("Get the storage failed, path: " + path + '/mystore')
})
}()
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册