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 NATIVE_RDB_SQLITE_SQL_BUILDER_H 17 #define NATIVE_RDB_SQLITE_SQL_BUILDER_H 18 19 #include <map> 20 #include <sstream> 21 #include <string> 22 #include <vector> 23 24 #include "rdb_store.h" 25 namespace OHOS { 26 namespace NativeRdb { 27 class SqliteSqlBuilder { 28 public: 29 SqliteSqlBuilder(); 30 ~SqliteSqlBuilder(); 31 static std::string BuildDeleteString(const std::string &tableName, const std::string &index, 32 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset); 33 static std::string BuildUpdateString(const ValuesBucket &values, const std::string &tableName, 34 const std::vector<std::string> &whereArgs, const std::string &index, const std::string &whereClause, 35 const std::string &group, const std::string &order, int limit, int offset, std::vector<ValueObject> &bindArgs, 36 ConflictResolution conflictResolution); 37 static int BuildQueryString(bool distinct, const std::string &table, const std::string &joinClause, 38 const std::vector<std::string> &columns, const std::string &whereClause, const std::string &groupBy, 39 const std::string &indexName, const std::string &orderBy, const int &limit, 40 const int &offset, std::string &outSql); 41 static std::string BuildCountString(const std::string &tableName, const std::string &index, 42 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset); 43 static std::string BuildSqlStringFromPredicates(const std::string &index, const std::string &joinClause, 44 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset); 45 static std::string BuildSqlStringFromPredicatesNoWhere(const std::string &index, const std::string &whereClause, 46 const std::string &group, const std::string &order, int limit, int offset); 47 static std::string BuildQueryString(const AbsRdbPredicates &predicates, const std::vector<std::string> &columns); 48 static std::string BuildCountString(const AbsRdbPredicates &predicates); 49 static std::string BuildSqlStringFromPredicates(const AbsPredicates &predicates); 50 static std::string BuildCursorQueryString( 51 const AbsRdbPredicates &predicates, const std::vector<std::string> &columns, const std::string &logTable); 52 53 private: 54 static void AppendClause(std::string &builder, const std::string &name, 55 const std::string &clause, const std::string &table = ""); 56 static void AppendColumns( 57 std::string &builder, const std::vector<std::string> &columns, const std::string &table = ""); 58 }; 59 } // namespace NativeRdb 60 } // namespace OHOS 61 #endif 62