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

!9216 [翻译完成】#I5LOJF

Merge pull request !9216 from Annie_wang/PR7701
...@@ -169,8 +169,6 @@ You can use the APIs provided by **rdbStore** to back up and restore local datab ...@@ -169,8 +169,6 @@ You can use the APIs provided by **rdbStore** to back up and restore local datab
| ---- | ---- | ---- | | ---- | ---- | ---- |
| RdbStore | int Backup(const std::string databasePath, const std::vector&lt;uint8_t&gt; destEncryptKey) | Backs up the current database file.<br>- **databasePath**: name or path of the backup file to generate.<br>- **destEncryptKey**: key used to encrypt the RDB store. Currently, only non-encrypted RDB stores can be backed up. | | RdbStore | int Backup(const std::string databasePath, const std::vector&lt;uint8_t&gt; destEncryptKey) | Backs up the current database file.<br>- **databasePath**: name or path of the backup file to generate.<br>- **destEncryptKey**: key used to encrypt the RDB store. Currently, only non-encrypted RDB stores can be backed up. |
- Restoring an RDB store - Restoring an RDB store
Call **int Restore()** to restore an RDB from the backup file. **backupPath** specifies the name or path of the backup file. If the restore is successful, **0** is returned; otherwise, an error code is returned. Call **int Restore()** to restore an RDB from the backup file. **backupPath** specifies the name or path of the backup file. If the restore is successful, **0** is returned; otherwise, an error code is returned.
...@@ -187,11 +185,11 @@ You can use the APIs provided by **rdbStore** to back up and restore local datab ...@@ -187,11 +185,11 @@ You can use the APIs provided by **rdbStore** to back up and restore local datab
Table 16 Transaction APIs Table 16 Transaction APIs
| Class| API| Description| | Class| API| Description|
| ---- | ---- | ---- | | ---- | ---- | ---- |
| RdbStore | int BeginTransaction() | Starts a transaction.| | RdbStore | int BeginTransaction() | Starts a transaction.|
| RdbStore | int Commit() | Commits the changes.| | RdbStore | int Commit() | Commits the changes.|
| RdbStore | int RollBack() | Rolls back the changes.| | RdbStore | int RollBack() | Rolls back the changes.|
## Constraints ## Constraints
...@@ -208,9 +206,9 @@ None. ...@@ -208,9 +206,9 @@ None.
c. Create an RDB store. c. Create an RDB store.
The sample code is as follows: The sample code is as follows:
``` ```c++
const std::string DATABASE_NAME = RDB_TEST_PATH + "RdbStoreTest.db"; const std::string DATABASE_NAME = RDB_TEST_PATH + "RdbStoreTest.db";
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, salary REAL, blobType BLOB)"; const std::string CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, salary REAL, blobType BLOB)";
class OpenCallback : public RdbOpenCallback { class OpenCallback : public RdbOpenCallback {
public: public:
...@@ -238,7 +236,7 @@ None. ...@@ -238,7 +236,7 @@ None.
c. Create an RDB store. c. Create an RDB store.
The sample code is as follows: The sample code is as follows:
``` ```c++
ValuesBucket values; ValuesBucket values;
values.PutInt("id", 1); values.PutInt("id", 1);
...@@ -260,7 +258,7 @@ None. ...@@ -260,7 +258,7 @@ None.
d. Call the **ResultSet** APIs to traverse data in the result set. d. Call the **ResultSet** APIs to traverse data in the result set.
The sample code is as follows: The sample code is as follows:
``` ```c++
std::vector<std::string> columns = {"id", "name", "age", "salary"}; std::vector<std::string> columns = {"id", "name", "age", "salary"};
RdbPredicates predicates("test"); RdbPredicates predicates("test");
...@@ -275,7 +273,7 @@ None. ...@@ -275,7 +273,7 @@ None.
The sample code is as follows: The sample code is as follows:
``` ```c++
store->SetDistributedTables("test"); store->SetDistributedTables("test");
``` ```
...@@ -289,7 +287,7 @@ None. ...@@ -289,7 +287,7 @@ None.
The sample code is as follows: The sample code is as follows:
``` ```c++
SyncOption option; SyncOption option;
option.mode = PUSH; option.mode = PUSH;
option.isBlock = true; option.isBlock = true;
...@@ -312,7 +310,7 @@ None. ...@@ -312,7 +310,7 @@ None.
The sample code is as follows: The sample code is as follows:
``` ```c++
class MyObserver : public RdbStoreObserver { class MyObserver : public RdbStoreObserver {
public: public:
void OnChange(const std::vector<std::string>& devices) override { void OnChange(const std::vector<std::string>& devices) override {
...@@ -337,10 +335,10 @@ None. ...@@ -337,10 +335,10 @@ None.
b. Run SQL statements to query data in the RDB store of the remote device. b. Run SQL statements to query data in the RDB store of the remote device.
The sample code is as follows: The sample code is as follows:
``` ```c++
std::string tableName = store->ObtainDistributedTableName("123456789abcd", "test"); std::string tableName = store->ObtainDistributedTableName("123456789abcd", "test");
auto resultSet = store->QuerySql("SELECT * from ?;", tableName); auto resultSet = store->QuerySql("SELECT * from ?;", tableName);
``` ```
8. Back up and restore an RDB store. 8. Back up and restore an RDB store.
...@@ -349,9 +347,9 @@ None. ...@@ -349,9 +347,9 @@ None.
b. Restore the RDB store from the specified backup file. b. Restore the RDB store from the specified backup file.
The sample code is as follows: The sample code is as follows:
``` ```c++
std::string backupName = "backup.db"; // Name of the database backup file to generate. std::string backupName = "backup.db"; // Name of the database backup file to generate.
std::vector<uint8_t> key; // Key used to encrypt the RDB store. std::vector<uint8_t> key; // Key used to encrypt the RDB store.
int errno = store->Backup(backupName, key); int errno = store->Backup(backupName, key);
errno = store->Restore(backupName, key); errno = store->Restore(backupName, key);
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册