mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 07:00:41 +00:00
fix
Signed-off-by: Anvette <anwentao@huawei.com>
This commit is contained in:
parent
8c270c5a05
commit
20b8936f18
@ -423,17 +423,27 @@ int ConnPool::RestoreMasterDb(const std::string &newPath, const std::string &bac
|
||||
Connection::Delete(config);
|
||||
}
|
||||
|
||||
int ret = E_OK;
|
||||
if (!SqliteUtils::CopyFile(backupPath, newPath)) {
|
||||
ret = E_ERROR;
|
||||
bool copyRet = SqliteUtils::CopyFile(backupPath, newPath);
|
||||
int32_t errCode = E_OK;
|
||||
std::shared_ptr<Connection> pool;
|
||||
for (uint32_t retry = 0; retry < ITERS_COUNT; ++retry) {
|
||||
std::tie(errCode, pool) = Init();
|
||||
if (errCode == E_OK) {
|
||||
break;
|
||||
}
|
||||
if (errCode != E_SQLITE_CORRUPT || !config_.IsEncrypt()) {
|
||||
break;
|
||||
}
|
||||
config_.SetIter(ITER_V1);
|
||||
}
|
||||
auto result = Init();
|
||||
if (result.first != E_OK) {
|
||||
if (errCode != E_OK) {
|
||||
CloseAllConnections();
|
||||
Connection::Delete(config_);
|
||||
result = Init();
|
||||
std::tie(errCode, pool) = Init();
|
||||
LOG_WARN("restore failed! rebuild res:%{public}d, path:%{public}s.", errCode,
|
||||
SqliteUtils::Anonymous(backupPath).c_str());
|
||||
}
|
||||
return ret == E_OK ? result.first : ret;
|
||||
return copyRet ? errCode : E_ERROR;
|
||||
}
|
||||
|
||||
std::stack<BaseTransaction> &ConnPool::GetTransactionStack()
|
||||
|
@ -766,8 +766,20 @@ describe('rdbEncryptTest', function () {
|
||||
let kvDb = await kvManager.getKVStore('kvDb', options)
|
||||
rdbConfig.name = "RdbTest1.db"
|
||||
let rdbStore1 = await data_relationalStore.getRdbStore(context, rdbConfig);
|
||||
await rdbStore1?.executeSql(CREATE_TABLE_TEST);
|
||||
console.log(TAG + "testEncryptRdbAndKv0002 create table test success");
|
||||
await rdbStore1.backup("RdbTest2.db");
|
||||
console.log(TAG + "testEncryptRdbAndKv0002 backup success");
|
||||
await rdbStore1?.executeSql("drop table test");
|
||||
console.log(TAG + "testEncryptRdbAndKv0002 drop table test success");
|
||||
await rdbStore1.restore("RdbTest2.db");
|
||||
console.log(TAG + "testEncryptRdbAndKv0002 restore success");
|
||||
let valueBucket = {
|
||||
"name": "zhangsan",
|
||||
"age": 18,
|
||||
"salary": 100.5,
|
||||
};
|
||||
await rdbStore1.insert("test", valueBucket)
|
||||
expect(true).assertTrue();
|
||||
} catch (err) {
|
||||
console.log(TAG + err);
|
||||
|
Loading…
Reference in New Issue
Block a user