Merge pull request !1916 from Anvette/master
This commit is contained in:
openharmony_ci 2024-11-19 10:05:16 +00:00 committed by Gitee
commit 6a9ac6a056
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 29 additions and 7 deletions

View File

@ -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()

View File

@ -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);