| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| •24 |
#include <sqlite3.h> |
| 25 |
|
| 26 |
#include "DataModel/DataModel.h" |
| 27 |
#include "Logger/Logger.h" |
| 28 |
#include "Storage/StorageInterface.h" |
| 29 |
#include "Storage/StorageParams.h" |
| 30 |
|
| 31 |
namespace Storage |
| 32 |
{ |
| 33 |
class SQLite : public StorageInterface |
| 34 |
{ |
| 35 |
public: |
| 36 |
SQLite() = delete; |
| 37 |
SQLite(const StorageParams* params); |
| 38 |
~SQLite(); |
| 39 |
|
| 40 |
void SaveHardwareParams(const Hardware::HardwareParams& params) override; |
| 41 |
void AllHardwareParams(std::map<ControlID,Hardware::HardwareParams*>& hardwareParams) override; |
| 42 |
void DeleteHardwareParams(const ControlID controlID) override; |
| 43 |
void SaveObject(const ObjectType objectType, const ObjectID objectID, const std::string& name, const std::string& object) override; |
| 44 |
void DeleteObject(const ObjectType objectType, const ObjectID objectID) override; |
| 45 |
void ObjectsOfType(const ObjectType objectType, std::vector<std::string>& objects) override; |
| 46 |
void SaveRelation(const DataModel::Relation::RelationType type, const ObjectID objectID1, const ObjectType objectType2, const ObjectID objectID2, const Priority priority, const std::string& relation) override; |
| 47 |
void DeleteRelationsFrom(const DataModel::Relation::RelationType type, const ObjectID objectID) override; |
| 48 |
void DeleteRelationsTo(const ObjectType objectType, const ObjectID objectID) override; |
| 49 |
void RelationsFrom(const DataModel::Relation::RelationType type, const ObjectID objectID, std::vector<std::string>& relations) override; |
| 50 |
void RelationsTo(const ObjectType objectType, const ObjectID objectID, std::vector<std::string>& relations) override; |
| 51 |
void SaveSetting(const std::string& key, const std::string& value) override; |
| 52 |
std::string GetSetting(const std::string& key) override; |
| 53 |
void StartTransaction() override; |
| 54 |
void CommitTransaction() override; |
| 55 |
|
| 56 |
private: |
| 57 |
sqlite3 *db; |
| 58 |
const std::string filename; |
| 59 |
Logger::Logger* logger; |
| 60 |
unsigned int keepBackups; |
| 61 |
|
| 62 |
inline bool Execute(const std::string& query, sqlite3_callback callback = nullptr, void* result = nullptr) |
| 63 |
{ |
| 64 |
return Execute(query.c_str(), callback, result); |
| 65 |
} |
| 66 |
|
| 67 |
bool Execute(const char* query, sqlite3_callback callback, void* result); |
| 68 |
bool DropTable(const std::string table); |
| 69 |
bool CreateTableHardware(); |
| 70 |
bool CreateTableObjects(); |
| 71 |
bool CreateTableRelations(const std::string& name); |
| 72 |
bool CreateTableSettings(); |
| 73 |
bool CheckTableRelations(); |
| 74 |
bool UpdateTableRelations1(); |
| 75 |
bool RenameTable(const std::string& oldName, const std::string& newName); |
| 76 |
|
| 77 |
static int CallbackTableInfo(void *v, int argc, char **argv, char **colName); |
| 78 |
static int CallbackListTables(void *v, int argc, char **argv, char **colName); |
| 79 |
static int CallbackAllHardwareParams(void *v, int argc, char **argv, char **colName); |
| 80 |
static int CallbackStringVector(void* v, int argc, char **argv, char **colName); |
| 81 |
static std::string EscapeString(const std::string& input); |
| 82 |
}; |
| 83 |
} |
| 84 |
|