25 #include <QSqlDatabase>
29 #include <QSqlTableModel>
34 #include "src/database/adatabasetypes.h"
35 #include "src/classes/aentry.h"
36 #include "src/classes/apilotentry.h"
37 #include "src/classes/atailentry.h"
38 #include "src/classes/aaircraftentry.h"
39 #include "src/classes/aflightentry.h"
40 #include "src/classes/astandardpaths.h"
41 #include "src/classes/acurrencyentry.h"
43 #define SQLITE_DRIVER QStringLiteral("QSQLITE")
52 #define aDB ADatabase::instance()
58 enum class ADatabaseTarget
60 airport_identifier_icao,
61 airport_identifier_iata,
62 airport_identifier_all,
71 enum class ADatabaseTable
83 enum class ADatabaseSummaryKey {
101 : numTails(numTails_), numPilots(numPilots_){}
105 return numTails == other.numTails && numPilots == other.numPilots;
109 return numTails != other.numTails || numPilots != other.numPilots;
127 QString text()
const;
140 TableNames_T tableNames;
141 TableColumns_T tableColumns;
142 int databaseRevision;
145 int checkDbVersion()
const;
147 const static QStringList userTableNames;
148 const static QStringList templateTableNames;
149 const static int minimumDatabaseRevision;
161 const QFileInfo databaseFile;
165 void operator=(
const ADatabase&) =
delete;
218 QVector<QVariant>
customQuery(QString statement,
int return_values);
324 const QHash<RowId_T, QString>
getIdMap(ADatabaseTarget target);
357 QMap<ADatabaseSummaryKey, QString>
databaseSummary(
const QString& db_path);
371 QVector<RowData_T>
getTable(ADatabaseTable table_name);
Custom Database Error derived from QSqlError. Extends text() adding "Database Error: " before the tex...
Definition: adatabase.h:123
The DB class encapsulates the SQL database by providing fast access to hot database data.
Definition: adatabase.h:135
RowId_T getLastEntry(ADatabaseTable table)
returns the ROWID for the newest entry in the respective database.
Definition: adatabase.cpp:600
bool restoreBackup(const QString &backup_file)
ADatabase::restoreBackup restores the database from a given backup file and replaces the currently ac...
Definition: adatabase.cpp:848
bool exists(const AEntry &entry)
Checks if an entry exists in the database, based on position data.
Definition: adatabase.cpp:253
void connectionReset()
connectionReset is emitted whenever the database connection is reset, for example when creating or re...
QList< RowId_T > getForeignKeyConstraints(RowId_T foreign_row_id, ADatabaseTable target)
returns a list of ROWID's in the flights table for which foreign key constraints exist.
Definition: adatabase.cpp:627
int dbRevision() const
dbRevision returns the database Revision Number. The Revision refers to what iteration of the databas...
Definition: adatabase.cpp:45
static QSqlDatabase database()
Can be used to access the database connection.
Definition: adatabase.cpp:168
QVector< QVariant > customQuery(QString statement, int return_values)
Can be used to send a complex query to the database.
Definition: adatabase.cpp:674
const QString databaseSummaryString(const QString &db_path)
returns a short summary string of the database, containing total time and date of last flight.
Definition: adatabase.cpp:763
ATailEntry getTailEntry(RowId_T row_id)
retreives a TailEntry from the database.
Definition: adatabase.cpp:475
void updateLayout()
Updates the member variables tableNames and tableColumns with up-to-date layout information if the da...
Definition: adatabase.cpp:98
const TableNames_T getTableNames() const
Return the names of all tables in the database.
Definition: adatabase.cpp:93
APilotEntry getPilotEntry(RowId_T row_id)
retreives a PilotEntry from the database.
Definition: adatabase.cpp:468
APilotEntry resolveForeignPilot(RowId_T foreign_key)
Resolves the foreign key in a flight entry.
Definition: adatabase.cpp:664
const QString sqliteVersion() const
ADatabase::sqliteVersion returns the database sqlite version. See also dbRevision()
Definition: adatabase.cpp:124
bool remove(const AEntry &entry)
deletes an entry from the database.
Definition: adatabase.cpp:182
QMap< ADatabaseSummaryKey, QString > databaseSummary(const QString &db_path)
Return a summary of a database.
Definition: adatabase.cpp:702
ATailEntry resolveForeignTail(RowId_T foreign_key)
Resolves the foreign key in a flight entry.
Definition: adatabase.cpp:669
bool createBackup(const QString &dest_file)
ADatabase::createBackup copies the currently used database to an external backup location provided by...
Definition: adatabase.cpp:781
ACurrencyEntry getCurrencyEntry(ACurrencyEntry::CurrencyName currency_name)
Retreives a currency entry from the database.
Definition: adatabase.cpp:496
void dataBaseUpdated()
updated is emitted whenever the database contents have been updated. This can be either a commit,...
QStringList getUserTableNames()
getUserTableNames returns a list of the table names of tables that contain user-created data (flights...
Definition: adatabase.cpp:83
bool clear()
clear resets the database, i.e. deletes all content in the tables containing userdata (pilots,...
Definition: adatabase.cpp:310
AFlightEntry getFlightEntry(RowId_T row_id)
retreives a flight entry from the database.
Definition: adatabase.cpp:489
bool commit(const AEntry &entry)
commits an entry to the database, calls either insert or update, based on position data
Definition: adatabase.cpp:173
bool removeMany(QList< DataPosition >)
deletes a list of entries from the database. Optimised for speed when deleting many entries.
Definition: adatabase.cpp:210
QSqlError lastError
Holds information about the last error that ocurred during a SQL operation. If the error type is QSql...
Definition: adatabase.h:159
AEntry getEntry(DataPosition data_position)
retreive an Entry from the database.
Definition: adatabase.cpp:461
const QStringList getCompletionList(ADatabaseTarget target)
getCompletionList returns a QStringList of values for a QCompleter based on database values
Definition: adatabase.cpp:503
QVector< RowData_T > getTable(ADatabaseTable table_name)
getTable returns all contents of a given table from the database
Definition: adatabase.cpp:799
const ColumnNames_T getTableColumns(TableName_T table_name) const
Return the names of a given table in the database.
Definition: adatabase.cpp:88
UserDataState getUserDataState()
getUserDataState returns a struct containing the current amount of entries in the tails and pilots ta...
Definition: adatabase.cpp:67
bool connect()
Connect to the database and populate database information.
Definition: adatabase.cpp:133
bool insert(const AEntry &new_entry)
Create new entry in the databse based on UserInput.
Definition: adatabase.cpp:360
static int getMinimumDatabaseRevision()
getMinimumDatabaseRevision returns the minimum required database revision number required by the appl...
Definition: adatabase.cpp:57
void disconnect()
closes the database connection.
Definition: adatabase.cpp:161
bool update(const AEntry &updated_entry)
Updates entry in database from existing entry tweaked by the user.
Definition: adatabase.cpp:326
QStringList getTemplateTableNames()
getTemplateTableNames returns a list of the table names of tables that contain template data (aiports...
Definition: adatabase.cpp:62
AAircraftEntry getAircraftEntry(RowId_T row_id)
retreives a TailEntry from the database.
Definition: adatabase.cpp:482
const QHash< RowId_T, QString > getIdMap(ADatabaseTarget target)
returns a QHash of a human-readable database value and its row id. Used in the Dialogs to map user in...
Definition: adatabase.cpp:552
RowData_T getEntryData(DataPosition data_position)
retreive entry data from the database to create an entry object
Definition: adatabase.cpp:404
The Entry class encapsulates table metadata(table name, row id) and data for new and existing entries...
Definition: aentry.h:33
Definition: aflightentry.h:23
Definition: aaircraftentry.h:24
Definition: acurrencyentry.h:8
Definition: apilotentry.h:24
Definition: atailentry.h:24
Definition: adatabasetypes.h:44
The UserDateState struct caches the current number of entries in relevant database tables for fast ac...
Definition: adatabase.h:97