• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UTILS_H
17 #define NATIVE_RDB_SQLITE_UTILS_H
18 
19 #include <map>
20 #include <string>
21 
22 namespace OHOS {
23 namespace NativeRdb {
24 
25 class SqliteUtils {
26 public:
27     static const int STATEMENT_SELECT;
28     static const int STATEMENT_UPDATE;
29     static const int STATEMENT_ATTACH;
30     static const int STATEMENT_DETACH;
31     static const int STATEMENT_BEGIN;
32     static const int STATEMENT_COMMIT;
33     static const int STATEMENT_ROLLBACK;
34     static const int STATEMENT_PRAGMA;
35     static const int STATEMENT_DDL;
36     static const int STATEMENT_OTHER;
37     static const int CONFLICT_CLAUSE_COUNT = 6;
38     static constexpr const char* REP = "#_";
39 
40     static int GetSqlStatementType(const std::string &sql);
41     static bool IsSqlReadOnly(int sqlType);
42     static bool IsSpecial(int sqlType);
43     static int GetConflictClause(int conflictResolution, std::string &conflictClause);
44     static std::string StrToUpper(std::string s);
45     static void Replace(std::string &src, const std::string &rep, const std::string &dst);
46     static bool DeleteFile(const std::string path);
47     static int RenameFile(const std::string srcFile, const std::string destFile);
48     static std::string Anonymous(const std::string &srcFile);
49     static int GetFileSize(const std::string fileName);
50 
51 private:
52     static const std::map<std::string, int> SQL_TYPE_MAP;
53     static const std::string ON_CONFLICT_CLAUSE[CONFLICT_CLAUSE_COUNT];
54 };
55 
56 } // namespace NativeRdb
57 } // namespace OHOS
58 #endif