mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 15:11:33 +00:00
匿名化信息
Change-Id: I0d496cfcfd2571df58bb6e99ec89a87843815d05 Signed-off-by: ZhaoJinghui <zhaojinghui5@huawei.com>
This commit is contained in:
parent
c3c746b58c
commit
aa11a271ea
@ -67,8 +67,8 @@ void RdbFaultHiViewReporter::InnerReportRdbCorrupted(RdbCorruptedEvent &eventInf
|
||||
if (eventInfo.walFileStatRet >= 0) {
|
||||
appendInfo = appendInfo + " \n WAL:" + GetFileStatInfo(eventInfo.walFileStat);
|
||||
}
|
||||
LOG_WARN("storeName: %{public}s, errorCode: %{public}d, appendInfo : %{public}s", storeName, eventInfo.errorCode,
|
||||
appendInfo.c_str());
|
||||
LOG_WARN("storeName: %{public}s, errorCode: %{public}d, appendInfo : %{public}s",
|
||||
SqliteUtils::Anonymous(eventInfo.storeName).c_str(), eventInfo.errorCode, appendInfo.c_str());
|
||||
std::string occurTime = GetTimeWithMilliseconds(eventInfo.errorOccurTime);
|
||||
char *errorOccurTime = occurTime.data();
|
||||
HiSysEventParam params[] = {
|
||||
|
@ -87,6 +87,9 @@ private:
|
||||
static constexpr size_t TYPE_SIZE = sizeof(SQL_TYPE_MAP) / sizeof(SqlType);
|
||||
static constexpr const char* ON_CONFLICT_CLAUSE[CONFLICT_CLAUSE_COUNT] = { "", " OR ROLLBACK", " OR ABORT",
|
||||
" OR FAIL", " OR IGNORE", " OR REPLACE" };
|
||||
|
||||
static int GetContinuousDigitsNum(const std::string& fileName);
|
||||
static std::string AnonyDigits(const std::string& fileName, int digitsNum);
|
||||
};
|
||||
|
||||
} // namespace NativeRdb
|
||||
|
@ -257,7 +257,7 @@ int AbsResultSet::GetRow(RowEntity &rowEntity)
|
||||
ValueObject value;
|
||||
auto ret = Get(index, value);
|
||||
if (ret != E_OK) {
|
||||
LOG_ERROR("Get(%{public}d, %{public}s)->ret %{public}d", index, name.c_str(), ret);
|
||||
LOG_ERROR("Get(%{public}d, %{public}s)->ret %{public}d", index, SqliteUtils::Anonymous(name).c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
rowEntity.Put(name, index, std::move(value));
|
||||
@ -404,7 +404,7 @@ int AbsResultSet::GetColumnIndex(const std::string &columnName, int &columnIndex
|
||||
return E_OK;
|
||||
}
|
||||
}
|
||||
LOG_ERROR("failed, columnName is: %{public}s", columnName.c_str());
|
||||
LOG_ERROR("failed, columnName is: %{public}s", SqliteUtils::Anonymous(columnName).c_str());
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,8 @@ std::pair<RebuiltType, std::shared_ptr<ConnectionPool>> ConnPool::HandleDataCorr
|
||||
pool = Create(storeConfig, errCode);
|
||||
if (errCode != E_OK) {
|
||||
LOG_WARN("failed, type %{public}d db %{public}s encrypt %{public}d error %{public}d, errno",
|
||||
static_cast<uint32_t>(rebuiltType), storeConfig.GetName().c_str(), storeConfig.IsEncrypt(), errCode, errno);
|
||||
static_cast<uint32_t>(rebuiltType), SqliteUtils::Anonymous(storeConfig.GetName()).c_str(),
|
||||
storeConfig.IsEncrypt(), errCode, errno);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -78,7 +78,7 @@ int RdbHelper::DeleteRdbStore(const std::string &dbFileName)
|
||||
return E_INVALID_FILE_PATH;
|
||||
}
|
||||
if (access(dbFileName.c_str(), F_OK) != 0) {
|
||||
LOG_ERROR("Store to delete doesn't exist, path %{public}s", dbFileName.c_str());
|
||||
LOG_ERROR("Store to delete doesn't exist, path %{public}s", SqliteUtils::Anonymous(dbFileName).c_str());
|
||||
return E_OK; // not not exist
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ int RdbHelper::DeleteRdbStore(const std::string &dbFileName)
|
||||
|
||||
int errCode = (errCodeSqlite == E_OK && errCodeVector == E_OK) ? E_OK : E_REMOVE_FILE;
|
||||
LOG_INFO("Delete rdb store ret sqlite=%{public}d, vector=%{public}d, path %{public}s",
|
||||
errCodeSqlite, errCodeVector, dbFileName.c_str());
|
||||
errCodeSqlite, errCodeVector, SqliteUtils::Anonymous(dbFileName).c_str());
|
||||
return errCode;
|
||||
}
|
||||
|
||||
@ -107,13 +107,13 @@ int RdbHelper::DeleteRdbStore(const RdbStoreConfig &config)
|
||||
return E_INVALID_FILE_PATH;
|
||||
}
|
||||
if (access(dbFile.c_str(), F_OK) != 0) {
|
||||
LOG_ERROR("not exist, path %{public}s", dbFile.c_str());
|
||||
LOG_ERROR("not exist, path %{public}s", SqliteUtils::Anonymous(dbFile).c_str());
|
||||
return E_OK; // not not exist
|
||||
}
|
||||
RdbStoreManager::GetInstance().Delete(dbFile);
|
||||
Connection::Delete(config);
|
||||
RdbSecurityManager::GetInstance().DelAllKeyFiles(dbFile);
|
||||
LOG_INFO("Delete rdb store, path %{public}s", dbFile.c_str());
|
||||
LOG_INFO("Delete rdb store, path %{public}s", SqliteUtils::Anonymous(dbFile).c_str());
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace NativeRdb
|
||||
|
@ -612,15 +612,12 @@ bool RdbSecurityManager::HasRootKey()
|
||||
|
||||
bool RdbSecurityManager::IsKeyFileEmpty(const std::string &keyFile)
|
||||
{
|
||||
if (access(keyFile.c_str(), F_OK) != 0) {
|
||||
return true;
|
||||
}
|
||||
struct stat fileInfo;
|
||||
auto errCode = stat(keyFile.c_str(), &fileInfo);
|
||||
if (errCode == 0 && fileInfo.st_size == 0) {
|
||||
if (errCode != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return fileInfo.st_size == 0;
|
||||
}
|
||||
|
||||
int32_t RdbSecurityManager::RestoreKeyFile(const std::string &dbPath, const std::vector<uint8_t> &key)
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_platform.h"
|
||||
#include "sqlite_sql_builder.h"
|
||||
#include "sqlite_utils.h"
|
||||
namespace OHOS {
|
||||
using namespace Rdb;
|
||||
namespace NativeRdb {
|
||||
@ -51,7 +52,8 @@ int RdbSqlUtils::CreateDirectory(const std::string &databaseDir)
|
||||
databaseDirectory = databaseDirectory + "/" + directory;
|
||||
if (access(databaseDirectory.c_str(), F_OK) != 0) {
|
||||
if (MkDir(databaseDirectory)) {
|
||||
LOG_ERROR("failed to mkdir errno[%{public}d] %{public}s", errno, databaseDirectory.c_str());
|
||||
LOG_ERROR("failed to mkdir errno[%{public}d] %{public}s", errno,
|
||||
SqliteUtils::Anonymous(databaseDirectory).c_str());
|
||||
return E_CREATE_FOLDER_FAIL;
|
||||
}
|
||||
// Set the default ACL attribute to the database root directory to ensure that files created by the server
|
||||
@ -80,8 +82,9 @@ std::pair<std::string, int> RdbSqlUtils::GetDefaultDatabasePath(const std::strin
|
||||
|
||||
errorCode = CreateDirectory(databaseDir);
|
||||
if (errorCode != E_OK) {
|
||||
LOG_ERROR("failed errno[%{public}d] baseDir : %{public}s name : %{public}s customDir : %{public}s",
|
||||
errno, baseDir.c_str(), name.c_str(), customDir.c_str());
|
||||
LOG_ERROR("failed errno[%{public}d] baseDir : %{public}s name : %{public}s customDir : %{public}s", errno,
|
||||
SqliteUtils::Anonymous(baseDir).c_str(), SqliteUtils::Anonymous(name).c_str(),
|
||||
SqliteUtils::Anonymous(customDir).c_str());
|
||||
}
|
||||
return std::make_pair(databaseDir.append("/").append(name), errorCode);
|
||||
}
|
||||
@ -94,8 +97,8 @@ std::string RdbSqlUtils::GetDefaultDatabasePath(const std::string &baseDir, cons
|
||||
std::string databaseDir = baseDir + "/rdb";
|
||||
errorCode = CreateDirectory(databaseDir);
|
||||
if (errorCode != E_OK) {
|
||||
LOG_ERROR(
|
||||
"failed errno[%{public}d] baseDir : %{public}s name : %{public}s", errno, baseDir.c_str(), name.c_str());
|
||||
LOG_ERROR("failed errno[%{public}d] baseDir : %{public}s name : %{public}s", errno,
|
||||
SqliteUtils::Anonymous(baseDir).c_str(), SqliteUtils::Anonymous(name).c_str());
|
||||
}
|
||||
return databaseDir.append("/").append(name);
|
||||
}
|
||||
|
@ -134,7 +134,8 @@ void RdbStoreImpl::UploadSchema(const DistributedRdb::RdbSyncerParam ¶m, uin
|
||||
return;
|
||||
}
|
||||
if (err != E_OK || service == nullptr) {
|
||||
LOG_ERROR("GetRdbService failed, err: %{public}d, storeName: %{public}s.", err, param.storeName_.c_str());
|
||||
LOG_ERROR("GetRdbService failed, err: %{public}d, storeName: %{public}s.", err,
|
||||
SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
auto pool = TaskExecutor::GetInstance().GetExecutor();
|
||||
if (err == E_SERVICE_NOT_FOUND && pool != nullptr && retry++ < MAX_RETRY_TIMES) {
|
||||
pool->Schedule(std::chrono::seconds(RETRY_INTERVAL), [param, retry]() { UploadSchema(param, retry); });
|
||||
@ -143,7 +144,8 @@ void RdbStoreImpl::UploadSchema(const DistributedRdb::RdbSyncerParam ¶m, uin
|
||||
}
|
||||
err = service->AfterOpen(param);
|
||||
if (err != E_OK) {
|
||||
LOG_ERROR("AfterOpen failed, err: %{public}d, storeName: %{public}s.", err, param.storeName_.c_str());
|
||||
LOG_ERROR("AfterOpen failed, err: %{public}d, storeName: %{public}s.", err,
|
||||
SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +319,7 @@ RdbStoreImpl::RdbStoreImpl(const RdbStoreConfig &config, int &errCode)
|
||||
connectionPool_ = ConnectionPool::Create(config_, errCode);
|
||||
InitSyncerParam();
|
||||
if (connectionPool_ == nullptr && errCode == E_SQLITE_CORRUPT && config.GetAllowRebuild() && !config.IsReadOnly()) {
|
||||
LOG_ERROR("database corrupt, rebuild database %{public}s", name_.c_str());
|
||||
LOG_ERROR("database corrupt, rebuild database %{public}s", SqliteUtils::Anonymous(name_).c_str());
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
auto [err, service] = RdbMgr::GetInstance().GetRdbService(syncerParam_);
|
||||
if (service != nullptr) {
|
||||
@ -333,7 +335,8 @@ RdbStoreImpl::RdbStoreImpl(const RdbStoreConfig &config, int &errCode)
|
||||
}
|
||||
if (connectionPool_ == nullptr || errCode != E_OK) {
|
||||
connectionPool_ = nullptr;
|
||||
LOG_ERROR("Create connPool failed, err is %{public}d, path:%{public}s", errCode, path_.c_str());
|
||||
LOG_ERROR("Create connPool failed, err is %{public}d, path:%{public}s", errCode,
|
||||
SqliteUtils::Anonymous(path_).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -866,7 +869,7 @@ int RdbStoreImpl::ExecuteSqlEntry(const std::string &sql, const std::vector<Valu
|
||||
statement = nullptr;
|
||||
if (vSchema_ < static_cast<int64_t>(version)) {
|
||||
LOG_INFO("db:%{public}s exe DDL schema<%{public}" PRIi64 "->%{public}" PRIi64 "> sql:%{public}s.",
|
||||
name_.c_str(), vSchema_, static_cast<int64_t>(version), sql.c_str());
|
||||
SqliteUtils::Anonymous(name_).c_str(), vSchema_, static_cast<int64_t>(version), sql.c_str());
|
||||
vSchema_ = version;
|
||||
errCode = connectionPool_->RestartReaders();
|
||||
}
|
||||
@ -915,7 +918,7 @@ std::pair<int32_t, ValueObject> RdbStoreImpl::HandleDifferentSqlTypes(std::share
|
||||
auto [err, version] = statement->ExecuteForValue();
|
||||
if (vSchema_ < static_cast<int64_t>(version)) {
|
||||
LOG_INFO("db:%{public}s exe DDL schema<%{public}" PRIi64 "->%{public}" PRIi64 "> sql:%{public}s.",
|
||||
name_.c_str(), vSchema_, static_cast<int64_t>(version), sql.c_str());
|
||||
SqliteUtils::Anonymous(name_).c_str(), vSchema_, static_cast<int64_t>(version), sql.c_str());
|
||||
vSchema_ = version;
|
||||
errCode = connectionPool_->RestartReaders();
|
||||
}
|
||||
@ -1097,7 +1100,7 @@ int RdbStoreImpl::ExecuteSqlInner(const std::string &sql, const std::vector<Valu
|
||||
*/
|
||||
int RdbStoreImpl::Backup(const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey)
|
||||
{
|
||||
LOG_INFO("Backup db: %{public}s.", config_.GetName().c_str());
|
||||
LOG_INFO("Backup db: %{public}s.", SqliteUtils::Anonymous(config_.GetName()).c_str());
|
||||
if ((config_.GetRoleType() == VISITOR)) {
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
@ -1328,7 +1331,8 @@ std::pair<int32_t, int32_t> RdbStoreImpl::Attach(
|
||||
} else if (err != E_OK) {
|
||||
LOG_ERROR("failed, errCode[%{public}d] fileName[%{public}s] attachName[%{public}s] attach fileName"
|
||||
"[%{public}s]",
|
||||
err, config_.GetName().c_str(), attachName.c_str(), config.GetName().c_str());
|
||||
err, SqliteUtils::Anonymous(config_.GetName()).c_str(), attachName.c_str(),
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str());
|
||||
return { err, 0 };
|
||||
}
|
||||
if (!attachedInfo_.Insert(attachName, dbPath)) {
|
||||
@ -1361,7 +1365,7 @@ std::pair<int32_t, int32_t> RdbStoreImpl::Detach(const std::string &attachName,
|
||||
errCode = statement->Execute(bindArgs);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("failed, errCode[%{public}d] fileName[%{public}s] attachName[%{public}s] attach", errCode,
|
||||
config_.GetName().c_str(), attachName.c_str());
|
||||
SqliteUtils::Anonymous(config_.GetName()).c_str(), attachName.c_str());
|
||||
return { errCode, 0 };
|
||||
}
|
||||
|
||||
@ -1432,7 +1436,7 @@ int RdbStoreImpl::BeginTransaction()
|
||||
errCode = statement->Execute();
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, name_.c_str(), errCode);
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
|
||||
return errCode;
|
||||
}
|
||||
@ -1441,7 +1445,7 @@ int RdbStoreImpl::BeginTransaction()
|
||||
// 1 means the number of transactions in process
|
||||
if (transactionId > 1) {
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, name_.c_str(), errCode);
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
@ -1458,7 +1462,8 @@ std::pair<int, int64_t> RdbStoreImpl::BeginTrans()
|
||||
int64_t tmpTrxId = 0;
|
||||
auto [errCode, connection] = connectionPool_->CreateConnection(false);
|
||||
if (connection == nullptr) {
|
||||
LOG_ERROR("Get null connection, storeName: %{public}s time:%{public}" PRIu64 ".", name_.c_str(), time);
|
||||
LOG_ERROR("Get null connection, storeName: %{public}s time:%{public}" PRIu64 ".",
|
||||
SqliteUtils::Anonymous(name_).c_str(), time);
|
||||
return {errCode, 0};
|
||||
}
|
||||
tmpTrxId = newTrxId_.fetch_add(1);
|
||||
@ -1483,7 +1488,8 @@ int RdbStoreImpl::RollBack()
|
||||
size_t transactionId = connectionPool_->GetTransactionStack().size();
|
||||
|
||||
if (connectionPool_->GetTransactionStack().empty()) {
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s", transactionId, name_.c_str());
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str());
|
||||
return E_NO_TRANSACTION_IN_SESSION;
|
||||
}
|
||||
BaseTransaction transaction = connectionPool_->GetTransactionStack().top();
|
||||
@ -1494,13 +1500,14 @@ int RdbStoreImpl::RollBack()
|
||||
auto [errCode, statement] = GetStatement(transaction.GetRollbackStr());
|
||||
if (statement == nullptr) {
|
||||
// size + 1 means the number of transactions in process
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s", transactionId + 1, name_.c_str());
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s", transactionId + 1,
|
||||
SqliteUtils::Anonymous(name_).c_str());
|
||||
return E_DATABASE_BUSY;
|
||||
}
|
||||
errCode = statement->Execute();
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, name_.c_str(), errCode);
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return errCode;
|
||||
}
|
||||
if (connectionPool_->GetTransactionStack().empty()) {
|
||||
@ -1509,7 +1516,7 @@ int RdbStoreImpl::RollBack()
|
||||
// 1 means the number of transactions in process
|
||||
if (transactionId > 1) {
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, name_.c_str(), errCode);
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
@ -1532,7 +1539,8 @@ int RdbStoreImpl::ExecuteByTrxId(const std::string &sql, int64_t trxId, bool clo
|
||||
auto result = trxConnMap_.Find(trxId);
|
||||
auto connection = result.second;
|
||||
if (connection == nullptr) {
|
||||
LOG_ERROR("Get null connection, storeName: %{public}s time:%{public}" PRIu64 ".", name_.c_str(), time);
|
||||
LOG_ERROR("Get null connection, storeName: %{public}s time:%{public}" PRIu64 ".",
|
||||
SqliteUtils::Anonymous(name_).c_str(), time);
|
||||
return E_ERROR;
|
||||
}
|
||||
auto [ret, statement] = GetStatement(sql, connection);
|
||||
@ -1541,9 +1549,8 @@ int RdbStoreImpl::ExecuteByTrxId(const std::string &sql, int64_t trxId, bool clo
|
||||
}
|
||||
ret = statement->Execute(bindArgs);
|
||||
if (ret != E_OK) {
|
||||
LOG_ERROR(
|
||||
"transaction id: %{public}" PRIu64 ", storeName: %{public}s, errCode: %{public}d" PRIu64, trxId,
|
||||
name_.c_str(), ret);
|
||||
LOG_ERROR("transaction id: %{public}" PRIu64 ", storeName: %{public}s, errCode: %{public}d" PRIu64, trxId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), ret);
|
||||
trxConnMap_.Erase(trxId);
|
||||
return ret;
|
||||
}
|
||||
@ -1578,25 +1585,27 @@ int RdbStoreImpl::Commit()
|
||||
std::string sqlStr = transaction.GetCommitStr();
|
||||
if (sqlStr.size() <= 1) {
|
||||
LOG_WARN("id: %{public}zu, storeName: %{public}s, sql: %{public}s",
|
||||
transactionId, name_.c_str(), sqlStr.c_str());
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), sqlStr.c_str());
|
||||
connectionPool_->GetTransactionStack().pop();
|
||||
return E_OK;
|
||||
}
|
||||
auto [errCode, statement] = GetStatement(sqlStr);
|
||||
if (statement == nullptr) {
|
||||
LOG_ERROR("id: %{public}zu, storeName: %{public}s, statement error", transactionId, name_.c_str());
|
||||
LOG_ERROR("id: %{public}zu, storeName: %{public}s, statement error", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str());
|
||||
return E_DATABASE_BUSY;
|
||||
}
|
||||
errCode = statement->Execute();
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, name_.c_str(), errCode);
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return errCode;
|
||||
}
|
||||
connectionPool_->SetInTransaction(false);
|
||||
// 1 means the number of transactions in process
|
||||
if (transactionId > 1) {
|
||||
LOG_WARN("id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId, name_.c_str(), errCode);
|
||||
LOG_WARN("id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
}
|
||||
connectionPool_->GetTransactionStack().pop();
|
||||
return E_OK;
|
||||
@ -1772,7 +1781,7 @@ int RdbStoreImpl::GetDestPath(const std::string &backupPath, std::string &destPa
|
||||
|
||||
int RdbStoreImpl::Restore(const std::string &backupPath, const std::vector<uint8_t> &newKey)
|
||||
{
|
||||
LOG_INFO("Restore db: %{public}s.", config_.GetName().c_str());
|
||||
LOG_INFO("Restore db: %{public}s.", SqliteUtils::Anonymous(config_.GetName()).c_str());
|
||||
if (config_.IsReadOnly()) {
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
@ -2041,7 +2050,7 @@ int32_t RdbStoreImpl::SubscribeLocalDetail(const SubscribeOption &option,
|
||||
int32_t errCode = connection->Subscribe(option.event, observer);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("subscribe local detail observer failed. db name:%{public}s errCode:%{public}" PRId32,
|
||||
config_.GetName().c_str(), errCode);
|
||||
SqliteUtils::Anonymous(config_.GetName()).c_str(), errCode);
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
@ -2174,7 +2183,7 @@ int32_t RdbStoreImpl::UnsubscribeLocalDetail(const SubscribeOption& option,
|
||||
int32_t errCode = connection->Unsubscribe(option.event, observer);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("unsubscribe local detail observer failed. db name:%{public}s errCode:%{public}" PRId32,
|
||||
config_.GetName().c_str(), errCode);
|
||||
SqliteUtils::Anonymous(config_.GetName()).c_str(), errCode);
|
||||
}
|
||||
return errCode;
|
||||
}
|
||||
@ -2537,7 +2546,7 @@ int32_t RdbStoreImpl::ExchangeSlaverToMaster()
|
||||
}
|
||||
auto strategy = conn->GenerateExchangeStrategy(slaveStatus_);
|
||||
if (strategy != ExchangeStrategy::NOT_HANDLE) {
|
||||
LOG_WARN("exchange st:%{public}d, %{public}s,", strategy, config_.GetName().c_str());
|
||||
LOG_WARN("exchange st:%{public}d, %{public}s,", strategy, SqliteUtils::Anonymous(config_.GetName()).c_str());
|
||||
}
|
||||
int ret = E_OK;
|
||||
if (strategy == ExchangeStrategy::RESTORE) {
|
||||
|
@ -83,8 +83,8 @@ std::shared_ptr<RdbStore> RdbStoreManager::GetRdbStore(const RdbStoreConfig &con
|
||||
if (config.GetRoleType() == OWNER && !config.IsReadOnly()) {
|
||||
errCode = SetSecurityLabel(config);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("fail, storeName:%{public}s security %{public}d errCode:%{public}d", config.GetName().c_str(),
|
||||
config.GetSecurityLevel(), errCode);
|
||||
LOG_ERROR("fail, storeName:%{public}s security %{public}d errCode:%{public}d",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), config.GetSecurityLevel(), errCode);
|
||||
return nullptr;
|
||||
}
|
||||
if (config.IsVector()) {
|
||||
@ -95,7 +95,8 @@ std::shared_ptr<RdbStore> RdbStoreManager::GetRdbStore(const RdbStoreConfig &con
|
||||
errCode = ProcessOpenCallback(*rdbStore, config, version, openCallback);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("fail, storeName:%{public}s path:%{public}s ProcessOpenCallback errCode:%{public}d",
|
||||
config.GetName().c_str(), config.GetPath().c_str(), errCode);
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
SqliteUtils::Anonymous(config.GetPath()).c_str(), errCode);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -109,11 +110,11 @@ bool RdbStoreManager::IsConfigInvalidChanged(const std::string &path, const RdbS
|
||||
Param param = GetSyncParam(config);
|
||||
Param tempParam;
|
||||
if (bundleName_.empty()) {
|
||||
LOG_WARN("Config has no bundleName, path: %{public}s", path.c_str());
|
||||
LOG_WARN("Config has no bundleName, path: %{public}s", SqliteUtils::Anonymous(path).c_str());
|
||||
return false;
|
||||
}
|
||||
if (!configCache_.Get(path, tempParam)) {
|
||||
LOG_WARN("Not found config cache, path: %{public}s", path.c_str());
|
||||
LOG_WARN("Not found config cache, path: %{public}s", SqliteUtils::Anonymous(path).c_str());
|
||||
tempParam = param;
|
||||
if (GetParamFromService(tempParam) == E_OK) {
|
||||
configCache_.Set(path, tempParam);
|
||||
@ -126,8 +127,8 @@ bool RdbStoreManager::IsConfigInvalidChanged(const std::string &path, const RdbS
|
||||
tempParam.isEncrypt_ != param.isEncrypt_) {
|
||||
LOG_ERROR("Store config invalid change, storeName %{public}s, securitylevel: %{public}d -> %{public}d, "
|
||||
"area: %{public}d -> %{public}d, isEncrypt: %{public}d -> %{public}d",
|
||||
path.c_str(), tempParam.level_, param.level_, tempParam.area_, param.area_, tempParam.isEncrypt_,
|
||||
param.isEncrypt_);
|
||||
SqliteUtils::Anonymous(path).c_str(), tempParam.level_, param.level_, tempParam.area_, param.area_,
|
||||
tempParam.isEncrypt_, param.isEncrypt_);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -115,8 +115,7 @@ int SqliteConnection::CreateSlaveConnection(const RdbStoreConfig &config, bool i
|
||||
if (errCode != E_OK) {
|
||||
SqliteUtils::TryAccessSlaveLock(config_.GetPath(), false, true, true);
|
||||
if (errCode == E_SQLITE_CORRUPT) {
|
||||
LOG_WARN("slave corrupt, rebuild:%{public}s",
|
||||
SqliteUtils::Anonymous(config.GetPath()).c_str());
|
||||
LOG_WARN("slave corrupt, rebuild:%{public}s", SqliteUtils::Anonymous(config.GetPath()).c_str());
|
||||
(void)Delete(config);
|
||||
errCode = slaveConnection_->InnerOpen(config);
|
||||
if (errCode != E_OK) {
|
||||
@ -196,22 +195,33 @@ int SqliteConnection::InnerOpen(const RdbStoreConfig &config)
|
||||
}
|
||||
|
||||
if (isWriter_) {
|
||||
struct stat fileInfo;
|
||||
if (stat(dbPath.c_str(), &fileInfo) == 0) {
|
||||
LOG_INFO("open database path [%{public}s] ino[%{public}" PRIu32
|
||||
"] config is [%{public}d, %{public}d, %{public}d, %{public}d, %{public}s, %{public}s, %{public}d,"
|
||||
"%{public}d, %{public}d]",
|
||||
SqliteUtils::Anonymous(dbPath).c_str(), static_cast<uint32_t>(fileInfo.st_ino), config.IsEncrypt(), config.GetArea(),
|
||||
config.GetHaMode(), config.GetSecurityLevel(), SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
config.GetBundleName().c_str(), config.GetRoleType(), config.IsReadOnly(), config.GetDBType());
|
||||
}
|
||||
TryCheckPoint();
|
||||
ValueObject checkResult{"ok"};
|
||||
auto index = static_cast<uint32_t>(config.GetIntegrityCheck());
|
||||
if (index < static_cast<uint32_t>(sizeof(INTEGRITIES) / sizeof(INTEGRITIES[0]))) {
|
||||
auto sql = INTEGRITIES[index];
|
||||
if (sql != nullptr) {
|
||||
LOG_INFO("%{public}s : %{public}s, ", sql, config.GetName().c_str());
|
||||
LOG_INFO("%{public}s : %{public}s, ", sql, SqliteUtils::Anonymous(config.GetName()).c_str());
|
||||
std::tie(errCode, checkResult) = ExecuteForValue(sql);
|
||||
}
|
||||
if (errCode == E_OK && static_cast<std::string>(checkResult) != "ok") {
|
||||
LOG_ERROR("%{public}s integrity check result is %{public}s, sql:%{public}s", config.GetName().c_str(),
|
||||
LOG_ERROR("%{public}s integrity check result is %{public}s, sql:%{public}s",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
static_cast<std::string>(checkResult).c_str(), sql);
|
||||
ReportDbCorruptedEvent(errCode, static_cast<std::string>(checkResult));
|
||||
} else {
|
||||
LOG_DEBUG("%{public}s integrity check err:%{public}d, result is %{public}s, sql:%{public}s",
|
||||
config.GetName().c_str(), errCode, static_cast<std::string>(checkResult).c_str(), sql);
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), errCode,
|
||||
static_cast<std::string>(checkResult).c_str(), sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,7 +262,7 @@ int32_t SqliteConnection::OpenDatabase(const std::string &dbPath, int openFileFl
|
||||
int errCode = sqlite3_open_v2(dbPath.c_str(), &dbHandle_, openFileFlags, nullptr);
|
||||
if (errCode != SQLITE_OK) {
|
||||
LOG_ERROR("fail to open database errCode=%{public}d, dbPath=%{public}s, flags=%{public}d, errno=%{public}d",
|
||||
errCode, dbPath.c_str(), openFileFlags, errno);
|
||||
errCode, SqliteUtils::Anonymous(dbPath).c_str(), openFileFlags, errno);
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
auto const pos = dbPath.find_last_of("\\/");
|
||||
if (pos != std::string::npos) {
|
||||
@ -532,7 +542,8 @@ int SqliteConnection::ReSetKey(const RdbStoreConfig &config)
|
||||
if (!IsWriter()) {
|
||||
return E_OK;
|
||||
}
|
||||
LOG_INFO("name = %{public}s, iter = %{public}d", config.GetName().c_str(), config.GetIter());
|
||||
LOG_INFO("name = %{public}s, iter = %{public}d", SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
config.GetIter());
|
||||
std::vector<uint8_t> newKey = config.GetNewEncryptKey();
|
||||
int errCode = sqlite3_rekey(dbHandle_, static_cast<const void *>(newKey.data()), static_cast<int>(newKey.size()));
|
||||
newKey.assign(newKey.size(), 0);
|
||||
@ -557,15 +568,15 @@ int SqliteConnection::SetEncrypt(const RdbStoreConfig &config)
|
||||
key.assign(key.size(), 0);
|
||||
if (errCode != E_OK) {
|
||||
if (!newKey.empty()) {
|
||||
LOG_INFO("use new key, iter=%{public}d err=%{public}d errno=%{public}d name=%{public}s",
|
||||
config.GetIter(), errCode, errno, config.GetName().c_str());
|
||||
LOG_INFO("use new key, iter=%{public}d err=%{public}d errno=%{public}d name=%{public}s", config.GetIter(),
|
||||
errCode, errno, SqliteUtils::Anonymous(config.GetName()).c_str());
|
||||
errCode = SetEncryptKey(newKey, config.GetIter());
|
||||
}
|
||||
newKey.assign(newKey.size(), 0);
|
||||
if (errCode != E_OK) {
|
||||
errCode = SetServiceKey(config, errCode);
|
||||
LOG_ERROR("fail, iter=%{public}d err=%{public}d errno=%{public}d name=%{public}s", config.GetIter(),
|
||||
errCode, errno, config.GetName().c_str());
|
||||
errCode, errno, SqliteUtils::Anonymous(config.GetName()).c_str());
|
||||
return errCode;
|
||||
}
|
||||
config.ChangeEncryptKey();
|
||||
@ -1146,8 +1157,8 @@ int32_t SqliteConnection::Backup(const std::string &databasePath, const std::vec
|
||||
LOG_INFO("backing up, return:%{public}s", config_.GetName().c_str());
|
||||
return E_OK;
|
||||
}
|
||||
LOG_INFO("begin backup to slave:%{public}s, isAsync:%{public}d", SqliteUtils::Anonymous(databasePath).c_str(),
|
||||
isAsync);
|
||||
LOG_INFO("begin backup to slave:%{public}s, isAsync:%{public}d",
|
||||
SqliteUtils::Anonymous(databasePath).c_str(), isAsync);
|
||||
if (!isAsync) {
|
||||
if (slaveConnection_ == nullptr) {
|
||||
RdbStoreConfig rdbSlaveStoreConfig = GetSlaveRdbStoreConfig(config_);
|
||||
@ -1207,13 +1218,13 @@ int SqliteConnection::LoadExtension(const RdbStoreConfig &config, sqlite3 *dbHan
|
||||
continue;
|
||||
}
|
||||
if (access(path.c_str(), F_OK) != 0) {
|
||||
LOG_ERROR("no file, errno:%{public}d %{public}s", errno, path.c_str());
|
||||
LOG_ERROR("no file, errno:%{public}d %{public}s", errno, SqliteUtils::Anonymous(path).c_str());
|
||||
return E_INVALID_FILE_PATH;
|
||||
}
|
||||
err = sqlite3_load_extension(dbHandle, path.c_str(), nullptr, nullptr);
|
||||
if (err != SQLITE_OK) {
|
||||
LOG_ERROR("load error. err=%{public}d, errno=%{public}d, errmsg:%{public}s, lib=%{public}s",
|
||||
err, errno, sqlite3_errmsg(dbHandle), path.c_str());
|
||||
LOG_ERROR("load error. err=%{public}d, errno=%{public}d, errmsg:%{public}s, lib=%{public}s", err, errno,
|
||||
sqlite3_errmsg(dbHandle), SqliteUtils::Anonymous(path).c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1385,7 +1396,7 @@ int32_t SqliteConnection::Repair(const RdbStoreConfig &config)
|
||||
ret = connection->ExchangeSlaverToMaster(true, curStatus);
|
||||
if (ret != E_OK) {
|
||||
LOG_ERROR("repair failed, [%{public}s]->[%{public}s], err:%{public}d", rdbSlaveStoreConfig.GetName().c_str(),
|
||||
config.GetName().c_str(), ret);
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), ret);
|
||||
} else {
|
||||
LOG_INFO("repair main success:%{public}s", SqliteUtils::Anonymous(config.GetPath()).c_str());
|
||||
}
|
||||
|
@ -60,12 +60,13 @@ void SqliteGlobalConfig::Log(const void *data, int err, const char *msg)
|
||||
if (errType == 0 || errType == SQLITE_CONSTRAINT || errType == SQLITE_SCHEMA || errType == SQLITE_NOTICE
|
||||
|| err == SQLITE_WARNING_AUTOINDEX) {
|
||||
if (verboseLog) {
|
||||
LOG_INFO("Error(%{public}d) %{public}s ", err, msg);
|
||||
LOG_INFO("Error(%{public}d) %{public}s ", err, SqliteUtils::Anonymous(msg).c_str());
|
||||
}
|
||||
} else if (errType == SQLITE_WARNING) {
|
||||
LOG_WARN("WARNING(%{public}d) %{public}s ", err, msg);
|
||||
LOG_WARN("WARNING(%{public}d) %{public}s ", err, SqliteUtils::Anonymous(msg).c_str());
|
||||
} else {
|
||||
LOG_ERROR("Error(%{public}d) errno is:%{public}d %{public}s.", err, errno, msg);
|
||||
LOG_ERROR("Error(%{public}d) errno is:%{public}d %{public}s.", err, errno,
|
||||
SqliteUtils::Anonymous(msg).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,8 +111,8 @@ int SqliteGlobalConfig::GetDbPath(const RdbStoreConfig &config, std::string &dbP
|
||||
|
||||
if (config.GetStorageMode() == StorageMode::MODE_MEMORY) {
|
||||
if (config.GetRoleType() == VISITOR) {
|
||||
LOG_ERROR("not support MODE_MEMORY, storeName:%{public}s, role:%{public}d", config.GetName().c_str(),
|
||||
config.GetRoleType());
|
||||
LOG_ERROR("not support MODE_MEMORY, storeName:%{public}s, role:%{public}d",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), config.GetRoleType());
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
dbPath = SqliteGlobalConfig::GetMemoryDbPath();
|
||||
|
@ -99,7 +99,8 @@ void SqliteStatement::PrintInfoForDbError(int errorCode)
|
||||
}
|
||||
if (errorCode == E_SQLITE_ERROR || errorCode == E_SQLITE_BUSY || errorCode == E_SQLITE_LOCKED ||
|
||||
errorCode == E_SQLITE_IOERR || errorCode == E_SQLITE_CORRUPT || errorCode == E_SQLITE_CANTOPEN) {
|
||||
LOG_ERROR(" DbError errorCode: %{public}d DbName: %{public}s ", errorCode, config_->GetName().c_str());
|
||||
LOG_ERROR(" DbError errorCode: %{public}d DbName: %{public}s ", errorCode,
|
||||
SqliteUtils::Anonymous(config_->GetName()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +116,8 @@ void SqliteStatement::ReadFile2Buffer()
|
||||
uint64_t buffer[BUFFER_LEN] = {0x0};
|
||||
FILE *file = fopen(fileName.c_str(), "r");
|
||||
if (file == nullptr) {
|
||||
LOG_ERROR("open db file failed: %{public}s, errno is %{public}d", fileName.c_str(), errno);
|
||||
LOG_ERROR(
|
||||
"open db file failed: %{public}s, errno is %{public}d", SqliteUtils::Anonymous(fileName).c_str(), errno);
|
||||
return;
|
||||
}
|
||||
size_t readSize = fread(buffer, sizeof(uint64_t), BUFFER_LEN, file);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
@ -36,11 +37,14 @@ namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
|
||||
constexpr int32_t HEAD_SIZE = 3;
|
||||
constexpr int32_t END_SIZE = 3;
|
||||
constexpr int32_t MIN_SIZE = HEAD_SIZE + END_SIZE + 3;
|
||||
constexpr const char *REPLACE_CHAIN = "***";
|
||||
constexpr const char *DEFAULT_ANONYMOUS = "******";
|
||||
/* A continuous number must contain at least eight digits, because the employee ID has eight digits,
|
||||
and the mobile phone number has 11 digits. The UUID is longer */
|
||||
constexpr int32_t CONTINUOUS_DIGITS_MINI_SIZE = 6;
|
||||
constexpr int32_t FILE_PATH_MINI_SIZE = 6;
|
||||
constexpr int32_t AREA_MINI_SIZE = 4;
|
||||
constexpr int32_t AREA_OFFSET_SIZE = 5;
|
||||
constexpr int32_t PRE_OFFSET_SIZE = 1;
|
||||
|
||||
constexpr SqliteUtils::SqlType SqliteUtils::SQL_TYPE_MAP[];
|
||||
constexpr const char *SqliteUtils::ON_CONFLICT_CLAUSE[];
|
||||
@ -122,7 +126,8 @@ bool SqliteUtils::DeleteFile(const std::string &filePath)
|
||||
}
|
||||
auto ret = remove(filePath.c_str());
|
||||
if (ret != 0) {
|
||||
LOG_WARN("remove file failed errno %{public}d ret %{public}d %{public}s", errno, ret, filePath.c_str());
|
||||
LOG_WARN("remove file failed errno %{public}d ret %{public}d %{public}s", errno, ret,
|
||||
Anonymous(filePath).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -133,7 +138,7 @@ bool SqliteUtils::RenameFile(const std::string &srcFile, const std::string &dest
|
||||
auto ret = rename(srcFile.c_str(), destFile.c_str());
|
||||
if (ret != 0) {
|
||||
LOG_WARN("rename failed errno %{public}d ret %{public}d %{public}s -> %{public}s", errno, ret,
|
||||
destFile.c_str(), srcFile.c_str());
|
||||
SqliteUtils::Anonymous(destFile).c_str(), srcFile.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -143,13 +148,13 @@ bool SqliteUtils::CopyFile(const std::string &srcFile, const std::string &destFi
|
||||
{
|
||||
std::ifstream src(srcFile.c_str(), std::ios::binary);
|
||||
if (!src.is_open()) {
|
||||
LOG_WARN("open srcFile failed errno %{public}d %{public}s", errno, srcFile.c_str());
|
||||
LOG_WARN("open srcFile failed errno %{public}d %{public}s", errno, SqliteUtils::Anonymous(srcFile).c_str());
|
||||
return false;
|
||||
}
|
||||
std::ofstream dst(destFile.c_str(), std::ios::binary);
|
||||
if (!dst.is_open()) {
|
||||
src.close();
|
||||
LOG_WARN("open destFile failed errno %{public}d %{public}s", errno, destFile.c_str());
|
||||
LOG_WARN("open destFile failed errno %{public}d %{public}s", errno, SqliteUtils::Anonymous(destFile).c_str());
|
||||
return false;
|
||||
}
|
||||
dst << src.rdbuf();
|
||||
@ -158,17 +163,74 @@ bool SqliteUtils::CopyFile(const std::string &srcFile, const std::string &destFi
|
||||
return true;
|
||||
}
|
||||
|
||||
int SqliteUtils::GetContinuousDigitsNum(const std::string &fileName)
|
||||
{
|
||||
int count = 0;
|
||||
bool isNumber = false;
|
||||
for (const auto &letter : fileName) {
|
||||
if (isdigit(letter) || isalpha(letter)) {
|
||||
count++;
|
||||
isNumber = true;
|
||||
} else {
|
||||
if (isNumber) {
|
||||
break;
|
||||
}
|
||||
count = 0;
|
||||
isNumber = false;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
std::string SqliteUtils::AnonyDigits(const std::string &fileName, int digitsNum)
|
||||
{
|
||||
if (digitsNum < CONTINUOUS_DIGITS_MINI_SIZE) {
|
||||
return fileName;
|
||||
}
|
||||
constexpr int longDigits = 11;
|
||||
int endDigitsNum = 4;
|
||||
std::regex pattern("\\d{11,}");
|
||||
if (digitsNum >= CONTINUOUS_DIGITS_MINI_SIZE && digitsNum < longDigits) {
|
||||
endDigitsNum = END_SIZE;
|
||||
pattern = "\\d{6,}";
|
||||
}
|
||||
std::string name = fileName;
|
||||
std::string replacement = "***";
|
||||
std::smatch result;
|
||||
while (std::regex_search(name, result, pattern)) {
|
||||
std::string matchStr = result[0];
|
||||
std::string lastFourDigits = matchStr.substr(matchStr.size() - endDigitsNum);
|
||||
name.replace(result.position(), matchStr.size(), replacement + lastFourDigits);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string SqliteUtils::Anonymous(const std::string &srcFile)
|
||||
{
|
||||
if (srcFile.length() <= HEAD_SIZE) {
|
||||
return DEFAULT_ANONYMOUS;
|
||||
auto pre = srcFile.find("/");
|
||||
auto end = srcFile.rfind("/");
|
||||
if (pre == std::string::npos || end - pre < FILE_PATH_MINI_SIZE) {
|
||||
int digitsNum = GetContinuousDigitsNum(srcFile);
|
||||
if (digitsNum >= CONTINUOUS_DIGITS_MINI_SIZE) {
|
||||
return AnonyDigits(srcFile, digitsNum);
|
||||
}
|
||||
return srcFile;
|
||||
}
|
||||
|
||||
if (srcFile.length() < MIN_SIZE) {
|
||||
return (srcFile.substr(0, HEAD_SIZE) + REPLACE_CHAIN);
|
||||
auto path = srcFile.substr(pre, end - pre);
|
||||
auto area = path.find("/el");
|
||||
if (area == std::string::npos || area + AREA_MINI_SIZE > path.size()) {
|
||||
path = "";
|
||||
} else if (area + AREA_OFFSET_SIZE < path.size()) {
|
||||
path = path.substr(area, AREA_MINI_SIZE) + "/***";
|
||||
} else {
|
||||
path = path.substr(area, AREA_MINI_SIZE);
|
||||
}
|
||||
|
||||
return (srcFile.substr(0, HEAD_SIZE) + REPLACE_CHAIN + srcFile.substr(srcFile.length() - END_SIZE, END_SIZE));
|
||||
std::string fileName = srcFile.substr(end); // rdb file name
|
||||
int digitsNum = GetContinuousDigitsNum(fileName);
|
||||
if (digitsNum >= CONTINUOUS_DIGITS_MINI_SIZE) {
|
||||
fileName = AnonyDigits(fileName, digitsNum);
|
||||
}
|
||||
return srcFile.substr(0, pre + PRE_OFFSET_SIZE) + "***" + path + fileName;
|
||||
}
|
||||
|
||||
int SqliteUtils::GetFileSize(const std::string &fileName)
|
||||
|
@ -113,6 +113,7 @@ ohos_unittest("NativeRdbTest") {
|
||||
"unittest/rdb_utils_test.cpp",
|
||||
"unittest/rdb_value_bucket_test.cpp",
|
||||
"unittest/rdb_wal_limit_test.cpp",
|
||||
"unittest/sqlite_utils_test.cpp",
|
||||
"unittest/value_object_test.cpp",
|
||||
]
|
||||
|
||||
|
@ -52,26 +52,6 @@ HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_001, TestSize.Level1)
|
||||
EXPECT_EQ(true, SqliteUtils::IsSpecial(7));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_SqliteUtils_002
|
||||
* @tc.desc: Abnormal testCase of sqlite_utils for Anonymous, if len(srcFile) < HEAD_SIZE
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_002, TestSize.Level2)
|
||||
{
|
||||
EXPECT_EQ("******", SqliteUtils::Anonymous("ac"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_SqliteUtils_003
|
||||
* @tc.desc: Abnormal testCase of sqlite_utils for Anonymous, if len(srcFile) < MIN_SIZE
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_003, TestSize.Level2)
|
||||
{
|
||||
EXPECT_EQ("abc***", SqliteUtils::Anonymous("abc/def"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_SqliteUtils_004
|
||||
* @tc.desc: Abnormal testCase of string_utils for SurroundWithQuote, if value is ""
|
||||
|
91
test/native/rdb/unittest/sqlite_utils_test.cpp
Normal file
91
test/native/rdb/unittest/sqlite_utils_test.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "sqlite_utils.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::NativeRdb;
|
||||
|
||||
class SqliteUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp(void){};
|
||||
void TearDown(void){};
|
||||
};
|
||||
|
||||
void SqliteUtilsTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void SqliteUtilsTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("30005245854585524412855412_rdb_test.db"), "***5412_rdb_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("rdb_test_30005245854585524412855412.db"), "rdb_test_***5412.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_003, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("rdb_30005245854585524412855412_test.db"), "rdb_***5412_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_004, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("rdb_300052_test.db"), "rdb_***052_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_005, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("rdb_30005_test.db"), "rdb_30005_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_006, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous("rdb_3000523_test.db"), "rdb_***523_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_007, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous(
|
||||
"file /data/stage/el2/database/rdb/ddddddd/30005245854585524412855412_rdb_test.db"),
|
||||
"file /***/el2/***/***5412_rdb_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_008, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(
|
||||
SqliteUtils::Anonymous("file /data/stage/database/rdb/ddddddd/30005245854585524412855412_rdb_test.db"),
|
||||
"file /***/***5412_rdb_test.db");
|
||||
}
|
||||
|
||||
HWTEST_F(SqliteUtilsTest, SqliteUtils_Test_009, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(SqliteUtils::Anonymous(
|
||||
"file /data/stage/el2/database/rdb/ddddddd/3E00mnj5H54efg5G4K1ABC5412_rdb_test.db"),
|
||||
"file /***/el2/***/***5412_rdb_test.db");
|
||||
}
|
Loading…
Reference in New Issue
Block a user