diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h index d116ea2263c540ea73c159c185bb57c3c1191dec..baa981448cdd3b47203d7e850d561f3a685df7ef 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h @@ -21,7 +21,7 @@ extern "C" { #endif // __cplusplus #ifndef _WIN32 -#define GRD_API __attribute__((visibility("default"))) +#define GRD_API __attribute__((visibility("default"), weak)) #endif typedef struct GRD_DB GRD_DB; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index b84a888ea8aab1b99ddeb4269e41075e837e880f..858cba93fef1478e39c64f85f71ed379ddf1692a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -102,7 +102,7 @@ bool JsonCommon::CheckNode(JsonObject &node) return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || '_' == fieldName[i])) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || fieldName[i] == '_')) { return false; } if (i == 0 && (isdigit(fieldName[i]))) { @@ -144,8 +144,8 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &e return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || - (isFirstLevel && '.' == fieldName[i]))) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || (fieldName[i] == '_') || + (isFirstLevel && fieldName[i] == '.'))) { errCode = -E_INVALID_ARGS; return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp index 501ce977242ed553274b5dddf599273b17fc146c..398dbc33173e530a338a2170c896e14cf809eb1d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp @@ -20,7 +20,6 @@ namespace DocumentDB { namespace { - void PrintLog(LogPrint::Level level, const char *tag, const std::string &msg) { if (msg.empty()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp index 4da4291ebdfa63eecb3290a04bf04b2bf65240a0..f61b9ffc616a6ab4f2288087a7f2ff124cd97cd4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) +GRD_API 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 @@ int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GR return TransferDocErr(ret); } -int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) +GRD_API int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -63,7 +63,7 @@ int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) return GRD_OK; } -int32_t GRD_Flush(GRD_DB *db, uint32_t flags) +GRD_API 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/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 70792700ec194e17c76618093c9ba59d20071c24..01513f9f83652c107f714e2e1e4e41d288db0c66 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -41,7 +41,7 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi void ReplaceAll(std::string &inout, const std::string &what, const std::string &with) { - std::string::size_type pos{}; + 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(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp index 668718c8dd4158d8484459b5f03a239ed709c783..4515211c312053e2041576c8e42819081d1ff80d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -21,7 +21,7 @@ #include "log_print.h" using namespace DocumentDB; -int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) +GRD_API 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 @@ int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char return TransferDocErr(ret); } -int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) +GRD_API 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 @@ int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flag return TransferDocErr(ret); } -int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, uint32_t flags) +GRD_API 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; @@ -56,7 +56,7 @@ int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter return TransferDocErr(ret); } -int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, uint32_t flags) +GRD_API 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) { @@ -69,7 +69,7 @@ int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter return TransferDocErr(ret); } -int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags) +GRD_API 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; @@ -78,7 +78,7 @@ int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *docume return TransferDocErr(ret); } -int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags) +GRD_API 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; @@ -95,7 +95,7 @@ int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter } } -int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet) +GRD_API 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/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 296dbe582273a1adb46a58fdecc21d667445bfa3..d529552f9d1bacaefe7803050d14a6fd90b4817b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int32_t GRD_Next(GRD_ResultSet *resultSet) +GRD_API int32_t GRD_Next(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { GLOGE("resultSet is nullptr"); @@ -33,7 +33,7 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) return TransferDocErr(ret); } -int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) +GRD_API int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) { if (resultSet == nullptr || value == nullptr) { GLOGE("resultSet is nullptr,cant get value from it"); @@ -49,7 +49,7 @@ int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) return TransferDocErr(ret); } -int32_t GRD_FreeValue(char *value) +GRD_API int32_t GRD_FreeValue(char *value) { if (value == nullptr) { return GRD_INVALID_ARGS; @@ -58,7 +58,7 @@ int32_t GRD_FreeValue(char *value) return GRD_OK; } -int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet) +GRD_API int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { return GRD_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 16c551c3da6f3902b63f9bdfea0d09055269651d..c04f5c7b9007ae17bd1e9b3f975dc6e2eeafb7a1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -26,7 +26,7 @@ class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); Collection(const Collection &other); - Collection(){}; + Collection() {}; ~Collection(); int PutDocument(const Key &key, const Value &document); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 60f50c1368ac24be7ffb0055eee28b5865cd5e7a..32e2e0df74872f09215470c7ff7070d9a9f0b4e3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -295,7 +295,8 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri } else { bool isIdExist; auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); + if (!isIdExist) { errCode = -E_INVALID_ARGS; goto END; } @@ -432,7 +433,7 @@ END: Key key(id.begin(), id.end()); errCode = coll.DeleteDocument(key); } - if (errCode == E_OK || errCode == E_NOT_FOUND) { + if (errCode == E_OK || errCode == E_NOT_FOUND) { executor_->Commit(); } else { executor_->Rollback(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index bd41e033596f8f079d9f4306f4601141a0eaec34..265ca61dcec0dcc62daf7b85ef320bd5f54efd16 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -14,8 +14,6 @@ */ #include "projection_tree.h" -#include - namespace DocumentDB { const int JSON_DEEP_MAX = 4; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 3ea01a2b7ed9a54efcedac3cb9b244c09d6d7cf1..72b1b25b366a1fb994adc2d23ba63ac63504ef44 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -147,7 +147,7 @@ int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) return errCode; } errCode = GetNextInner(isNeedCheckTable); - if (errCode == E_OK || errCode == -E_NO_DATA) { + if (errCode == E_OK || errCode == -E_NO_DATA) { store_->Commit(); } else { store_->Rollback(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 3609c481f92330a0b65b10a96cdc468459406ed3..55a82f7c6c4a180da173b1fe5deb17c4091d07a4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -107,10 +107,7 @@ bool JsonObject::operator==(const JsonObject &other) const bool JsonObject::IsNull() const { - if (cjson_ == nullptr) { - return true; - } - return false; + return (cjson_ == nullptr); } JsonObject::Type JsonObject::GetType() const @@ -122,6 +119,7 @@ JsonObject::Type JsonObject::GetType() const } return JsonObject::Type::JSON_LEAF; } + int JsonObject::GetDeep() { if (cjson_ == nullptr) { @@ -134,6 +132,7 @@ int JsonObject::GetDeep() jsonDeep_ = GetDeep(cjson_); return jsonDeep_; } + int JsonObject::GetDeep(cJSON *cjson) { if (cjson->child == nullptr) { @@ -156,7 +155,7 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) if (item != NULL && cJSON_IsNumber(item)) { double value = cJSON_GetNumberValue(item); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { - errCode = E_INVALID_ARGS; + errCode = -E_INVALID_ARGS; } } if (item->child != nullptr) { @@ -185,7 +184,7 @@ int JsonObject::Init(const std::string &str, bool isFilter) int ret = 0; CheckNumber(cjson_, ret); - if (ret == E_INVALID_ARGS) { + if (ret == -E_INVALID_ARGS) { GLOGE("Int value is larger than double"); return -E_INVALID_ARGS; } @@ -261,14 +260,14 @@ std::string JsonObject::Print() const return ""; } char *ret = cJSON_PrintUnformatted(cjson_); - std::string str = ret; + std::string str = (ret == nullptr ? "" : ret); cJSON_free(ret); return str; } JsonObject JsonObject::GetObjectItem(const std::string &field, int &errCode) { - if (cjson_ == nullptr || (cjson_->type & cJSON_Object) != cJSON_Object) { + if (cjson_ == nullptr || cjson_->type != cJSON_Object) { errCode = -E_INVALID_ARGS; return JsonObject(); } @@ -288,7 +287,7 @@ JsonObject JsonObject::GetObjectItem(const std::string &field, int &errCode) JsonObject JsonObject::GetArrayItem(int index, int &errCode) { - if (cjson_ == nullptr || (cjson_->type & cJSON_Array) != cJSON_Array) { + if (cjson_ == nullptr || cjson_->type != cJSON_Array) { errCode = -E_INVALID_ARGS; return JsonObject(); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index 892ec657ccfd792de2568b02d1d6d2c99aef246c..e22232c8a6e51484b16963bf5a86e642eb63d554 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -47,6 +47,7 @@ ohos_source_set("src_file") { sources = [ "../../src/common/src/collection_option.cpp", "../../src/common/src/db_config.cpp", + "../../src/common/src/db_constant.cpp", "../../src/common/src/json_common.cpp", "../../src/common/src/log_print.cpp", "../../src/common/src/os_api.cpp",