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_DATABASE_UTILS_H 17 #define NATIVE_RDB_SQLITE_DATABASE_UTILS_H 18 19 #include <map> 20 #include <string> 21 #include <mutex> 22 23 #include "rdb_store_config.h" 24 25 namespace OHOS { 26 namespace NativeRdb { 27 enum Type { 28 STATEMENT_SELECT = 1, 29 STATEMENT_UPDATE = 2, 30 STATEMENT_ATTACH = 3, 31 STATEMENT_DETACH = 4, 32 STATEMENT_BEGIN = 5, 33 STATEMENT_COMMIT = 6, 34 STATEMENT_ROLLBACK = 7, 35 STATEMENT_PRAGMA = 8, 36 STATEMENT_DDL = 9, 37 STATEMENT_OTHER = 99, 38 DATA_TYPE_BOOLEAN = 5, 39 DATA_TYPE_BLOB = 4, 40 DATA_TYPE_STRING = 3, 41 DATA_TYPE_FLOAT = 2, 42 DATA_TYPE_INTEGER = 1, 43 DATA_TYPE_NULL = 0, 44 SQL_FIRST_CHARACTER = 3 45 }; 46 47 class SqliteDatabaseUtils { 48 public: 49 static std::map<std::string, int> MapInit(); 50 static int GetSqlStatementType(std::string sql); 51 static void DeleteFile(std::string &fileName); 52 static bool RenameFile(std::string &oldFileName, std::string &newFileName); 53 static std::string GetDefaultDatabasePath(std::string &context, std::string &name, int &errorCode); 54 static std::string GetCorruptPath(std::string &path, int &errorCode); 55 static std::string GetDatabasePathNoName(std::string &context, RdbStoreConfig &fileConfig, int &errorCode); 56 57 private: 58 static std::map<std::string, int> g_statementType; 59 static std::mutex g_locker; 60 static int g_mkdirMode; 61 62 SqliteDatabaseUtils(); 63 ~SqliteDatabaseUtils(); 64 65 static std::string GetDatabaseDir(RdbStoreConfig &fileConfig, std::string &securityLevel); 66 }; 67 } // namespace NativeRdb 68 } // namespace OHOS 69 70 #endif 71