• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_SQL_UTILS_H
17 #define NATIVE_RDB_SQL_UTILS_H
18 #include <string>
19 #include <vector>
20 #include "abs_rdb_predicates.h"
21 #include "rdb_common.h"
22 #include "rdb_predicates.h"
23 #include "values_bucket.h"
24 #include "value_object.h"
25 
26 namespace OHOS {
27 namespace NativeRdb {
28 struct SqlInfo {
29     std::string sql;
30     std::vector<NativeRdb::ValueObject> args;
31 };
32 
33 using Values = std::vector<ValueObject>;
34 using Row = ValuesBucket;
35 using Rows = std::vector<Row>;
36 using Fields = std::vector<std::string>;
37 using Resolution = ConflictResolution;
38 
39 class API_EXPORT RdbSqlUtils {
40 public:
41     /**
42      * @brief create data base directory.
43      */
44     static int CreateDirectory(const std::string &databaseDir);
45 
46     /**
47      * @brief get custom data base path.
48      */
49     static std::pair<std::string, int> GetDefaultDatabasePath(
50         const std::string &baseDir, const std::string &name, const std::string &customDir = "");
51 
52     /**
53      * @brief get custom rootDir data base path.
54      */
55     static std::pair<std::string, int> GetCustomDatabasePath(const std::string &rootDir, const std::string &name,
56         const std::string &customDir);
57 
58     /**
59      * @brief get default data base path.
60      */
61     static std::string GetDefaultDatabasePath(const std::string &baseDir, const std::string &name, int &errorCode);
62 
63     /**
64      * @brief build query sql string.
65      */
66     static std::string BuildQueryString(const AbsRdbPredicates &predicates, const std::vector<std::string> &columns);
67 
68     static std::pair<int, SqlInfo> GetInsertSqlInfo(const std::string &table, const Row &row, Resolution resolution);
69     static std::pair<int, SqlInfo> GetUpdateSqlInfo(const AbsRdbPredicates &predicates, const Row &row,
70         Resolution resolution, const std::vector<std::string> &returningFields = {});
71     static std::pair<int, SqlInfo> GetDeleteSqlInfo(
72         const AbsRdbPredicates &predicates, const std::vector<std::string> &returningFields = {});
73     static std::pair<int, SqlInfo> GetQuerySqlInfo(const AbsRdbPredicates &predicates, const Fields &columns);
74 };
75 } // namespace NativeRdb
76 } // namespace OHOS
77 
78 #endif
79