1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef QUERY_HELPER_H 17 #define QUERY_HELPER_H 18 19 #include <set> 20 21 #include "query.h" 22 #include "types.h" 23 24 namespace OHOS::DistributedKv { 25 class QueryHelper { 26 public: 27 API_EXPORT static DistributedDB::Query StringToDbQuery(const std::string &query, bool &isSuccess); 28 29 private: 30 using DBQuery = DistributedDB::Query; 31 static std::string deviceId_; 32 static bool hasPrefixKey_; 33 static bool hasInKeys_; 34 static bool Handle(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 35 static bool HandleExtra(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 36 static bool HandleEqualTo(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 37 static bool HandleNotEqualTo(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 38 static bool HandleGreaterThan(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 39 static bool HandleLessThan(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 40 static bool HandleGreaterThanOrEqualTo( 41 const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 42 static bool HandleLessThanOrEqualTo(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 43 static bool HandleIsNull(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 44 static bool HandleIsNotNull(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 45 static bool HandleIn(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 46 static bool HandleNotIn(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 47 static bool HandleLike(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 48 static bool HandleNotLike(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 49 static bool HandleAnd(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 50 static bool HandleOr(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 51 static bool HandleOrderByAsc(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 52 static bool HandleOrderByDesc(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 53 static bool HandleOrderByWriteTime(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 54 static bool HandleLimit(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 55 static bool HandleBeginGroup(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 56 static bool HandleEndGroup(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 57 static bool HandleKeyPrefix(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 58 static bool HandleInKeys(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 59 static bool HandleSetSuggestIndex(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 60 static bool HandleDeviceId(const std::vector<std::string> &words, int &pointer, int end, DBQuery &dbQuery); 61 static int StringToInt(const std::string &word); 62 static int64_t StringToLong(const std::string &word); 63 static double StringToDouble(const std::string &word); 64 static bool StringToBoolean(const std::string &word); 65 static std::string StringToString(const std::string &word); 66 static std::vector<int> GetIntegerList(const std::vector<std::string> &words, int &elementPointer, int end); 67 static std::vector<int64_t> GetLongList(const std::vector<std::string> &words, int &elementPointer, int end); 68 static std::vector<double> GetDoubleList(const std::vector<std::string> &words, int &elementPointer, int end); 69 static std::vector<std::string> GetStringList(const std::vector<std::string> &words, int &elementPointer, int end); 70 }; 71 } // namespace OHOS::DistributedKv 72 #endif // QUERY_HELPER_H 73