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 28 class SqliteSqlBuilder { 29 public: 30 SqliteSqlBuilder(); 31 ~SqliteSqlBuilder(); 32 static std::string BuildDeleteString(const std::string &tableName, const std::string &index, 33 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset); 34 static std::string BuildUpdateString(const ValuesBucket &values, const std::string &tableName, 35 const std::vector<std::string> &whereArgs, const std::string &index, const std::string &whereClause, 36 const std::string &group, const std::string &order, int limit, int offset, std::vector<ValueObject> &bindArgs, 37 ConflictResolution conflictResolution); 38 static std::string BuildUpdateStringOnlyWhere(const ValuesBucket &values, const std::string &tableName, 39 const std::vector<std::string> &whereArgs, const std::string &index, const std::string &whereClause, 40 const std::string &group, const std::string &order, int limit, int offset, std::vector<ValueObject> &bindArgs, 41 ConflictResolution conflictResolution); 42 static int BuildQueryString(bool distinct, const std::string &table, const std::vector<std::string> &columns, 43 const std::string &where, const std::string &groupBy, const std::string &having, const std::string &orderBy, 44 const std::string &limit, const std::string &offset, std::string &outSql); 45 static std::string BuildQueryStringWithExpr(const std::string &tableName, bool distinct, const std::string &index, 46 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset, 47 std::vector<std::string> &expr); 48 static std::string BuildCountString(const std::string &tableName, const std::string &index, 49 const std::string &whereClause, const std::string &group, const std::string &order, int limit, int offset); 50 static std::string BuildSqlStringFromPredicates(const std::string &index, const std::string &whereClause, 51 const std::string &group, const std::string &order, int limit, int offset); 52 static std::string BuildSqlStringFromPredicatesNoWhere(const std::string &index, const std::string &whereClause, 53 const std::string &group, const std::string &order, int limit, int offset); 54 static std::string Normalize(const std::string &source, int &errorCode); 55 56 static std::string BuildQueryString(const AbsRdbPredicates &predicates, 57 const std::vector<std::string> &columns); 58 static std::string BuildCountString(const AbsRdbPredicates &predicates); 59 static std::string BuildSqlStringFromPredicates(const AbsRdbPredicates &predicates); 60 61 private: 62 static void AppendClause(std::string &builder, const std::string &name, const std::string &clause); 63 static void AppendColumns(std::string &builder, const std::vector<std::string> &columns, int &errorCode); 64 static void AppendExpr(std::string &builder, std::vector<std::string> &exprs); 65 static bool IsNotEmptyString(const std::string &str); 66 static std::string NormalizeComplexPattern(const std::string &source, int &errorCode); 67 }; 68 69 } // namespace NativeRdb 70 } // namespace OHOS 71 #endif 72