SOLA
Loading...
Searching...
No Matches
sqlite_helper.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_SQLITE_HELPER_H_
18#define DAISI_SQLITE_HELPER_H_
19
20#include <future>
21#include <string>
22#include <vector>
23
24class sqlite3;
25
26namespace daisi {
27
29public:
33 SQLiteHelper(std::string file_path, std::string file_name);
34
37
38 void setFailed();
39
40 void execute(const std::string &query);
41
42private:
43 sqlite3 *db_ = nullptr;
44 const std::string file_path_;
45 std::string file_name_;
46 std::string temp_file_name_;
47 std::vector<std::string> queries_;
48 std::future<void> last_logging_task_;
49 bool failed_database_ = false;
50
51 // creates and opens the database files
52 void connect();
53
54 // log queued queries to database. Only used if deferred logging is enabled!
55 [[maybe_unused]] void logQueue();
56 [[maybe_unused]] void logQueueTask(const std::vector<std::string> &queries);
57
58 // executes a sql query
59 void executeSql(const char *query);
60
61 // closes the connection (or the file)
62 void disconnect();
63};
64
65} // namespace daisi
66
67#endif
Definition sqlite_helper.h:28
~SQLiteHelper()
Disconnects and renames the temporary database filename to final name.
Definition sqlite_helper.cpp:39