From 19bf68ad049aef727f84c49f5f99d544ee18c88b Mon Sep 17 00:00:00 2001 From: lianhuix Date: Tue, 9 May 2023 20:17:16 +0800 Subject: [PATCH 1/2] Fix code reviews Signed-off-by: lianhuix --- .../include/grd_base/grd_db_api.h | 6 +- .../include/grd_base/grd_resultset_api.h | 8 +- .../include/grd_base/grd_type_export.h | 2 +- .../include/grd_document/grd_document_api.h | 14 +- .../src/common/include/doc_limit.h | 2 +- .../src/common/include/log_print.h | 14 +- .../src/common/src/collection_option.cpp | 1 - .../src/common/src/db_config.cpp | 191 ++++++------------ .../src/common/src/json_common.cpp | 11 +- .../src/common/src/log_print.cpp | 4 +- .../src/common/src/os_api.cpp | 3 +- .../src/executor/base/grd_db_api.cpp | 2 +- .../src/executor/document/document_check.cpp | 18 +- .../src/executor/document/document_check.h | 2 +- .../src/interface/include/document_store.h | 25 ++- .../src/interface/src/doc_errno.cpp | 1 + .../src/interface/src/document_store.cpp | 32 +-- .../src/oh_adapter/src/json_object.cpp | 13 +- .../test/unittest/api/documentdb_api_test.cpp | 2 - .../api/documentdb_collection_test.cpp | 5 +- .../unittest/api/documentdb_insert_test.cpp | 20 +- .../unittest/common/documentdb_test_utils.cpp | 2 +- 22 files changed, 165 insertions(+), 213 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h index 323c487d..e08fb605 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h @@ -22,11 +22,11 @@ extern "C" { #endif // __cplusplus -DOC_API int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GRD_DB **db); +GRD_API int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GRD_DB **db); -DOC_API int GRD_DBClose(GRD_DB *db, unsigned int flags); +GRD_API int GRD_DBClose(GRD_DB *db, unsigned int flags); -DOC_API int GRD_Flush(GRD_DB *db, unsigned int flags); +GRD_API int GRD_Flush(GRD_DB *db, unsigned int flags); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h index 1d534708..008a1cbc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h @@ -24,13 +24,13 @@ extern "C" { typedef struct GRD_ResultSet GRD_ResultSet; -DOC_API int GRD_Next(GRD_ResultSet *resultSet); +GRD_API int GRD_Next(GRD_ResultSet *resultSet); -DOC_API int GRD_GetValue(GRD_ResultSet *resultSet, char **value); +GRD_API int GRD_GetValue(GRD_ResultSet *resultSet, char **value); -DOC_API int GRD_FreeValue(char *value); +GRD_API int GRD_FreeValue(char *value); -DOC_API int GRD_FreeResultSet(GRD_ResultSet *resultSet); +GRD_API int GRD_FreeResultSet(GRD_ResultSet *resultSet); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h index 665cfbe2..d116ea22 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h @@ -21,7 +21,7 @@ extern "C" { #endif // __cplusplus #ifndef _WIN32 -#define DOC_API __attribute__((visibility("default"))) +#define GRD_API __attribute__((visibility("default"))) #endif typedef struct GRD_DB GRD_DB; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h index 9d217a1e..e6e5bb72 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h @@ -23,22 +23,22 @@ extern "C" { #endif -DOC_API int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, unsigned int flags); +GRD_API int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, unsigned int flags); -DOC_API int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flags); +GRD_API int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flags); -DOC_API int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, unsigned int flags); +GRD_API int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, unsigned int flags); -DOC_API int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, +GRD_API int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, GRD_ResultSet **resultSet); -DOC_API int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, +GRD_API int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, unsigned int flags); -DOC_API int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, +GRD_API int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, unsigned int flags); -DOC_API int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, unsigned int flags); +GRD_API int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, unsigned int flags); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/doc_limit.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/doc_limit.h index 38ceb943..557b92da 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/doc_limit.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/doc_limit.h @@ -17,6 +17,6 @@ #define DOC_LIMIT_H namespace DocumentDB { -constexpr const int MAX_DB_CONFIG_LEN = 512 * 1024; // 512 * 1024: 512k length +constexpr int MAX_DB_CONFIG_LEN = 512 * 1024; // 512 * 1024: 512k length } // namespace DocumentDB #endif // DOC_LIMIT_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/log_print.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/log_print.h index 55c800a9..25918731 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/log_print.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/log_print.h @@ -19,7 +19,7 @@ #include namespace DocumentDB { -constexpr const char *LOG_TAG_DOC = "DocumentDB"; +constexpr const char *LOG_TAG_DOC = "GAUSSDB_RD"; class Logger { public: @@ -31,14 +31,14 @@ public: LEVEL_FATAL }; - static void Log(Level level, const std::string &tag, const char *func, int line, const char *format, ...); + static void Log(Level level, const std::string &tag, const char *format, ...); }; } // namespace DocumentDB #define NO_LOG(...) // No log in normal and release. Used for convenience when deep debugging -#define GLOGD(...) Logger::Log(Logger::Level::LEVEL_DEBUG, LOG_TAG_DOC, __FUNCTION__, __LINE__, __VA_ARGS__) -#define GLOGI(...) Logger::Log(Logger::Level::LEVEL_INFO, LOG_TAG_DOC, __FUNCTION__, __LINE__, __VA_ARGS__) -#define GLOGW(...) Logger::Log(Logger::Level::LEVEL_WARN, LOG_TAG_DOC, __FUNCTION__, __LINE__, __VA_ARGS__) -#define GLOGE(...) Logger::Log(Logger::Level::LEVEL_ERROR, LOG_TAG_DOC, __FUNCTION__, __LINE__, __VA_ARGS__) -#define GLOGF(...) Logger::Log(Logger::Level::LEVEL_FATAL, LOG_TAG_DOC, __FUNCTION__, __LINE__, __VA_ARGS__) +#define GLOGD(...) Logger::Log(Logger::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGI(...) Logger::Log(Logger::Level::LEVEL_INFO, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGW(...) Logger::Log(Logger::Level::LEVEL_WARN, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGE(...) Logger::Log(Logger::Level::LEVEL_ERROR, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGF(...) Logger::Log(Logger::Level::LEVEL_FATAL, LOG_TAG_DOC, __VA_ARGS__) #endif // LOG_PRINT_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp index eba7ec4c..7f34d765 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp @@ -17,7 +17,6 @@ #include #include -#include #include "doc_errno.h" #include "json_object.h" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp index e660ae3c..d5947625 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "doc_errno.h" @@ -44,150 +45,78 @@ const int DB_CONFIG_SIZE = 6; // db config size const char *DB_CONFIG[DB_CONFIG_SIZE] = { DB_CONFIG_PAGESIZE, DB_CONFIG_REDO_FLUSH_BY_TRX, DB_CONFIG_REDO_PUB_BUFF_SIZE, DB_CONFIG_MAX_CONN_NUM, DB_CONFIG_BUFFER_POOL_SIZE, DB_CONFIG_CRC_CHECK_ENABLE }; -bool CheckPageSizeConfig(const JsonObject &config, int32_t &pageSize, int &errCode) +template +bool CheckAndGetDBConfig(const JsonObject &config, const std::string &name, const std::function &checkValid, + T &val) { - static const JsonFieldPath pageSizeField = { DB_CONFIG_PAGESIZE }; - if (!config.IsFieldExists(pageSizeField)) { + const JsonFieldPath configField = { name }; + if (!config.IsFieldExists(configField)) { return true; } - ValueObject configValue = config.GetObjectByPath(pageSizeField, errCode); + int errCode = E_OK; + ValueObject configValue = config.GetObjectByPath(configField, errCode); if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of pageSize is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; + GLOGE("Check DB config failed, not found or type of %s is not NUMBER.", name.c_str()); return false; } - static const std::vector pageSizeValid = { 4, 8, 16, 32, 64 }; - if (std::find(pageSizeValid.begin(), pageSizeValid.end(), configValue.GetIntValue()) == pageSizeValid.end()) { - GLOGE("Check DB config failed, invalid pageSize value."); - errCode = -E_INVALID_CONFIG_VALUE; + if (checkValid && !checkValid(static_cast(configValue.GetIntValue()))) { + GLOGE("Check DB config failed, invalid %s value.", name.c_str()); return false; } - pageSize = static_cast(configValue.GetIntValue()); + val = static_cast(configValue.GetIntValue()); return true; } -bool CheckRedoFlushConfig(const JsonObject &config, uint32_t &redoFlush, int &errCode) +bool CheckPageSizeConfig(const JsonObject &config, int32_t &pageSize) { - static const JsonFieldPath redoFlushField = { DB_CONFIG_REDO_FLUSH_BY_TRX }; - if (!config.IsFieldExists(redoFlushField)) { - return true; - } - - ValueObject configValue = config.GetObjectByPath(redoFlushField, errCode); - if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of redoFlushByTrx is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - if (configValue.GetIntValue() != 0 && configValue.GetIntValue() != 1) { - GLOGE("Check DB config failed, invalid redoFlushByTrx value."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - redoFlush = static_cast(configValue.GetIntValue()); - return true; + std::function checkFunction = [](int32_t val) { + static const std::vector pageSizeValid = { 4, 8, 16, 32, 64 }; + return std::find(pageSizeValid.begin(), pageSizeValid.end(), val) != pageSizeValid.end(); + }; + return CheckAndGetDBConfig(config, DB_CONFIG_PAGESIZE, checkFunction, pageSize); } -bool CheckRedoBufSizeConfig(const JsonObject &config, uint32_t &redoBufSize, int &errCode) +bool CheckRedoFlushConfig(const JsonObject &config, uint32_t &redoFlush) { - static const JsonFieldPath redoBufSizeField = { DB_CONFIG_REDO_PUB_BUFF_SIZE }; - if (!config.IsFieldExists(redoBufSizeField)) { - return true; - } - - ValueObject configValue = config.GetObjectByPath(redoBufSizeField, errCode); - if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of redoPubBufSize is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - if (configValue.GetIntValue() < MIN_REDO_BUFFER_SIZE || configValue.GetIntValue() > MAX_REDO_BUFFER_SIZE) { - GLOGE("Check DB config failed, invalid redoPubBufSize value."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - redoBufSize = static_cast(configValue.GetIntValue()); - return true; + std::function checkFunction = [](uint32_t val) { + return val == 0 || val == 1; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_REDO_FLUSH_BY_TRX, checkFunction, redoFlush); } -bool CheckMaxConnNumConfig(const JsonObject &config, int32_t &maxConnNum, int &errCode) +bool CheckRedoBufSizeConfig(const JsonObject &config, uint32_t &redoBufSize) { - static const JsonFieldPath maxConnNumField = { DB_CONFIG_MAX_CONN_NUM }; - if (!config.IsFieldExists(maxConnNumField)) { - return true; - } - - ValueObject configValue = config.GetObjectByPath(maxConnNumField, errCode); - if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of maxConnNum is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - if (configValue.GetIntValue() < MIN_CONNECTION_NUM || configValue.GetIntValue() > MAX_CONNECTION_NUM) { - GLOGE("Check DB config failed, invalid maxConnNum value."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - maxConnNum = static_cast(configValue.GetIntValue()); - return true; + std::function checkFunction = [](uint32_t val) { + return val >= MIN_REDO_BUFFER_SIZE && val <= MAX_REDO_BUFFER_SIZE; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_REDO_PUB_BUFF_SIZE, checkFunction, redoBufSize); } -bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint32_t &redoBufSize, int &errCode) +bool CheckMaxConnNumConfig(const JsonObject &config, int32_t &maxConnNum) { - static const JsonFieldPath bufferPoolSizeField = { DB_CONFIG_BUFFER_POOL_SIZE }; - if (!config.IsFieldExists(bufferPoolSizeField)) { - return true; - } - - ValueObject configValue = config.GetObjectByPath(bufferPoolSizeField, errCode); - if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of bufferPoolSize is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - if (configValue.GetIntValue() < MIN_BUFFER_POOL_SIZE || configValue.GetIntValue() > MAX_BUFFER_POOL_SIZE || - configValue.GetIntValue() < pageSize * 33) { - GLOGE("Check DB config failed, invalid bufferPoolSize value."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - redoBufSize = static_cast(configValue.GetIntValue()); - return true; + std::function checkFunction = [](int32_t val) { + return val >= MIN_CONNECTION_NUM && val <= MAX_CONNECTION_NUM; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_MAX_CONN_NUM, checkFunction, maxConnNum); } -bool CheckCrcCheckEnableConfig(const JsonObject &config, uint32_t &crcCheckEnable, int &errCode) +bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint32_t &redoBufSize) { - static const JsonFieldPath crcCheckEnableField = { DB_CONFIG_CRC_CHECK_ENABLE }; - if (!config.IsFieldExists(crcCheckEnableField)) { - return true; - } - - ValueObject configValue = config.GetObjectByPath(crcCheckEnableField, errCode); - if (configValue.GetValueType() != ValueObject::ValueType::VALUE_NUMBER) { - GLOGE("Check DB config failed, the field type of crcCheckEnable is not NUMBER."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } - - if (configValue.GetIntValue() != 0 && configValue.GetIntValue() != 1) { - GLOGE("Check DB config failed, invalid crcCheckEnable value."); - errCode = -E_INVALID_CONFIG_VALUE; - return false; - } + std::function checkFunction = [&pageSize](uint32_t val) { + return val >= MIN_BUFFER_POOL_SIZE && val <= MAX_BUFFER_POOL_SIZE && val >= pageSize * 64; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_BUFFER_POOL_SIZE, checkFunction, redoBufSize); +} - crcCheckEnable = static_cast(configValue.GetIntValue()); - return true; +bool CheckCrcCheckEnableConfig(const JsonObject &config, uint32_t &crcCheckEnable) +{ + std::function checkFunction = [](uint32_t val) { + return val == 0 || val == 1; + }; + return CheckAndGetDBConfig(config, DB_CONFIG_BUFFER_POOL_SIZE, checkFunction, crcCheckEnable); } int CheckConfigValid(const JsonObject &config) @@ -244,33 +173,39 @@ DBConfig DBConfig::ReadConfig(const std::string &confStr, int &errCode) } DBConfig conf; - if (!CheckPageSizeConfig(dbConfig, conf.pageSize_, errCode)) { - GLOGE("Check DB config 'pageSize' failed. %d", errCode); + if (!CheckPageSizeConfig(dbConfig, conf.pageSize_)) { + GLOGE("Check DB config 'pageSize' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } - if (!CheckRedoFlushConfig(dbConfig, conf.redoFlushByTrx_, errCode)) { - GLOGE("Check DB config 'redoFlushByTrx' failed. %d", errCode); + if (!CheckRedoFlushConfig(dbConfig, conf.redoFlushByTrx_)) { + GLOGE("Check DB config 'redoFlushByTrx' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } - if (!CheckRedoBufSizeConfig(dbConfig, conf.redoPubBufSize_, errCode)) { - GLOGE("Check DB config 'redoPubBufSize' failed. %d", errCode); + if (!CheckRedoBufSizeConfig(dbConfig, conf.redoPubBufSize_)) { + GLOGE("Check DB config 'redoPubBufSize' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } - if (!CheckMaxConnNumConfig(dbConfig, conf.maxConnNum_, errCode)) { - GLOGE("Check DB config 'maxConnNum' failed. %d", errCode); + if (!CheckMaxConnNumConfig(dbConfig, conf.maxConnNum_)) { + GLOGE("Check DB config 'maxConnNum' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } - if (!CheckBufferPoolSizeConfig(dbConfig, conf.pageSize_, conf.bufferPoolSize_, errCode)) { - GLOGE("Check DB config 'bufferPoolSize' failed. %d", errCode); + if (!CheckBufferPoolSizeConfig(dbConfig, conf.pageSize_, conf.bufferPoolSize_)) { + GLOGE("Check DB config 'bufferPoolSize' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } - if (!CheckCrcCheckEnableConfig(dbConfig, conf.crcCheckEnable_, errCode)) { - GLOGE("Check DB config 'crcCheckEnable' failed. %d", errCode); + if (!CheckCrcCheckEnableConfig(dbConfig, conf.crcCheckEnable_)) { + GLOGE("Check DB config 'crcCheckEnable' failed."); + errCode = -E_INVALID_CONFIG_VALUE; return {}; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 0045d798..d00c4683 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -202,7 +202,7 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, std::string priFieldName = node.GetItemFiled(); for (size_t j = 0; j < priFieldName.size(); j++) { if (priFieldName[j] != '.') { - tempParseName = tempParseName + priFieldName[j]; + tempParseName += priFieldName[j]; } if (priFieldName[j] == '.' || j == priFieldName.size() - 1) { if (j > 0 && priFieldName[j] == '.' && priFieldName[j - 1] == '.') { @@ -249,7 +249,7 @@ std::vector> JsonCommon::ParsePath(const JsonObject &ro namespace { JsonFieldPath SplitePath(const JsonFieldPath &path, bool &isCollapse) { - if (path.size() > 1 || path.empty()) { // only first lever has collapse field + if (path.size() > 1 || path.empty()) { // only first level has collapse field return path; } JsonFieldPath splitPath; @@ -299,7 +299,6 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, } child = child.GetNext(); } - return; } void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, @@ -314,7 +313,6 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, } child = child.GetNext(); } - return; } bool IsNumber(const std::string &str) @@ -533,7 +531,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl if (!isCollapse) { bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); if (!ret) { - return false; // replace faild + return false; // replace failed } isAddedFlag = true; return false; // Different node types, overwrite directly, skip child node @@ -656,8 +654,7 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target if (src.IsFieldExistsPowerMode(itemPath)) { if (isCollapse) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); - } - else { + } else { JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp index e6df873c..246852eb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp @@ -27,7 +27,7 @@ void PrintLog(Logger::Level level, const std::string &tag, const std::string &ms return; } const std::string format = "%{public}s"; - OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001630, tag.c_str() }; // log module id. // TODO: + OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag.c_str() }; switch (level) { case Logger::Level::LEVEL_DEBUG: (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); @@ -60,7 +60,7 @@ void PreparePrivateLog(const char *format, std::string &outStrFormat) } } // namespace -void Logger::Log(Level level, const std::string &tag, const char *func, int line, const char *format, ...) +void Logger::Log(Level level, const std::string &tag, const char *format, ...) { static const int maxLogLength = 1024; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp index 1af7c1ff..f3e2a983 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp @@ -40,7 +40,7 @@ bool CheckPathExistence(const std::string &filePath) int GetRealPath(const std::string &inOriPath, std::string &outRealPath) { const unsigned int MAX_PATH_LENGTH = PATH_MAX; - if (inOriPath.length() > MAX_PATH_LENGTH || MAX_PATH_LENGTH > 0x10000) { // max limit is 64K(0x10000). + if (inOriPath.length() > MAX_PATH_LENGTH) { // max limit is 64K(0x10000). GLOGE("[OS_API] OriPath too long."); return -E_INVALID_ARGS; } @@ -79,7 +79,6 @@ void SplitFilePath(const std::string &filePath, std::string &fileDir, std::strin fileDir = filePath.substr(0, slashPos); fileName = filePath.substr(slashPos + 1); - return; } } // namespace OSAPI } // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp index 1dec89b6..30eeb22f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp @@ -40,7 +40,7 @@ int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GR if (*db == nullptr) { (void)DocumentStoreManager::CloseDocumentStore(store, GRD_DB_CLOSE_IGNORE_ERROR); store = nullptr; - return TransferDocErr(-E_OUT_OF_MEMORY); + return GRD_FAILED_MEMORY_ALLOCATE; } (*db)->store_ = store; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index 94bb5138..ec4a6436 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -38,9 +38,18 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi return (strncasecmp(name.c_str(), prefix.c_str(), prefix.length()) == 0); } + +void ReplaceAll(std::string &inout, const std::string &what, const std::string &with) +{ + std::string::size_type pos {}; + while ((pos = inout.find(what.data(), pos, what.length())) != std::string::npos) { + inout.replace(pos, what.length(), with.data(), with.length()); + pos += with.length(); + } +} } // namespace -bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::string &lowerCaseName, int &errCode) +bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::string &formattedName, int &errCode) { if (collectionName.empty()) { errCode = -E_INVALID_ARGS; @@ -56,10 +65,13 @@ bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::st errCode = -E_INVALID_COLL_NAME_FORMAT; return false; } - lowerCaseName = collectionName; - std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { + + formattedName = collectionName; + std::transform(formattedName.begin(), formattedName.end(), formattedName.begin(), [](unsigned char c) { return std::tolower(c); }); + + ReplaceAll(formattedName, "'", R"('')"); return true; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h index 94952795..3e5b984f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h @@ -28,7 +28,7 @@ public: CheckCommon() = default; ~CheckCommon() = default; - static bool CheckCollectionName(const std::string &collectionName, std::string &lowerCaseName, int &errCode); + static bool CheckCollectionName(const std::string &collectionName, std::string &formattedName, int &errCode); static int CheckFilter(JsonObject &document); static int CheckFilter(JsonObject &document, bool &isOnlyId, std::vector> &filterPath); static bool CheckFilter(const std::string &filter, std::string &idStr, int &errCode); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h index 2c54187b..a3cf1f0a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h @@ -30,23 +30,32 @@ public: DocumentStore(KvStoreExecutor *); ~DocumentStore(); - int CreateCollection(const std::string &name, const std::string &option, int flags); - int DropCollection(const std::string &name, int flags); + int CreateCollection(const std::string &name, const std::string &option, unsigned int flags); + + int DropCollection(const std::string &name, unsigned int flags); + + int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, + unsigned int flags); - int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, int flags); int UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, - int flags); - int InsertDocument(const std::string &collection, const std::string &document, int flag); - int DeleteDocument(const std::string &collection, const std::string &filter, int flag); + unsigned int flags); + + int InsertDocument(const std::string &collection, const std::string &document, unsigned int flags); + + int DeleteDocument(const std::string &collection, const std::string &filter, unsigned int flags); + int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, - int flags, GRD_ResultSet *grdResultSet); + unsigned int flags, GRD_ResultSet *grdResultSet); + KvStoreExecutor *GetExecutor(int errCode); + bool IsCollectionOpening(const std::string collection); + int EraseCollection(const std::string collectionName); void OnClose(const std::function ¬ifier); - int Close(int flags); + int Close(unsigned int flags); private: int GetViewType(JsonObject &jsonObj, bool &viewType); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp index edf9b8d7..8672338d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp @@ -71,6 +71,7 @@ int TransferDocErr(int err) outErr = GRD_RESOURCE_BUSY; break; case -E_FAILED_MEMORY_ALLOCATE: + case -E_OUT_OF_MEMORY: outErr = GRD_FAILED_MEMORY_ALLOCATE; break; default: diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index a1c9ae11..4da036dd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -37,7 +37,7 @@ DocumentStore::~DocumentStore() delete executor_; } -int DocumentStore::CreateCollection(const std::string &name, const std::string &option, int flags) +int DocumentStore::CreateCollection(const std::string &name, const std::string &option, unsigned int flags) { std::string lowerCaseName; int errCode = E_OK; @@ -53,7 +53,7 @@ int DocumentStore::CreateCollection(const std::string &name, const std::string & return errCode; } - if (flags != 0 && flags != CHK_EXIST_COLLECTION) { + if (flags != 0u && flags != CHK_EXIST_COLLECTION) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } @@ -81,7 +81,7 @@ END: return errCode; } -int DocumentStore::DropCollection(const std::string &name, int flags) +int DocumentStore::DropCollection(const std::string &name, unsigned int flags) { std::string lowerCaseName; int errCode = E_OK; @@ -90,7 +90,7 @@ int DocumentStore::DropCollection(const std::string &name, int flags) return errCode; } - if (flags != 0 && flags != CHK_NON_EXIST_COLLECTION) { + if (flags != 0u && flags != CHK_NON_EXIST_COLLECTION) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } @@ -125,7 +125,7 @@ END: } int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - int flags) + unsigned int flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -225,7 +225,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, - const std::string &document, int flags) + const std::string &document, unsigned int flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -337,10 +337,10 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return errCode; } -int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, int flag) +int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, unsigned int flags) { - if (flag != 0) { - GLOGE("InsertDocument flag is not zero"); + if (flags != 0u) { + GLOGE("InsertDocument flags is not zero"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; @@ -390,10 +390,10 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri } } -int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, int flag) +int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, unsigned int flags) { - if (flag != 0) { - GLOGE("DeleteDocument flag is not zero"); + if (flags != 0u) { + GLOGE("DeleteDocument flags is not zero"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; @@ -465,10 +465,10 @@ KvStoreExecutor *DocumentStore::GetExecutor(int errCode) return executor_; } int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, - const std::string &projection, int flags, GRD_ResultSet *grdResultSet) + const std::string &projection, unsigned int flags, GRD_ResultSet *grdResultSet) { - if (flags != 0 && flags != GRD_DOC_ID_DISPLAY) { - GLOGE("FindDocument flag is illegal"); + if (flags != 0u && flags != GRD_DOC_ID_DISPLAY) { + GLOGE("FindDocument flags is illegal"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; @@ -626,7 +626,7 @@ void DocumentStore::OnClose(const std::function ¬ifier) closeNotifier_ = notifier; } -int DocumentStore::Close(int flags) +int DocumentStore::Close(unsigned int flags) { std::lock_guard lock(dbMutex_); if (flags == GRD_DB_CLOSE && !collections_.empty()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index ed4d1169..0a51e18f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -15,6 +15,7 @@ #include "json_object.h" #include +#include #include "doc_errno.h" #include "log_print.h" @@ -69,7 +70,7 @@ bool ValueObject::GetBoolValue() const int64_t ValueObject::GetIntValue() const { - return static_cast(doubleValue + 0.5); + return static_cast(std::llround(doubleValue)); } double ValueObject::GetDoubleValue() const @@ -262,7 +263,7 @@ int JsonObject::CheckSubObj(std::set &filedSet, cJSON *subObj, int return E_OK; } if (fieldName.empty()) { - return -E_INVALID_JSON_FORMAT; + return -E_INVALID_JSON_FORMAT; } if (filedSet.find(fieldName) == filedSet.end()) { filedSet.insert(fieldName); @@ -377,11 +378,14 @@ int JsonObject::AddItemToObject(const JsonObject &item) int JsonObject::AddItemToObject(const std::string &fieldName, const JsonObject &item) { + if (cjson_ == nullptr) { + return -E_ERROR; + } + if (item.IsNull()) { GLOGD("Add null object."); return E_OK; } - // TODO: check item exist if (cjson_->type == cJSON_Array) { int n = 0; cJSON *child = cjson_->child; @@ -405,7 +409,6 @@ int JsonObject::AddItemToObject(const std::string &fieldName, const JsonObject & int JsonObject::AddItemToObject(const std::string &fieldName) { - // TODO: check item exist if (cjson_->type == cJSON_Array) { int n = 0; cJSON *child = cjson_->child; @@ -632,7 +635,6 @@ JsonObject JsonObject::FindItem(const JsonFieldPath &jsonPath, int &errCode) con curr.cjson_ = cjson_; curr.caseSensitive_ = caseSensitive_; curr.isOwner_ = false; - GLOGW("Path empty, return current object"); return curr; } @@ -656,7 +658,6 @@ JsonObject JsonObject::FindItemPowerMode(const JsonFieldPath &jsonPath, int &err curr.cjson_ = cjson_; curr.caseSensitive_ = caseSensitive_; curr.isOwner_ = false; - GLOGW("Path empty, return current object"); return curr; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp index 70c159de..64845403 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp @@ -586,8 +586,6 @@ HWTEST_F(DocumentDBApiTest, CloseDBFlagTest002, TestSize.Level0) EXPECT_EQ(status, GRD_OK); ASSERT_NE(db, nullptr); - // TODO: open result set - status = GRD_DBClose(db, GRD_DB_CLOSE_IGNORE_ERROR); EXPECT_EQ(status, GRD_OK); db = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp index f63fed02..42c1cb7f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp @@ -118,8 +118,9 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest002, TestSize.Level0) HWTEST_F(DocumentDBCollectionTest, CollectionTest003, TestSize.Level0) { string overLenName(MAX_COLLECTION_LEN - 1, 'a'); - std::vector validName = { "123", "&^%@", "中文字符", "sqlite_master", "NULL", "SELECT", - overLenName.c_str() }; + std::vector validName = { "123", "&^%@", "中文字符", "sqlite_master", "NULL", "SELECT", "CREATE", + "student/", "student'", "student\"", "student[", "student]", "student%", "student&", "student_", "student(", + "student)", overLenName.c_str() }; for (auto *it : validName) { GLOGD("CollectionTest003: create collection with name: %s", it); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp index 9b08e1c5..b68538b9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp @@ -32,19 +32,20 @@ const int MAX_ID_LENS = 899; static void TestInsertDocIntoCertainColl(const char *collectionName, const char *projection, int expectedResult) { - /** * @tc.steps: step1. Create Collection - * @tc.expected: step1. GRD_OK - */ + /** + * @tc.steps: step1. Create Collection + * @tc.expected: step1. GRD_OK + */ EXPECT_EQ(GRD_CreateCollection(g_db, collectionName, "", 0), expectedResult); /** - * @tc.steps: step2. Insert projection into colloction. - * @tc.expected: step2. GRD_OK - */ + * @tc.steps: step2. Insert projection into colloction. + * @tc.expected: step2. GRD_OK + */ EXPECT_EQ(GRD_InsertDoc(g_db, collectionName, projection, 0), expectedResult); /** - * @tc.steps: step3. Call GRD_DroCollection to drop the collection. - * @tc.expected: step3. GRD_OK - */ + * @tc.steps: step3. Call GRD_DroCollection to drop the collection. + * @tc.expected: step3. GRD_OK + */ EXPECT_EQ(GRD_DropCollection(g_db, collectionName, 0), expectedResult); } @@ -824,7 +825,6 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest043, TestSize.Level1) HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest044, TestSize.Level1) { - const char *document1 = R""({"_id":"0123", "num":"num"})""; const char *document2 = R""({"_id":"0123", "NUM":"No.45"})""; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.cpp index f26640ad..0a5531c5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.cpp @@ -18,7 +18,7 @@ namespace DocumentDBUnitTest { int DocumentDBTestUtils::RemoveTestDbFiles(const std::string &dir) { - (void)remove(dir.c_str()); // TODO: remove dir or files + (void)remove(dir.c_str()); return 0; } } // namespace DocumentDBUnitTest \ No newline at end of file -- Gitee From cd83b809dffbe61e7c14422d3038c3eed645a6ae Mon Sep 17 00:00:00 2001 From: lianhuix Date: Wed, 10 May 2023 14:45:45 +0800 Subject: [PATCH 2/2] Fix api Signed-off-by: lianhuix --- .../include/grd_base/grd_db_api.h | 8 +++++--- .../include/grd_base/grd_resultset_api.h | 10 ++++++---- .../include/grd_document/grd_document_api.h | 20 ++++++++++--------- .../src/executor/base/grd_db_api.cpp | 6 +++--- .../executor/document/grd_document_api.cpp | 14 ++++++------- .../executor/document/grd_resultset_api.cpp | 8 ++++---- .../src/interface/include/document_store.h | 16 +++++++-------- .../include/document_store_manager.h | 4 ++-- .../src/interface/src/document_store.cpp | 16 +++++++-------- .../interface/src/document_store_manager.cpp | 6 +++--- 10 files changed, 57 insertions(+), 51 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h index e08fb605..cc1da4b9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_db_api.h @@ -16,17 +16,19 @@ #ifndef GRD_DB_API_H #define GRD_DB_API_H +#include + #include "grd_type_export.h" #ifdef __cplusplus extern "C" { #endif // __cplusplus -GRD_API int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GRD_DB **db); +GRD_API int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db); -GRD_API int GRD_DBClose(GRD_DB *db, unsigned int flags); +GRD_API int32_t GRD_DBClose(GRD_DB *db, uint32_t flags); -GRD_API int GRD_Flush(GRD_DB *db, unsigned int flags); +GRD_API int32_t GRD_Flush(GRD_DB *db, uint32_t flags); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h index 008a1cbc..c9365f18 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_resultset_api.h @@ -16,6 +16,8 @@ #ifndef GRD_RESULTSET_API_H #define GRD_RESULTSET_API_H +#include + #include "grd_base/grd_type_export.h" #ifdef __cplusplus @@ -24,13 +26,13 @@ extern "C" { typedef struct GRD_ResultSet GRD_ResultSet; -GRD_API int GRD_Next(GRD_ResultSet *resultSet); +GRD_API int32_t GRD_Next(GRD_ResultSet *resultSet); -GRD_API int GRD_GetValue(GRD_ResultSet *resultSet, char **value); +GRD_API int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value); -GRD_API int GRD_FreeValue(char *value); +GRD_API int32_t GRD_FreeValue(char *value); -GRD_API int GRD_FreeResultSet(GRD_ResultSet *resultSet); +GRD_API int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h index e6e5bb72..bd6e77c2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h @@ -16,6 +16,8 @@ #ifndef GRD_DOCUMENT_API_H #define GRD_DOCUMENT_API_H +#include + #include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" @@ -23,22 +25,22 @@ extern "C" { #endif -GRD_API int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, unsigned int flags); +GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags); -GRD_API int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flags); +GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags); -GRD_API int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, unsigned int flags); +GRD_API int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags); -GRD_API int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, +GRD_API int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet); -GRD_API int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, - unsigned int flags); +GRD_API int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, + uint32_t flags); -GRD_API int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, - unsigned int flags); +GRD_API int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, + uint32_t flags); -GRD_API int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, unsigned int flags); +GRD_API int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags); #ifdef __cplusplus } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp index 30eeb22f..4da4291e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GRD_DB **db) +int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) { if (db == nullptr) { return GRD_INVALID_ARGS; @@ -47,7 +47,7 @@ int GRD_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, GR return TransferDocErr(ret); } -int GRD_DBClose(GRD_DB *db, unsigned int flags) +int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -63,7 +63,7 @@ int GRD_DBClose(GRD_DB *db, unsigned int flags) return GRD_OK; } -int GRD_Flush(GRD_DB *db, unsigned int flags) +int32_t GRD_Flush(GRD_DB *db, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp index 78273d64..5fffa173 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp @@ -21,7 +21,7 @@ #include "log_print.h" using namespace DocumentDB; -int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, unsigned int flags) +int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -33,7 +33,7 @@ int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *opt return TransferDocErr(ret); } -int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flags) +int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -44,7 +44,7 @@ int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flag return TransferDocErr(ret); } -int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, unsigned int flags) +int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || update == nullptr) { return GRD_INVALID_ARGS; @@ -58,7 +58,7 @@ int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, co return TransferDocErr(ret); } -int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, unsigned int flags) +int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || document == nullptr) { @@ -73,7 +73,7 @@ int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, co return TransferDocErr(ret); } -int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, unsigned int flags) +int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || document == nullptr) { return GRD_INVALID_ARGS; @@ -82,7 +82,7 @@ int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, return TransferDocErr(ret); } -int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, unsigned int flags) +int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || filter == nullptr || collectionName == nullptr) { return GRD_INVALID_ARGS; @@ -105,7 +105,7 @@ int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, un return errCode; } -int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, GRD_ResultSet **resultSet) +int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || resultSet == nullptr || query.filter == nullptr || query.projection == nullptr) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp index fd3643a3..20cbe48a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int GRD_Next(GRD_ResultSet *resultSet) +int32_t GRD_Next(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { GLOGE("resultSet is nullptr"); @@ -35,7 +35,7 @@ int GRD_Next(GRD_ResultSet *resultSet) return TransferDocErr(ret); } -int GRD_GetValue(GRD_ResultSet *resultSet, char **value) +int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) { if (resultSet == nullptr) { GLOGE("resultSet is nullptr,cant get value from it"); @@ -51,7 +51,7 @@ int GRD_GetValue(GRD_ResultSet *resultSet, char **value) return TransferDocErr(ret); } -int GRD_FreeValue(char *value) +int32_t GRD_FreeValue(char *value) { if (value == nullptr) { return GRD_INVALID_ARGS; @@ -60,7 +60,7 @@ int GRD_FreeValue(char *value) return GRD_OK; } -int GRD_FreeResultSet(GRD_ResultSet *resultSet) +int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { return GRD_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h index a3cf1f0a..9fb37fd7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h @@ -30,22 +30,22 @@ public: DocumentStore(KvStoreExecutor *); ~DocumentStore(); - int CreateCollection(const std::string &name, const std::string &option, unsigned int flags); + int CreateCollection(const std::string &name, const std::string &option, uint32_t flags); - int DropCollection(const std::string &name, unsigned int flags); + int DropCollection(const std::string &name, uint32_t flags); int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - unsigned int flags); + uint32_t flags); int UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, - unsigned int flags); + uint32_t flags); - int InsertDocument(const std::string &collection, const std::string &document, unsigned int flags); + int InsertDocument(const std::string &collection, const std::string &document, uint32_t flags); - int DeleteDocument(const std::string &collection, const std::string &filter, unsigned int flags); + int DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags); int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, - unsigned int flags, GRD_ResultSet *grdResultSet); + uint32_t flags, GRD_ResultSet *grdResultSet); KvStoreExecutor *GetExecutor(int errCode); @@ -55,7 +55,7 @@ public: void OnClose(const std::function ¬ifier); - int Close(unsigned int flags); + int Close(uint32_t flags); private: int GetViewType(JsonObject &jsonObj, bool &viewType); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h index 076c2791..4696beab 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h @@ -25,10 +25,10 @@ namespace DocumentDB { class DocumentStoreManager { public: - static int GetDocumentStore(const std::string &path, const std::string &config, unsigned int flags, + static int GetDocumentStore(const std::string &path, const std::string &config, uint32_t flags, DocumentStore *&store); - static int CloseDocumentStore(DocumentStore *store, unsigned int flags); + static int CloseDocumentStore(DocumentStore *store, uint32_t flags); private: static int CheckDBPath(const std::string &path, std::string &canonicalPath, std::string &dbName); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 4da036dd..f5182019 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -37,7 +37,7 @@ DocumentStore::~DocumentStore() delete executor_; } -int DocumentStore::CreateCollection(const std::string &name, const std::string &option, unsigned int flags) +int DocumentStore::CreateCollection(const std::string &name, const std::string &option, uint32_t flags) { std::string lowerCaseName; int errCode = E_OK; @@ -81,7 +81,7 @@ END: return errCode; } -int DocumentStore::DropCollection(const std::string &name, unsigned int flags) +int DocumentStore::DropCollection(const std::string &name, uint32_t flags) { std::string lowerCaseName; int errCode = E_OK; @@ -125,7 +125,7 @@ END: } int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - unsigned int flags) + uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -225,7 +225,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, - const std::string &document, unsigned int flags) + const std::string &document, uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -337,7 +337,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return errCode; } -int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, unsigned int flags) +int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) { if (flags != 0u) { GLOGE("InsertDocument flags is not zero"); @@ -390,7 +390,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri } } -int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, unsigned int flags) +int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) { if (flags != 0u) { GLOGE("DeleteDocument flags is not zero"); @@ -465,7 +465,7 @@ KvStoreExecutor *DocumentStore::GetExecutor(int errCode) return executor_; } int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, - const std::string &projection, unsigned int flags, GRD_ResultSet *grdResultSet) + const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { if (flags != 0u && flags != GRD_DOC_ID_DISPLAY) { GLOGE("FindDocument flags is illegal"); @@ -626,7 +626,7 @@ void DocumentStore::OnClose(const std::function ¬ifier) closeNotifier_ = notifier; } -int DocumentStore::Close(unsigned int flags) +int DocumentStore::Close(uint32_t flags) { std::lock_guard lock(dbMutex_); if (flags == GRD_DB_CLOSE && !collections_.empty()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp index b52e9993..42afc2fc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp @@ -36,7 +36,7 @@ bool CheckDBCloseFlag(unsigned int flag) return (flag == GRD_DB_CLOSE) || (flag == GRD_DB_CLOSE_IGNORE_ERROR); } -bool CheckDBCreate(unsigned int flags, const std::string &path) +bool CheckDBCreate(uint32_t flags, const std::string &path) { if ((flags & GRD_DB_OPEN_CREATE) == 0 && !OSAPI::CheckPathExistence(path)) { return false; @@ -48,7 +48,7 @@ bool CheckDBCreate(unsigned int flags, const std::string &path) std::mutex DocumentStoreManager::openCloseMutex_; std::map DocumentStoreManager::dbConnCount_; -int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::string &config, unsigned int flags, +int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::string &config, uint32_t flags, DocumentStore *&store) { std::string canonicalPath; @@ -107,7 +107,7 @@ int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::s return errCode; } -int DocumentStoreManager::CloseDocumentStore(DocumentStore *store, unsigned int flags) +int DocumentStoreManager::CloseDocumentStore(DocumentStore *store, uint32_t flags) { if (!CheckDBCloseFlag(flags)) { GLOGE("Check document db close flags failed."); -- Gitee