LibrePCB Developers Documentation
Loading...
Searching...
No Matches
sqlitedatabase.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_SQLITEDATABASE_H
21#define LIBREPCB_CORE_SQLITEDATABASE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "fileio/filepath.h"
27
28#include <QtCore>
29#include <QtSql>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35
36/*******************************************************************************
37 * Class SQLiteDatabase
38 ******************************************************************************/
39
43class SQLiteDatabase final : public QObject {
44 Q_OBJECT
45
46public:
47 // Types
48 typedef QVector<std::pair<QString, QString>> Replacements;
50 public:
54 ~TransactionScopeGuard() noexcept;
55 void commit();
56 TransactionScopeGuard& operator=(const TransactionScopeGuard& rhs) = delete;
57
58 private:
61 };
62
63 // Constructors / Destructor
64 SQLiteDatabase() = delete;
65 SQLiteDatabase(const SQLiteDatabase& other) = delete;
66 SQLiteDatabase(const FilePath& filepath, QObject* parent = nullptr);
67 ~SQLiteDatabase() noexcept;
68
69 // SQL Commands
70 void beginTransaction();
71 void commitTransaction();
73 void clearTable(const QString& table);
74
75 // General Methods
76 QSqlQuery prepareQuery(QString query,
77 const Replacements& replacements = {}) const;
78 int count(QSqlQuery& query);
79 int insert(QSqlQuery& query);
80 void exec(QSqlQuery& query);
81 void exec(const QString& query);
82
83 // Operator Overloadings
85
86private: // Methods
97
105 QHash<QString, QString> getSqliteCompileOptions();
106
107private: // Data
108 QSqlDatabase mDb;
109};
110
111/*******************************************************************************
112 * End of File
113 ******************************************************************************/
114
115} // namespace librepcb
116
117#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
SQLiteDatabase & mDb
Definition sqlitedatabase.h:59
bool mIsCommited
Definition sqlitedatabase.h:60
~TransactionScopeGuard() noexcept
Definition sqlitedatabase.cpp:49
void commit()
Definition sqlitedatabase.cpp:44
TransactionScopeGuard(const TransactionScopeGuard &other)=delete
The SQLiteDatabase class.
Definition sqlitedatabase.h:43
SQLiteDatabase & operator=(const SQLiteDatabase &rhs)=delete
void commitTransaction()
Definition sqlitedatabase.cpp:112
int count(QSqlQuery &query)
Definition sqlitedatabase.cpp:155
void exec(QSqlQuery &query)
Definition sqlitedatabase.cpp:183
int insert(QSqlQuery &query)
Definition sqlitedatabase.cpp:170
void beginTransaction()
Definition sqlitedatabase.cpp:103
QVector< std::pair< QString, QString > > Replacements
Definition sqlitedatabase.h:48
void rollbackTransaction()
Definition sqlitedatabase.cpp:121
void clearTable(const QString &table)
Definition sqlitedatabase.cpp:130
QHash< QString, QString > getSqliteCompileOptions()
Get compile options of the SQLite driver library.
Definition sqlitedatabase.cpp:214
QSqlDatabase mDb
Definition sqlitedatabase.h:108
QSqlQuery prepareQuery(QString query, const Replacements &replacements={}) const
Definition sqlitedatabase.cpp:138
void enableSqliteWriteAheadLogging()
Enable the "Write-Ahead Logging" (WAL) feature of SQLite.
Definition sqlitedatabase.cpp:202
Definition occmodel.cpp:76