!670 fixed: backup and ndk

Merge pull request !670 from lihuihui/master
This commit is contained in:
openharmony_ci 2023-06-19 08:43:55 +00:00 committed by Gitee
commit 0738f6c060
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
20 changed files with 554 additions and 254 deletions

View File

@ -87,7 +87,7 @@
"oh_predicates.h",
"relational_store.h",
"oh_cursor.h",
"relational_error_code.h",
"relational_store_error_code.h",
"oh_value_object.h",
"oh_values_bucket.h"
],

View File

@ -86,8 +86,6 @@ public:
int ConfigLocale(const std::string localeStr);
#endif
int Restore(const std::string backupPath, const std::vector<uint8_t> &newKey = std::vector<uint8_t>()) override;
int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey) override;
void GetSchema(const RdbStoreConfig &config);
std::string GetName();
std::string GetOrgPath();
@ -132,6 +130,8 @@ private:
int ExecuteSqlInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
int ExecuteGetLongInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
void DoCloudSync(const std::string &table);
int InnerBackup(const std::string databasePath,
const std::vector<uint8_t> destEncryptKey = std::vector<uint8_t>());
const RdbStoreConfig rdbStoreConfig;
SqliteConnectionPool *connectionPool;

View File

@ -79,8 +79,6 @@ public:
int ConfigLocale(const std::string localeStr);
#endif
int Restore(const std::string backupPath, const std::vector<uint8_t> &newKey = std::vector<uint8_t>()) override;
int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey) override;
std::string GetName();
std::string GetOrgPath();
std::string GetFileType();
@ -105,6 +103,8 @@ private:
int ExecuteSqlInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
int ExecuteGetLongInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
void DoCloudSync(const std::string &table);
int InnerBackup(const std::string databasePath,
const std::vector<uint8_t> destEncryptKey = std::vector<uint8_t>());
const RdbStoreConfig rdbStoreConfig;
SqliteConnectionPool *connectionPool;

View File

@ -581,7 +581,8 @@ int RdbStoreImpl::GetDataBasePath(const std::string &databasePath, std::string &
if (ISFILE(databasePath)) {
backupFilePath = ExtractFilePath(path) + databasePath;
} else {
if (!PathToRealPath(ExtractFilePath(databasePath), backupFilePath)) {
if (!PathToRealPath(ExtractFilePath(databasePath), backupFilePath) || databasePath.back() == '/' ||
databasePath.substr(databasePath.length() - 2, 2) == "\\") {
LOG_ERROR("Invalid databasePath.");
return E_INVALID_FILE_PATH;
}
@ -627,7 +628,7 @@ int RdbStoreImpl::ExecuteGetLongInner(const std::string &sql, const std::vector<
}
/**
* Restores a database from a specified encrypted or unencrypted database file.
* Backup a database from a specified encrypted or unencrypted database file.
*/
int RdbStoreImpl::Backup(const std::string databasePath, const std::vector<uint8_t> destEncryptKey)
{
@ -636,16 +637,37 @@ int RdbStoreImpl::Backup(const std::string databasePath, const std::vector<uint8
if (ret != E_OK) {
return ret;
}
std::string tempPath = backupFilePath + "temp";
while (access(tempPath.c_str(), F_OK) == E_OK) {
tempPath += "temp";
}
if (access(backupFilePath.c_str(), F_OK) == E_OK) {
SqliteUtils::RenameFile(backupFilePath, tempPath);
ret = InnerBackup(backupFilePath, destEncryptKey);
if (ret == E_OK) {
SqliteUtils::DeleteFile(tempPath);
} else {
SqliteUtils::RenameFile(tempPath, backupFilePath);
}
return ret;
}
ret = InnerBackup(backupFilePath, destEncryptKey);
return ret;
}
/**
* Backup a database from a specified encrypted or unencrypted database file.
*/
int RdbStoreImpl::InnerBackup(const std::string databasePath, const std::vector<uint8_t> destEncryptKey)
{
std::vector<ValueObject> bindArgs;
bindArgs.push_back(ValueObject(backupFilePath));
bindArgs.push_back(ValueObject(databasePath));
if (destEncryptKey.size() != 0 && !isEncrypt_) {
bindArgs.push_back(ValueObject(destEncryptKey));
ExecuteSql(GlobalExpr::CIPHER_DEFAULT_ATTACH_HMAC_ALGO);
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
} else if (isEncrypt_) {
RdbPassword rdbPwd =
RdbSecurityManager::GetInstance().GetRdbPassword(RdbSecurityManager::KeyFileType::PUB_KEY_FILE);
RdbPassword rdbPwd = RdbSecurityManager::GetInstance().GetRdbPassword(RdbSecurityManager::KeyFileType::PUB_KEY_FILE);
std::vector<uint8_t> key = std::vector<uint8_t>(rdbPwd.GetData(), rdbPwd.GetData() + rdbPwd.GetSize());
bindArgs.push_back(ValueObject(key));
ExecuteSql(GlobalExpr::CIPHER_DEFAULT_ATTACH_HMAC_ALGO);
@ -655,17 +677,16 @@ int RdbStoreImpl::Backup(const std::string databasePath, const std::vector<uint8
bindArgs.push_back(ValueObject(str));
}
ret = ExecuteSqlInner(GlobalExpr::ATTACH_BACKUP_SQL, bindArgs);
int ret = ExecuteSqlInner(GlobalExpr::ATTACH_BACKUP_SQL, bindArgs);
if (ret != E_OK) {
return ret;
}
ret = ExecuteGetLongInner(GlobalExpr::EXPORT_SQL, std::vector<ValueObject>());
if (ret != E_OK) {
return ret;
}
return ExecuteSqlInner(GlobalExpr::DETACH_BACKUP_SQL, std::vector<ValueObject>());
int res = ExecuteSqlInner(GlobalExpr::DETACH_BACKUP_SQL, std::vector<ValueObject>());
return res == E_OK ? ret : res;
}
int RdbStoreImpl::BeginExecuteSql(const std::string &sql, SqliteConnection **connection)
@ -1097,64 +1118,34 @@ int RdbStoreImpl::ConfigLocale(const std::string localeStr)
#endif
int RdbStoreImpl::Restore(const std::string backupPath, const std::vector<uint8_t> &newKey)
{
return ChangeDbFileForRestore(path, backupPath, newKey);
}
/**
* Restores a database from a specified encrypted or unencrypted database file.
*/
int RdbStoreImpl::ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey)
{
if (isOpen == false) {
LOG_ERROR("ChangeDbFileForRestore:The connection pool has been closed.");
LOG_ERROR("The connection pool has been closed.");
return E_ERROR;
}
if (connectionPool == nullptr) {
LOG_ERROR("ChangeDbFileForRestore:The connectionPool is null.");
LOG_ERROR("The connectionPool is null.");
return E_ERROR;
}
if (newPath.empty() || backupPath.empty()) {
LOG_ERROR("ChangeDbFileForRestore:Empty databasePath.");
return E_INVALID_FILE_PATH;
}
std::string backupFilePath;
std::string restoreFilePath;
if (ISFILE(backupPath)) {
backupFilePath = ExtractFilePath(path) + backupPath;
} else {
backupFilePath = backupPath;
int ret = GetDataBasePath(backupPath, backupFilePath);
if (ret != E_OK) {
return ret;
}
if (access(backupFilePath.c_str(), F_OK) != E_OK) {
LOG_ERROR("ChangeDbFileForRestore:The backupPath does not exists.");
LOG_ERROR("The backupFilePath does not exists.");
return E_INVALID_FILE_PATH;
}
if (ISFILE(newPath)) {
restoreFilePath = ExtractFilePath(path) + newPath;
} else {
if (!PathToRealPath(ExtractFilePath(newPath), restoreFilePath)) {
LOG_ERROR("ChangeDbFileForRestore:Invalid newPath.");
return E_INVALID_FILE_PATH;
}
restoreFilePath = newPath;
}
if (backupFilePath == restoreFilePath) {
LOG_ERROR("ChangeDbFileForRestore:The backupPath and newPath should not be same.");
return E_INVALID_FILE_PATH;
}
if (backupFilePath == path) {
LOG_ERROR("ChangeDbFileForRestore:The backupPath and path should not be same.");
LOG_ERROR("The backupPath and path should not be same.");
return E_INVALID_FILE_PATH;
}
int ret = connectionPool->ChangeDbFileForRestore(restoreFilePath, backupFilePath, newKey);
if (ret == E_OK) {
path = restoreFilePath;
}
return ret;
return connectionPool->ChangeDbFileForRestore(path, backupFilePath, newKey);
}
/**

View File

@ -316,9 +316,9 @@ int SqliteConnectionPool::ChangeDbFileForRestore(const std::string newPath, cons
int retVal = SqliteUtils::RenameFile(backupPath, newPath);
if (retVal != E_OK) {
LOG_ERROR("RenameFile error");
return retVal;
}
config.SetPath(newPath);
return Init();
}

View File

@ -273,8 +273,6 @@ static constexpr int E_WAL_SIZE_OVER_LIMIT = (E_BASE + 47);
* @brief The error when the connection count is used up.
*/
static constexpr int E_CON_OVER_LIMIT = (E_BASE + 48);
constexpr int E_INVALID_BUNDLE_NAME = (E_BASE + 49);
} // namespace NativeRdb
} // namespace OHOS

View File

@ -359,16 +359,6 @@ public:
*/
virtual int Restore(const std::string backupPath, const std::vector<uint8_t> &newKey = std::vector<uint8_t>()) = 0;
/**
* @brief Restores a database from a specified encrypted or unencrypted database file.
*
* @param newPath Indicates the database new path.
* @param backupPath Indicates the database backup path.
* @param newKey Indicates the database new key.
*/
virtual int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey) = 0;
/**
* @brief Set table to be distributed table.
*

View File

@ -83,8 +83,6 @@ public:
virtual bool IsReadOnly() const = 0;
virtual bool IsMemoryRdb() const = 0;
virtual int Restore(const std::string backupPath, const std::vector<uint8_t> &newKey = std::vector<uint8_t>()) = 0;
virtual int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey) = 0;
};
} // namespace OHOS::NativeRdb
#endif

View File

@ -22,8 +22,8 @@ ohos_ndk_headers("native_rdb_ndk_header") {
"./include/oh_predicates.h",
"./include/oh_value_object.h",
"./include/oh_values_bucket.h",
"./include/relational_error_code.h",
"./include/relational_store.h",
"./include/relational_store_error_code.h",
]
}

View File

@ -49,7 +49,7 @@ extern "C" {
*
* @since 10
*/
enum OH_ColumnType {
typedef enum OH_ColumnType {
/**
* Indicates the column type is NULL.
*/
@ -70,7 +70,7 @@ enum OH_ColumnType {
* Indicates the column type is BLOB.
*/
TYPE_BLOB,
};
} OH_ColumnType;
/**
* @brief Define the OH_Cursor structure type.

View File

@ -50,7 +50,7 @@ extern "C" {
*
* @since 10
*/
enum OH_OrderType {
typedef enum OH_OrderType {
/**
* Ascend order.
*/
@ -59,7 +59,7 @@ enum OH_OrderType {
* Descend order.
*/
DESC = 1,
};
} OH_OrderType;
/**
* @brief Define the OH_Predicates structure type.

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2023 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.
*/
#ifndef RELATIONAL_ERRNO_CODE_H
#define RELATIONAL_ERRNO_CODE_H
/**
* @addtogroup RDB
* @{
*
* @brief The relational database (RDB) store manages data based on relational models.
* With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases.
* To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations
* such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
*
* @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
* @since 10
*/
/**
* @file relational_error_code.h
*
* @brief Declaration error code information.
*
* @since 10
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Indicates the error code information.
*
* @since 10
*/
enum OH_Rdb_ErrCode {
/**
* Indicates the parameters is invalid.
*/
RDB_ERR_INVALID_ARGS = -2,
/**
* Indicates that the function execution exception.
*/
RDB_ERR = -1,
/**
* Indicates that the function execution normal.
*/
RDB_ERR_OK = 0
};
#ifdef __cplusplus
};
#endif
#endif // RELATIONAL_ERRNO_CODE_H

View File

@ -51,7 +51,7 @@ extern "C" {
*
* @since 10
*/
enum OH_Rdb_SecurityLevel {
typedef enum OH_Rdb_SecurityLevel {
/**
* @brief S1: means the db is low level security.
*
@ -76,7 +76,7 @@ enum OH_Rdb_SecurityLevel {
* There are some critical impact, when the data is leaked.
*/
S4
};
} OH_Rdb_SecurityLevel;
/**
* @brief Manages relational database configurations.
@ -162,7 +162,7 @@ OH_Rdb_Store *OH_Rdb_GetOrOpen(const OH_Rdb_Config *config, int *errCode);
* @brief Close the {@link OH_Rdb_Store} object and reclaim the memory occupied by the object.
*
* @param store Represents a pointer to an {@link OH_Rdb_Store} instance.
* @return Returns the status code of the execution. Successful execution returns RDB_ERR_OK,
* @return Returns the status code of the execution. Successful execution returns RDB_OK,
* while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}.
* @see OH_Rdb_Store, OH_Rdb_ErrCode.
* @since 10
@ -173,7 +173,7 @@ int OH_Rdb_CloseStore(OH_Rdb_Store *store);
* @brief Deletes the database with a specified path.
*
* @param path Indicates the database path.
* @return Returns the status code of the execution. Successful execution returns RDB_ERR_OK,
* @return Returns the status code of the execution. Successful execution returns RDB_OK,
* while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}.
* @see OH_Rdb_ErrCode.
* @since 10

View File

@ -0,0 +1,316 @@
/*
* Copyright (c) 2023 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.
*/
#ifndef RELATIONAL_STORE_ERRNO_CODE_H
#define RELATIONAL_STORE_ERRNO_CODE_H
/**
* @addtogroup RDB
* @{
*
* @brief The relational database (RDB) store manages data based on relational models.
* With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases.
* To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations
* such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
*
* @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
* @since 10
*/
/**
* @file relational_store_error_code.h
*
* @brief Declaration error code information.
*
* @since 10
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Indicates the error code information.
*
* @since 10
*/
typedef enum OH_Rdb_ErrCode {
/**
* Indicates that the function execution exception.
*/
RDB_ERR = -1,
/**
* The error code in the correct case.
*/
RDB_OK = 0,
/**
* @brief The base code of the exception error code.
*/
E_BASE = 14800000,
/**
* @brief The error when the capability not supported.
*/
RDB_E_NOT_SUPPORTED = 801,
/**
* @brief The error code for common exceptions.
*/
RDB_E_ERROR = E_BASE,
/**
* @brief The error code for common invalid args.
*/
RDB_E_INVALID_ARGS = (E_BASE + 1),
/**
* @brief The error code for upgrade the read-only store.
*/
RDB_E_CANNOT_UPDATE_READONLY = (E_BASE + 2),
/**
* @brief The error code when deleting a file fails.
*/
RDB_E_REMOVE_FILE = (E_BASE + 3),
/**
* @brief The error code for a table name is empty.
*/
RDB_E_EMPTY_TABLE_NAME = (E_BASE + 5),
/**
* @brief The error code for a values bucket is empty.
*/
RDB_E_EMPTY_VALUES_BUCKET = (E_BASE + 6),
/**
* @brief The error code when the sql is not select.
*/
RDB_E_EXECUTE_IN_STEP_QUERY = (E_BASE + 7),
/**
* @brief The error code for the column index is invalid.
*/
RDB_E_INVALID_COLUMN_INDEX = (E_BASE + 8),
/**
* @brief The error code for the column type is invalid.
*/
RDB_E_INVALID_COLUMN_TYPE = (E_BASE + 9),
/**
* @brief The error code for a file name is empty.
*/
RDB_E_EMPTY_FILE_NAME = (E_BASE + 10),
/**
* @brief The error for the current file path is invalid.
*/
RDB_E_INVALID_FILE_PATH = (E_BASE + 11),
/**
* @brief The error code when using transactions.
*/
RDB_E_TRANSACTION_IN_EXECUTE = (E_BASE + 12),
/**
* @brief The error code for the current status is invalid.
*/
RDB_E_INVALID_STATEMENT = (E_BASE + 13),
/**
* @brief The error code when execute write operation in read connection.
*/
RDB_E_EXECUTE_WRITE_IN_READ_CONNECTION = (E_BASE + 14),
/**
* @brief The error code for execute begin transaction operation in read connection.
*/
RDB_E_BEGIN_TRANSACTION_IN_READ_CONNECTION = (E_BASE + 15),
/**
* @brief The error code for there are no transactions in this connection.
*/
RDB_E_NO_TRANSACTION_IN_SESSION = (E_BASE + 16),
/**
* @brief The error code when begin more step query in one session.
*/
RDB_E_MORE_STEP_QUERY_IN_ONE_SESSION = (E_BASE + 17),
/**
* @brief The error code when the current statement doesn't contains one row result data.
*/
RDB_E_NO_ROW_IN_QUERY = (E_BASE + 18),
/**
* @brief The error code for the bind arguments count is invalid.
*/
RDB_E_INVALID_BIND_ARGS_COUNT = (E_BASE + 19),
/**
* @brief The error code for the object type is invalid.
*/
RDB_E_INVALID_OBJECT_TYPE = (E_BASE + 20),
/**
* @brief The error code for the conflict flag is invalid.
*/
RDB_E_INVALID_CONFLICT_FLAG = (E_BASE + 21),
/**
* @brief The error code for having clause not in group.
*/
RDB_E_HAVING_CLAUSE_NOT_IN_GROUP_BY = (E_BASE + 22),
/**
* @brief The error code for not supported by step result set.
*/
RDB_E_NOT_SUPPORTED_BY_STEP_RESULT_SET = (E_BASE + 23),
/**
* @brief The error code for step result current tid not equal to object's tid.
*/
RDB_E_STEP_RESULT_SET_CROSS_THREADS = (E_BASE + 24),
/**
* @brief The error code when the result query was not executed.
*/
RDB_E_STEP_RESULT_QUERY_NOT_EXECUTED = (E_BASE + 25),
/**
* @brief The error code for the result set cursor is after the last row.
*/
RDB_E_STEP_RESULT_IS_AFTER_LAST = (E_BASE + 26),
/**
* @brief The error code for the result set query exceeded.
*/
RDB_E_STEP_RESULT_QUERY_EXCEEDED = (E_BASE + 27),
/**
* @brief The error code for the statement not prepared.
*/
RDB_E_STATEMENT_NOT_PREPARED = (E_BASE + 28),
/**
* @brief The error code for the result set is incorrect.
*/
RDB_E_EXECUTE_RESULT_INCORRECT = (E_BASE + 29),
/**
* @brief The error code when the result set is closed.
*/
RDB_E_STEP_RESULT_CLOSED = (E_BASE + 30),
/**
* @brief The error code when input relative path.
*/
RDB_E_RELATIVE_PATH = (E_BASE + 31),
/**
* @brief The error code for the new encrypt key is empty.
*/
RDB_E_EMPTY_NEW_ENCRYPT_KEY = (E_BASE + 32),
/**
* @brief The error code for change unencrypted to encrypted.
*/
RDB_E_CHANGE_UNENCRYPTED_TO_ENCRYPTED = (E_BASE + 33),
/**
* @brief The error code for change encrypt in busy.
*/
RDB_E_CHANGE_ENCRYPT_KEY_IN_BUSY = (E_BASE + 34),
/**
* @brief The error code when the statement not initialized.
*/
RDB_E_STEP_STATEMENT_NOT_INIT = (E_BASE + 35),
/**
* @brief The error code for the attach is not supported in WAL journal mode.
*/
RDB_E_NOT_SUPPORTED_ATTACH_IN_WAL_MODE = (E_BASE + 36),
/**
* @brief The error code when create folder failed.
*/
RDB_E_CREATE_FOLDER_FAIL = (E_BASE + 37),
/**
* @brief The error for SQL builder normalize failed.
*/
RDB_E_SQLITE_SQL_BUILDER_NORMALIZE_FAIL = (E_BASE + 38),
/**
* @brief The error for store session not give connection temporarily.
*/
RDB_E_STORE_SESSION_NOT_GIVE_CONNECTION_TEMPORARILY = (E_BASE + 39),
/**
* @brief The error for store session not current transaction.
*/
RDB_E_STORE_SESSION_NO_CURRENT_TRANSACTION = (E_BASE + 40),
/**
* @brief The error for not supported the current operation.
*/
RDB_E_NOT_SUPPORT = (E_BASE + 41),
/**
* @brief The error for the current parcel is invalid.
*/
RDB_E_INVALID_PARCEL = (E_BASE + 42),
/**
* @brief The error code when using sqlite3_step function failed.
*/
RDB_E_QUERY_IN_EXECUTE = (E_BASE + 43),
/**
* @brief The error for set persist WAL.
*/
RDB_E_SET_PERSIST_WAL = (E_BASE + 44),
/**
* @brief The error when the database does not exist.
*/
RDB_E_DB_NOT_EXIST = (E_BASE + 45),
/**
* @brief The error when the read connection count is overload.
*/
RDB_E_ARGS_READ_CON_OVERLOAD = (E_BASE + 46),
/**
* @brief The error when the wal file size over default limit.
*/
RDB_E_WAL_SIZE_OVER_LIMIT = (E_BASE + 47),
/**
* @brief The error when the connection count is used up.
*/
RDB_E_CON_OVER_LIMIT = (E_BASE + 48)
} OH_Rdb_ErrCode;
#ifdef __cplusplus
};
#endif
#endif // RELATIONAL_STORE_ERRNO_CODE_H

View File

@ -20,7 +20,7 @@
#include "logger.h"
#include "oh_cursor.h"
#include "relational_cursor_impl.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
#include "rdb_errno.h"
#include "securec.h"
@ -31,7 +31,7 @@ int Rdb_GetColumnCount(OH_Cursor *cursor, int *count)
if (cursor == nullptr || count == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, count is NULL ? %{public}d", (cursor == nullptr),
(count == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
OHOS::RdbNdk::CursorImpl *tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetColumnCount(*count);
@ -42,7 +42,7 @@ int Rdb_GetColumnType(OH_Cursor *cursor, int32_t columnIndex, OH_ColumnType *col
if (cursor == nullptr || columnType == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, columnType is NULL ? %{public}d",
(cursor == nullptr), (columnType == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
OHOS::NativeRdb::ColumnType type;
@ -56,7 +56,7 @@ int Rdb_GetColumnIndex(OH_Cursor *cursor, const char *name, int *columnIndex)
if (cursor == nullptr || name == nullptr || columnIndex == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, name is NULL ? %{public}d,"
"columnIndex is NULL ? %{public}d", (cursor == nullptr), (name == nullptr), columnIndex == nullptr);
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetColumnIndex(name, *columnIndex);
@ -67,7 +67,7 @@ int Rdb_GetColumnName(OH_Cursor *cursor, int32_t columnIndex, char *name, int le
if (cursor == nullptr || name == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, name is NULL ? %{public}d", (cursor == nullptr),
(name == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
std::string str;
@ -88,7 +88,7 @@ int Rdb_GetRowCount(OH_Cursor *cursor, int *count)
if (cursor == nullptr || count == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, count is NULL ? %{public}d", (cursor == nullptr),
(count == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetRowCount(*count);
@ -98,7 +98,7 @@ int Rdb_GoToNextRow(OH_Cursor *cursor)
{
if (cursor == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d", (cursor == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GoToNextRow();
@ -109,7 +109,7 @@ int Rdb_GetSize(OH_Cursor *cursor, int32_t columnIndex, size_t *size)
if (cursor == nullptr || size == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, size is NULL ? %{public}d", (cursor == nullptr),
(size == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetSize(columnIndex, *size);
@ -120,7 +120,7 @@ int Rdb_GetText(OH_Cursor *cursor, int32_t columnIndex, char *value, int length)
if (cursor == nullptr || value == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, value is NULL ? %{public}d", (cursor == nullptr),
(value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
std::string str;
@ -141,7 +141,7 @@ int Rdb_GetInt64(OH_Cursor *cursor, int32_t columnIndex, int64_t *value)
if (cursor == nullptr || value == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, value is NULL ? %{public}d", (cursor == nullptr),
(value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetLong(columnIndex, *value);
@ -152,7 +152,7 @@ int Rdb_GetReal(OH_Cursor *cursor, int32_t columnIndex, double *value)
if (cursor == nullptr || value == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, value is NULL ? %{public}d", (cursor == nullptr),
(value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
return tempCursor->GetResultSet()->GetDouble(columnIndex, *value);
@ -163,7 +163,7 @@ int Rdb_GetBlob(OH_Cursor *cursor, int32_t columnIndex, unsigned char *value, in
if (cursor == nullptr || value == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, value is NULL ? %{public}d", (cursor == nullptr),
(value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
std::vector<uint8_t> vec;
@ -184,7 +184,7 @@ int Rdb_IsNull(OH_Cursor *cursor, int32_t columnIndex, bool *isNull)
if (cursor == nullptr || isNull == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d, value is NULL ? %{public}d", (cursor == nullptr),
(isNull == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
bool isNULLTemp = false;
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
@ -197,7 +197,7 @@ int Rdb_Close(OH_Cursor *cursor)
{
if (cursor == nullptr || cursor->id != OHOS::RdbNdk::RDB_CURSOR_CID) {
LOG_ERROR("Parameters set error:cursor is NULL ? %{public}d", (cursor == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempCursor = static_cast<OHOS::RdbNdk::CursorImpl *>(cursor);
int errCode = tempCursor->GetResultSet()->Close();

View File

@ -15,7 +15,7 @@
#include "logger.h"
#include "oh_predicates.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
#include "relational_predicates_impl.h"
#include "relational_value_object_impl.h"
#include "sqlite_global_config.h"
@ -355,11 +355,11 @@ int Rdb_DestroyPredicates(OH_Predicates *predicates)
{
if (predicates == nullptr || predicates->id != OHOS::RdbNdk::RDB_PREDICATES_CID) {
LOG_ERROR("Parameters set error:predicates is NULL ? %{public}d", (predicates == nullptr));
return RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
delete predicates;
predicates = nullptr;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
OHOS::RdbNdk::PredicateImpl::PredicateImpl(const char *table) : predicates_(table)

View File

@ -20,7 +20,7 @@
#include "rdb_helper.h"
#include "rdb_predicates.h"
#include "relational_cursor_impl.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
#include "relational_predicates_impl.h"
#include "relational_store_impl.h"
#include "relational_value_object_impl.h"
@ -97,24 +97,20 @@ int OH_Rdb_CloseStore(OH_Rdb_Store *store)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:config is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
delete store;
store = nullptr;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int OH_Rdb_DeleteStore(const char *path)
{
if (path == nullptr) {
LOG_ERROR("Parameters set error:path is NULL ? %{public}d", (path == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
int err = OHOS::NativeRdb::RdbHelper::DeleteRdbStore(path);
if (err != OHOS::NativeRdb::E_OK) {
return OH_Rdb_ErrCode::RDB_ERR;
}
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OHOS::NativeRdb::RdbHelper::DeleteRdbStore(path);
}
int OH_Rdb_Insert(OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBucket)
@ -123,7 +119,7 @@ int OH_Rdb_Insert(OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBuck
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, table is NULL ? %{public}d,"
"valuesBucket is NULL ? %{public}d",
(store == nullptr), (table == nullptr), (valuesBucket == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
int64_t rowId = -1;
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
@ -138,7 +134,7 @@ int OH_Rdb_Update(OH_Rdb_Store *store, OH_VBucket *valueBucket, OH_Predicates *p
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, valueBucket is NULL ? %{public}d,"
"predicates is NULL ? %{public}d",
(store == nullptr), (valueBucket == nullptr), (predicates == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
int updatedRows = -1;
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
@ -154,7 +150,7 @@ int OH_Rdb_Delete(OH_Rdb_Store *store, OH_Predicates *predicates)
if (store == nullptr || predicates == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, predicates is NULL ? %{public}d",
(store == nullptr), (predicates == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
int deletedRows = -1;
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
@ -186,8 +182,7 @@ OH_Cursor *OH_Rdb_Query(OH_Rdb_Store *store, OH_Predicates *predicates, const ch
if (resultSet == nullptr) {
return nullptr;
}
std::shared_ptr<OHOS::NativeRdb::ResultSet> retParam = std::move(resultSet);
return new OHOS::RdbNdk::CursorImpl(retParam);
return new OHOS::RdbNdk::CursorImpl(std::move(resultSet));
}
OH_Cursor *OH_Rdb_ExecuteQuery(OH_Rdb_Store *store, const char *sql)
@ -203,8 +198,7 @@ OH_Cursor *OH_Rdb_ExecuteQuery(OH_Rdb_Store *store, const char *sql)
if (resultSet == nullptr) {
return nullptr;
}
std::shared_ptr<OHOS::NativeRdb::ResultSet> retParam = std::move(resultSet);
return new OHOS::RdbNdk::CursorImpl(retParam);
return new OHOS::RdbNdk::CursorImpl(std::move(resultSet));
}
int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql)
@ -212,7 +206,7 @@ int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql)
if (store == nullptr || sql == nullptr ||store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, sql is NULL ? %{public}d", (store == nullptr),
(sql == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->ExecuteSql(sql, std::vector<OHOS::NativeRdb::ValueObject>{});
@ -222,7 +216,7 @@ int OH_Rdb_BeginTransaction(OH_Rdb_Store *store)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->BeginTransaction();
@ -232,7 +226,7 @@ int OH_Rdb_RollBack(OH_Rdb_Store *store)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->RollBack();
@ -242,7 +236,7 @@ int OH_Rdb_Commit(OH_Rdb_Store *store)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->Commit();
@ -253,7 +247,7 @@ int OH_Rdb_Backup(OH_Rdb_Store *store, const char *databasePath)
if (store == nullptr || databasePath == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, databasePath is NULL ? %{public}d",
(store == nullptr), (databasePath == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
@ -265,7 +259,7 @@ int OH_Rdb_Restore(OH_Rdb_Store *store, const char *databasePath)
if (store == nullptr || databasePath == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d, databasePath is NULL ? %{public}d",
(store == nullptr), (databasePath == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
@ -276,7 +270,7 @@ int OH_Rdb_GetVersion(OH_Rdb_Store *store, int *version)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->GetVersion(*version);
@ -286,7 +280,7 @@ int OH_Rdb_SetVersion(OH_Rdb_Store *store, int version)
{
if (store == nullptr || store->id != OHOS::RdbNdk::RDB_STORE_CID) {
LOG_ERROR("Parameters set error:store is NULL ? %{public}d", (store == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto tempStore = static_cast<OHOS::RdbNdk::StoreImpl *>(store);
return tempStore->GetStore()->SetVersion(version);

View File

@ -15,7 +15,7 @@
#include "logger.h"
#include "oh_value_object.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
#include "relational_value_object_impl.h"
using namespace OHOS::RdbNdk;
@ -25,7 +25,7 @@ int Rdb_ValueObject_PutInt64(OH_VObject *valueObject, int64_t *value, uint32_t c
if (valueObject == nullptr || value == nullptr || valueObject->id != OHOS::RdbNdk::RDB_VOBJECT_CID) {
LOG_ERROR("Parameters set error:valueObject is NULL ? %{public}d, value is NULL ? %{public}d",
(valueObject == nullptr), (value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto vObject = static_cast<OHOS::RdbNdk::ValueObjectImpl *>(valueObject);
@ -37,7 +37,7 @@ int Rdb_ValueObject_PutInt64(OH_VObject *valueObject, int64_t *value, uint32_t c
vObject->getValue().push_back(std::to_string(value[i]));
}
};
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_ValueObject_PutDouble(OH_VObject *valueObject, double *value, uint32_t count)
@ -45,7 +45,7 @@ int Rdb_ValueObject_PutDouble(OH_VObject *valueObject, double *value, uint32_t c
if (valueObject == nullptr || value == nullptr || valueObject->id != OHOS::RdbNdk::RDB_VOBJECT_CID) {
LOG_ERROR("Parameters set error:valueObject is NULL ? %{public}d, value is NULL ? %{public}d",
(valueObject == nullptr), (value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto vObject = static_cast<OHOS::RdbNdk::ValueObjectImpl *>(valueObject);
@ -57,7 +57,7 @@ int Rdb_ValueObject_PutDouble(OH_VObject *valueObject, double *value, uint32_t c
vObject->getValue().push_back(std::to_string(value[i]));
}
}
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_ValueObject_PutText(OH_VObject *valueObject, const char *value)
@ -65,14 +65,14 @@ int Rdb_ValueObject_PutText(OH_VObject *valueObject, const char *value)
if (valueObject == nullptr || value == nullptr || valueObject->id != OHOS::RdbNdk::RDB_VOBJECT_CID) {
LOG_ERROR("Parameters set error:valueObject is NULL ? %{public}d, value is NULL ? %{public}d",
(valueObject == nullptr), (value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
std::string textValue(value);
auto vObject = static_cast<OHOS::RdbNdk::ValueObjectImpl *>(valueObject);
vObject->getValue().clear();
vObject->getValue().push_back(textValue);
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_ValueObject_PutTexts(OH_VObject *valueObject, const char **value, uint32_t count)
@ -80,7 +80,7 @@ int Rdb_ValueObject_PutTexts(OH_VObject *valueObject, const char **value, uint32
if (valueObject == nullptr || value == nullptr || valueObject->id != OHOS::RdbNdk::RDB_VOBJECT_CID) {
LOG_ERROR("Parameters set error:valueObject is NULL ? %{public}d, value is NULL ? %{public}d",
(valueObject == nullptr), (value == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
auto vObject = static_cast<OHOS::RdbNdk::ValueObjectImpl *>(valueObject);
@ -89,17 +89,17 @@ int Rdb_ValueObject_PutTexts(OH_VObject *valueObject, const char **value, uint32
std::string textValue(value[i]);
vObject->getValue().push_back(textValue);
}
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_DestroyValueObject(OH_VObject *valueObject)
{
if (valueObject == nullptr || valueObject->id != OHOS::RdbNdk::RDB_VOBJECT_CID) {
LOG_ERROR("Parameters set error:valueObject is NULL ? %{public}d", (valueObject == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
delete static_cast<OHOS::RdbNdk::ValueObjectImpl *>(valueObject);
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
OHOS::RdbNdk::ValueObjectImpl::ValueObjectImpl()

View File

@ -17,7 +17,7 @@
#include "logger.h"
#include "oh_values_bucket.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
#include "relational_values_bucket_impl.h"
#include "value_object.h"
#include "securec.h"
@ -27,12 +27,12 @@ using namespace OHOS::RdbNdk;
int Rdb_VBucket_PutText(OH_VBucket *bucket, const char *field, const char *value)
{
if (bucket == nullptr || field == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Put(
field, OHOS::NativeRdb::ValueObject(value));
bucket->capability += 1;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_VBucket_PutInt64(OH_VBucket *bucket, const char *field, int64_t value)
@ -40,12 +40,12 @@ int Rdb_VBucket_PutInt64(OH_VBucket *bucket, const char *field, int64_t value)
if (bucket == nullptr || field == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d, field is NULL ? %{public}d", (bucket == nullptr),
(field == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Put(
field, OHOS::NativeRdb::ValueObject(value));
bucket->capability += 1;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_VBucket_PutReal(OH_VBucket *bucket, const char *field, double value)
@ -53,12 +53,12 @@ int Rdb_VBucket_PutReal(OH_VBucket *bucket, const char *field, double value)
if (bucket == nullptr || field == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d, field is NULL ? %{public}d", (bucket == nullptr),
(field == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Put(
field, OHOS::NativeRdb::ValueObject(value));
bucket->capability += 1;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_VBucket_PutBlob(OH_VBucket *bucket, const char *field, const uint8_t *value, uint32_t size)
@ -66,7 +66,7 @@ int Rdb_VBucket_PutBlob(OH_VBucket *bucket, const char *field, const uint8_t *va
if (bucket == nullptr || field == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d, field is NULL ? %{public}d", (bucket == nullptr),
(field == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
std::vector<uint8_t> blobValue;
if (value != nullptr) {
@ -79,7 +79,7 @@ int Rdb_VBucket_PutBlob(OH_VBucket *bucket, const char *field, const uint8_t *va
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Put(
field, OHOS::NativeRdb::ValueObject(blobValue));
bucket->capability += 1;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_VBucket_PutNull(OH_VBucket *bucket, const char *field)
@ -87,33 +87,33 @@ int Rdb_VBucket_PutNull(OH_VBucket *bucket, const char *field)
if (bucket == nullptr || field == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d, field is NULL ? %{public}d", (bucket == nullptr),
(field == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Put(field, OHOS::NativeRdb::ValueObject());
bucket->capability += 1;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_VBucket_Clear(OH_VBucket *bucket)
{
if (bucket == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d", (bucket == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
static_cast<OHOS::RdbNdk::ValuesBucketImpl *>(bucket)->getValuesBucket().Clear();
bucket->capability = 0;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
int Rdb_DestroyValuesBucket(OH_VBucket *bucket)
{
if (bucket == nullptr || bucket->id != OHOS::RdbNdk::RDB_VBUCKET_CID) {
LOG_ERROR("Parameters set error:bucket is NULL ? %{public}d", (bucket == nullptr));
return OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS;
return OH_Rdb_ErrCode::RDB_E_INVALID_ARGS;
}
delete bucket;
bucket = nullptr;
return OH_Rdb_ErrCode::RDB_ERR_OK;
return OH_Rdb_ErrCode::RDB_OK;
}
OHOS::RdbNdk::ValuesBucketImpl::ValuesBucketImpl()

View File

@ -18,7 +18,7 @@
#include <string>
#include "common.h"
#include "relational_store.h"
#include "relational_error_code.h"
#include "relational_store_error_code.h"
using namespace testing::ext;
using namespace OHOS::NativeRdb;
@ -316,7 +316,6 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_005, TestSize.Level1)
{
int errCode = 0;
OH_VBucket* valueBucket = OH_Rdb_CreateValuesBucket();
valueBucket->putInt64(valueBucket, "id", 1);
valueBucket->putText(valueBucket, "data1", "zhangSan");
valueBucket->putInt64(valueBucket, "data2", 12800);
valueBucket->putReal(valueBucket, "data3", 100.1);
@ -335,44 +334,55 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_005, TestSize.Level1)
EXPECT_EQ(rowCount, 1);
cursor->close(cursor);
std::string backupPath = RDB_TEST_PATH + "backup.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
std::string backupPath1 = RDB_TEST_PATH + "a.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath1.c_str());
EXPECT_EQ(errCode, 0);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath.c_str());
errCode = OH_Rdb_Insert(storeTestRdbStore_, "test", valueBucket);
EXPECT_EQ(errCode, 2);
std::string backupPath2 = RDB_TEST_PATH + "b.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath2.c_str());
EXPECT_EQ(errCode, 0);
errCode = OH_Rdb_Insert(storeTestRdbStore_, "test", valueBucket);
EXPECT_EQ(errCode, 3);
std::string backupPath3 = RDB_TEST_PATH + "c.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath3.c_str());
EXPECT_EQ(errCode, 0);
// Continuous backup
errCode = OH_Rdb_Insert(storeTestRdbStore_, "test", valueBucket);
EXPECT_EQ(errCode, 4);
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath3.c_str());
EXPECT_EQ(errCode, 0);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath1.c_str());
EXPECT_EQ(errCode, 0);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 1);
cursor->close(cursor);
errCode = cursor->goToNextRow(cursor);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath2.c_str());
EXPECT_EQ(errCode, 0);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 2);
cursor->close(cursor);
size_t size = 0;
cursor->getSize(cursor, 1, &size);
char data1Value[size + 1];
cursor->getText(cursor, 1, data1Value, size + 1);
EXPECT_EQ(strcmp(data1Value, "zhangSan"), 0);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath3.c_str());
EXPECT_EQ(errCode, 0);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 4);
cursor->close(cursor);
int64_t data2Value;
cursor->getInt64(cursor, 2, &data2Value);
EXPECT_EQ(data2Value, 12800);
double data3Value;
cursor->getReal(cursor, 3, &data3Value);
EXPECT_EQ(data3Value, 100.1);
cursor->getSize(cursor, 4, &size);
unsigned char data4Value[size];
cursor->getBlob(cursor, 4, data4Value, size);
EXPECT_EQ(data4Value[0], 1);
EXPECT_EQ(data4Value[1], 2);
cursor->getSize(cursor, 5, &size);
char data5Value[size + 1];
cursor->getText(cursor, 5, data5Value, size + 1);
EXPECT_EQ(strcmp(data5Value, "ABCDEFG"), 0);
// Continuous restore
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath3.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 4);
valueBucket->destroyValuesBucket(valueBucket);
cursor->close(cursor);
@ -380,10 +390,82 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_005, TestSize.Level1)
/**
* @tc.name: RDB_NDK_store_test_006
* @tc.desc: Normal testCase of NDK store for GetVersionSetVersion.
* @tc.desc: Normal testCase of NDK store for BackupRestore.
* @tc.type: FUNC
*/
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_006, TestSize.Level1)
{
int errCode = 0;
OH_VBucket* valueBucket = OH_Rdb_CreateValuesBucket();
valueBucket->putText(valueBucket, "data1", "zhangSan");
valueBucket->putInt64(valueBucket, "data2", 12800);
valueBucket->putReal(valueBucket, "data3", 100.1);
uint8_t arr[] = {1, 2, 3, 4, 5};
int len = sizeof(arr) / sizeof(arr[0]);
valueBucket->putBlob(valueBucket, "data4", arr, len);
valueBucket->putText(valueBucket, "data5", "ABCDEFG");
errCode = OH_Rdb_Insert(storeTestRdbStore_, "test", valueBucket);
EXPECT_EQ(errCode, 1);
char querySql[] = "SELECT * FROM test";
OH_Cursor *cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
int rowCount = 0;
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 1);
cursor->close(cursor);
std::string backupPath = "backup.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, 0);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, 0);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 1);
cursor->close(cursor);
std::string restorePath = "error.db";
errCode = OH_Rdb_Restore(storeTestRdbStore_, restorePath.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
errCode = OH_Rdb_Insert(storeTestRdbStore_, "test", valueBucket);
EXPECT_EQ(errCode, 2);
backupPath = " ";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, 0);
errCode = OH_Rdb_Restore(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, 0);
cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
cursor->getRowCount(cursor, &rowCount);
EXPECT_EQ(rowCount, 2);
cursor->close(cursor);
backupPath = "";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
backupPath = RDB_TEST_PATH + "/backup/backup.db";
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
backupPath = RDB_TEST_PATH;
errCode = OH_Rdb_Backup(storeTestRdbStore_, backupPath.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
restorePath = RDB_TEST_PATH;
errCode = OH_Rdb_Restore(storeTestRdbStore_, restorePath.c_str());
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_FILE_PATH);
valueBucket->destroyValuesBucket(valueBucket);
}
/**
* @tc.name: RDB_NDK_store_test_007
* @tc.desc: Normal testCase of NDK store for GetVersionSetVersion.
* @tc.type: FUNC
*/
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_007, TestSize.Level1)
{
int errCode = 0;
int version = 0;
@ -399,11 +481,11 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_006, TestSize.Level1)
}
/**
* @tc.name: RDB_NDK_store_test_007
* @tc.name: RDB_NDK_store_test_008
* @tc.desc: Normal testCase of NDK store for Insert with wrong table name or table is NULL.
* @tc.type: FUNC
*/
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_007, TestSize.Level1)
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_008, TestSize.Level1)
{
int errCode = 0;
OH_VBucket* valueBucket = OH_Rdb_CreateValuesBucket();
@ -425,7 +507,7 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_007, TestSize.Level1)
valueBucket->putReal(valueBucket, "data3", 200.1);
valueBucket->putText(valueBucket, "data5", "ABCDEFGH");
errCode = OH_Rdb_Insert(storeTestRdbStore_, "wrong", valueBucket);
EXPECT_EQ(errCode, -1);
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_ERR);
valueBucket->clear(valueBucket);
valueBucket->putInt64(valueBucket, "id", 3);
@ -435,7 +517,7 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_007, TestSize.Level1)
valueBucket->putText(valueBucket, "data5", "ABCDEFGHI");
char *table = NULL;
errCode = OH_Rdb_Insert(storeTestRdbStore_, table, valueBucket);
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS);
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
char querySql[] = "SELECT * FROM test";
OH_Cursor *cursor = OH_Rdb_ExecuteQuery(storeTestRdbStore_, querySql);
@ -449,11 +531,11 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_007, TestSize.Level1)
}
/**
* @tc.name: RDB_NDK_store_test_008
* @tc.name: RDB_NDK_store_test_009
* @tc.desc: Normal testCase of NDK store for Update with wrong table or table is NULL.
* @tc.type: FUNC
*/
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_008, TestSize.Level1)
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_009, TestSize.Level1)
{
int errCode = 0;
OH_VBucket* valueBucket = OH_Rdb_CreateValuesBucket();
@ -486,7 +568,7 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_008, TestSize.Level1)
OH_Predicates *predicates1 = OH_Rdb_CreatePredicates(table);
EXPECT_EQ(predicates1, NULL);
errCode = OH_Rdb_Update(storeTestRdbStore_, valueBucket, predicates1);
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_ERR_INVALID_ARGS);
EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
OH_Predicates *predicates2 = OH_Rdb_CreatePredicates("test");
OH_Cursor *cursor = OH_Rdb_Query(storeTestRdbStore_, predicates2, NULL, 0);
@ -532,11 +614,11 @@ HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_008, TestSize.Level1)
}
/**
* @tc.name: RDB_NDK_store_test_009
* @tc.name: RDB_NDK_store_test_010
* @tc.desc: Normal testCase of NDK store for querysql is NULL.
* @tc.type: FUNC
*/
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_009, TestSize.Level1)
HWTEST_F(RdbNdkStoreTest, RDB_NDK_store_test_010, TestSize.Level1)
{
int errCode = 0;
OH_VBucket *valueBucket = OH_Rdb_CreateValuesBucket();