mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-27 01:01:02 +00:00
commit
05eb1a98fd
@ -371,7 +371,7 @@ int ConnPool::ChangeDbFileForRestore(const std::string &newPath, const std::stri
|
||||
CloseAllConnections();
|
||||
auto [retVal, conn] = Connection::Create(config_, false);
|
||||
if (retVal != E_OK) {
|
||||
LOG_ERROR("create connection fail, erroce:%{public}d", retVal);
|
||||
LOG_ERROR("create connection fail, errCode:%{public}d", retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@ -735,8 +735,17 @@ bool ConnectionPool::CheckIntegrity(const std::string &dbPath)
|
||||
config.SetPath(dbPath);
|
||||
config.SetIntegrityCheck(IntegrityCheck::FULL);
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
auto [ret, connection] = Connection::Create(config, true);
|
||||
return ret == E_OK;
|
||||
for (uint32_t retry = 0; retry < ITERS_COUNT; ++retry) {
|
||||
auto [ret, connection] = Connection::Create(config, true);
|
||||
if (ret == E_OK) {
|
||||
return true;
|
||||
}
|
||||
if (ret != E_SQLITE_CORRUPT || !config.IsEncrypt()) {
|
||||
break;
|
||||
}
|
||||
config.SetIter(ITER_V1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t ConnPool::Container::Clear()
|
||||
|
@ -15,8 +15,10 @@
|
||||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
|
||||
import data_relationalStore from '@ohos.data.relationalStore'
|
||||
import ability_featureAbility from '@ohos.ability.featureAbility'
|
||||
import factory from '@ohos.data.distributedKVStore'
|
||||
|
||||
const TAG = "[RELATIONAL_STORE_JSKITS_TEST]"
|
||||
const TEST_BUNDLE_NAME = "com.example.myapplication"
|
||||
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"
|
||||
|
||||
@ -732,5 +734,50 @@ describe('rdbEncryptTest', function () {
|
||||
console.log(TAG + "************* RdbDecryptTest_0090 end *************")
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.number testEncryptRdbAndKv0002
|
||||
* @tc.name Normal test case of using encrypt kv, then using rdb attach interface
|
||||
* @tc.desc 1.Get encrypt kv db
|
||||
* 2.Get encrypt rdb1
|
||||
* 3.rdb1.backup(rdb2)
|
||||
* 4.rdb1.restore(rdb2)
|
||||
*/
|
||||
it('testEncryptRdbAndKv0002', 0, async () => {
|
||||
console.log(TAG + "************* testEncryptRdbAndKv0002 start *************");
|
||||
let kvConfig = {
|
||||
bundleName: TEST_BUNDLE_NAME,
|
||||
context: context
|
||||
}
|
||||
let options = {
|
||||
createIfMissing: true,
|
||||
encrypt: true,
|
||||
backup: false,
|
||||
autoSync: false,
|
||||
kvStoreType: factory.KVStoreType.SINGLE_VERSION,
|
||||
securityLevel: factory.SecurityLevel.S2,
|
||||
}
|
||||
let rdbConfig = {
|
||||
name: "RdbTest.db",
|
||||
securityLevel: data_relationalStore.SecurityLevel.S1,
|
||||
encrypt: true,
|
||||
}
|
||||
let kvManager = factory.createKVManager(kvConfig);
|
||||
try {
|
||||
let kvDb = await kvManager.getKVStore('kvDb', options)
|
||||
rdbConfig.name = "RdbTest1.db"
|
||||
let rdbStore1 = await data_relationalStore.getRdbStore(context, rdbConfig);
|
||||
await rdbStore1.backup("RdbTest2.db");
|
||||
await rdbStore1.restore("RdbTest2.db");
|
||||
expect(true).assertTrue();
|
||||
} catch (err) {
|
||||
console.log(TAG + err);
|
||||
expect(null).assertFail();
|
||||
console.log(TAG + "testEncryptRdbAndKv0002 failed");
|
||||
}
|
||||
await kvManager.closeKVStore(TEST_BUNDLE_NAME, 'kvDb');
|
||||
await data_relationalStore.deleteRdbStore(context, "RdbTest1.db");
|
||||
await data_relationalStore.deleteRdbStore(context, "RdbTest2.db");
|
||||
console.log(TAG + "************* testEncryptRdbAndKv0002 end *************");
|
||||
})
|
||||
console.log(TAG + "*************Unit Test End*************")
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user