Debian Codegraph @

Storage/Sqlite.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
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 } // namespace Storage
84