1 /* 2 * Copyright (c) 2022 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 OHOS_RESTOOL_SQLITE_DATABASE_H 17 #define OHOS_RESTOOL_SQLITE_DATABASE_H 18 19 #include<string> 20 #include "resource_item.h" 21 #include "singleton.h" 22 #include "sqlite3.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace Restool { 27 class SqliteDatabase : public Singleton<SqliteDatabase> { 28 public: 29 void Init(const std::string &dbPath); 30 bool OpenDatabase(); 31 void CloseDatabase(); 32 bool Insert(const ResourceItem &resourceItem); SetPriority(int32_t priority)33 void SetPriority(int32_t priority) 34 { 35 priority_ = priority; 36 }; 37 private: 38 bool Query(const ResourceItem &resourceItem, int32_t &id); 39 bool FindMaxId(); 40 bool CreateTable(); 41 std::string GetValue(const ResourceItem &resourceItem) const; 42 std::string dbPath_; 43 sqlite3 *db_ = nullptr; 44 static int32_t id_; 45 int32_t priority_ = 0; 46 }; 47 } 48 } 49 } 50 #endif 51