1 /* 2 * Copyright (c) 2022 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 NATIVE_RDB_RDBPREDICATES_H 17 #define NATIVE_RDB_RDBPREDICATES_H 18 #include "abs_rdb_predicates.h" 19 #include "rdb_visibility.h" 20 21 namespace OHOS { 22 namespace NativeRdb { 23 /** 24 * The RdbPredicates class of RDB. 25 */ 26 class API_EXPORT RdbPredicates : public AbsRdbPredicates { 27 public: 28 /** 29 * @brief Constructor. 30 * 31 * A parameterized constructor used to create an AbsRdbPredicates instance. 32 * 33 * @param tableName Indicates the table name of the database. 34 */ 35 API_EXPORT explicit RdbPredicates(const std::string &tableName); 36 37 /** 38 * @brief Destructor. 39 */ ~RdbPredicates()40 API_EXPORT ~RdbPredicates() override {} 41 42 /** 43 * @brief Obtains the join clause in the predicates. 44 */ 45 API_EXPORT std::string GetJoinClause() const override; 46 47 /** 48 * @brief Adds a {@code cross join} condition to a SQL statement. 49 */ 50 API_EXPORT RdbPredicates *CrossJoin(const std::string &tableName); 51 52 /** 53 * @brief Adds an {@code inner join} condition to a SQL statement. 54 */ 55 API_EXPORT RdbPredicates *InnerJoin(const std::string &tableName); 56 57 /** 58 * @brief Adds a {@code left outer join} condition to a SQL statement. 59 */ 60 API_EXPORT RdbPredicates *LeftOuterJoin(const std::string &tableName); 61 62 /** 63 * @brief Adds a {@code using} condition to the predicate. 64 * This method is similar to {@code using} of the SQL statement. 65 */ 66 API_EXPORT RdbPredicates *Using(const std::vector<std::string> &fields); 67 68 /** 69 * @brief Adds an {@code on} condition to the predicate. 70 */ 71 API_EXPORT RdbPredicates *On(const std::vector<std::string> &clauses); 72 73 private: 74 std::string ProcessJoins() const; 75 std::string GetGrammar(int type) const; 76 RdbPredicates *Join(int join, const std::string &tableName); 77 }; 78 } // namespace NativeRdb 79 } // namespace OHOS 80 81 #endif