From daa882dedb0aa07d98c88bbfb03adedae58f313e Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 12 May 2023 11:05:12 +0800 Subject: [PATCH 1/2] Resolve nesting too deeply Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 90 ++++++++++--------- 1 file changed, 50 insertions(+), 40 deletions(-) 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 bf5e02a0..ad57c3c1 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 @@ -15,9 +15,9 @@ #include "document_store.h" +#include "check_common.h" #include "collection_option.h" #include "doc_errno.h" -#include "check_common.h" #include "grd_base/grd_type_export.h" #include "grd_resultset_inner.h" #include "log_print.h" @@ -560,52 +560,62 @@ int DocumentStore::EraseCollection(const std::string collectionName) return E_INVALID_ARGS; } +int JudgeViewType(size_t &index, ValueObject &leafItem, bool &viewType) +{ + switch (leafItem.GetValueType()) { + case ValueObject::ValueType::VALUE_BOOL: + if (leafItem.GetBoolValue()) { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + if (index != 0 && viewType) { + return E_INVALID_ARGS; + } + viewType = false; + } + break; + case ValueObject::ValueType::VALUE_STRING: + if (leafItem.GetStringValue() == "") { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + return -E_INVALID_ARGS; + } + break; + case ValueObject::ValueType::VALUE_NUMBER: + if (leafItem.GetIntValue() == 0) { + if (index != 0 && viewType) { + return -E_INVALID_ARGS; + } + viewType = false; + } else { + if (index != 0 && !viewType) { + return E_INVALID_ARGS; + } + viewType = true; + } + break; + default: + return E_INVALID_ARGS; + } + return E_OK; +} + int DocumentStore::GetViewType(JsonObject &jsonObj, bool &viewType) { std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); if (leafValue.size() == 0) { return E_INVALID_ARGS; } + int ret = E_OK; for (size_t i = 0; i < leafValue.size(); i++) { - switch (leafValue[i].GetValueType()) { - case ValueObject::ValueType::VALUE_BOOL: - if (leafValue[i].GetBoolValue()) { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - if (i != 0 && viewType) { - return E_INVALID_ARGS; - } - viewType = false; - } - break; - case ValueObject::ValueType::VALUE_STRING: - if (leafValue[i].GetStringValue() == "") { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - return -E_INVALID_ARGS; - } - break; - case ValueObject::ValueType::VALUE_NUMBER: - if (leafValue[i].GetIntValue() == 0) { - if (i != 0 && viewType) { - return -E_INVALID_ARGS; - } - viewType = false; - } else { - if (i != 0 && !viewType) { - return E_INVALID_ARGS; - } - viewType = true; - } - break; - default: - return E_INVALID_ARGS; + ret = JudgeViewType(i, leafValue[i], viewType); + if (ret != E_OK) { + return ret; } } return E_OK; -- Gitee From af21ec33e212c07aace0d4375c12d032ead58c36 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 12 May 2023 11:23:56 +0800 Subject: [PATCH 2/2] fix bug Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 3 --- .../data_share/gaussdb_rd/src/interface/src/collection.cpp | 1 - .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 -- 3 files changed, 6 deletions(-) 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 b84a888e..fb9f5430 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 @@ -223,9 +223,6 @@ std::vector> JsonCommon::ParsePath(const JsonObject &ro { std::vector> resultPath; JsonObject projectionJson = root.GetChild(); - if (projectionJson.IsNull()) { - GLOGE("projectionJson is null"); - } std::vector singlePath; errCode = ParseNode(projectionJson, singlePath, resultPath, true); return resultPath; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index 94f962c8..4337077e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -187,7 +187,6 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, GLOGE("Get original document failed. %d", errCode); return errCode; } - GLOGD("Update document value."); JsonObject originValue = JsonObject::Parse(valueGotStr, errCode, true); if (errCode != E_OK) { GLOGD("Parse original value failed. %d %s", errCode, valueGotStr.c_str()); 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 3609c481..d1790b28 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 @@ -670,7 +670,6 @@ int JsonObject::DeleteItemOnTarget(const JsonFieldPath &path) cJSON *nodeFather = MoveToPath(cjson_, patherPath, caseSensitive_); if (nodeFather == nullptr) { - GLOGE("Delete item failed, json field path not found."); return -E_JSON_PATH_NOT_EXISTS; } @@ -703,7 +702,6 @@ int JsonObject::DeleteItemDeeplyOnTarget(const JsonFieldPath &path) cJSON *nodeFather = MoveToPath(cjson_, patherPath, caseSensitive_); if (nodeFather == nullptr) { - GLOGE("Delete item failed, json field path not found."); return -E_JSON_PATH_NOT_EXISTS; } -- Gitee