|
openPilotLog
|
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
61 airport_identifier_icao,
62 airport_identifier_iata,
63 airport_identifier_all,
74 enum class ADatabaseSummaryKey {
102 TableNames_T tableNames;
103 TableColumns_T tableColumns;
104 int databaseRevision;
107 int checkDbVersion()
const;
115 const QFileInfo databaseFile;
119 void operator=(
const ADatabase&) =
delete;
172 QVector<QVariant>
customQuery(QString statement,
int return_values);
273 const QMap<QString, RowId_T>
getIdMap(ADatabaseTarget target);
306 QMap<ADatabaseSummaryKey, QString>
databaseSummary(
const QString& db_path);
332 #endif // ADATABASE_H
bool exists(AEntry entry)
Checks if an entry exists in the database, based on position data.
Definition: adatabase.cpp:229
bool restoreBackup(const QString &backup_file)
ADatabase::restoreBackup restores the database from a given backup file and replaces the currently ac...
Definition: adatabase.cpp:766
void updateLayout()
Updates the member variables tableNames and tableColumns with up-to-date layout information if the da...
Definition: adatabase.cpp:65
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:726
APilotEntry resolveForeignPilot(RowId_T foreign_key)
Resolves the foreign key in a flight entry.
Definition: adatabase.cpp:630
const QStringList getCompletionList(ADatabaseTarget target)
getCompletionList returns a QStringList of values for a QCompleter based on database values
Definition: adatabase.cpp:470
void disconnect()
closes the database connection.
Definition: adatabase.cpp:131
Definition: aflightentry.h:23
APilotEntry getPilotEntry(RowId_T row_id)
retreives a PilotEntry from the database.
Definition: adatabase.cpp:435
Custom Database Error derived from QSqlError. Extends text() adding "Database Error: " before the tex...
Definition: adatabase.h:86
Definition: apilotentry.h:24
bool connect()
Connect to the database and populate database information.
Definition: adatabase.cpp:103
bool createBackup(const QString &dest_file)
ADatabase::createBackup copies the currently used database to an external backup location provided by...
Definition: adatabase.cpp:744
void connectionReset()
connectionReset is emitted whenever the database connection is reset, for example when creating or re...
const QString sqliteVersion() const
ADatabase::sqliteVersion returns the database sqlite version. See also dbRevision()
Definition: adatabase.cpp:94
void dataBaseUpdated()
updated is emitted whenever the database contents have been updated. This can be either a commit,...
QVector< QVariant > customQuery(QString statement, int return_values)
Can be used to send a complex query to the database.
Definition: adatabase.cpp:640
QMap< ADatabaseSummaryKey, QString > databaseSummary(const QString &db_path)
Return a summary of a database.
Definition: adatabase.cpp:665
AEntry getEntry(DataPosition data_position)
retreive an Entry from the database.
Definition: adatabase.cpp:428
ATailEntry getTailEntry(RowId_T row_id)
retreives a TailEntry from the database.
Definition: adatabase.cpp:442
AFlightEntry getFlightEntry(RowId_T row_id)
retreives a flight entry from the database.
Definition: adatabase.cpp:456
QList< RowId_T > getForeignKeyConstraints(RowId_T foreign_row_id, ADatabaseTarget target)
returns a list of ROWID's in the flights table for which foreign key constraints exist.
Definition: adatabase.cpp:593
AAircraftEntry getAircraftEntry(RowId_T row_id)
retreives a TailEntry from the database.
Definition: adatabase.cpp:449
Definition: adatabasetypes.h:44
Definition: atailentry.h:24
static QSqlDatabase database()
Can be used to access the database connection.
Definition: adatabase.cpp:138
The DB class encapsulates the SQL database by providing fast access to hot database data.
Definition: adatabase.h:97
bool remove(AEntry entry)
deletes an entry from the database.
Definition: adatabase.cpp:152
int getLastEntry(ADatabaseTarget target)
returns the ROWID for the newest entry in the respective database.
Definition: adatabase.cpp:565
TableNames_T getTableNames() const
Return the names of all tables in the database.
Definition: adatabase.cpp:60
RowData_T getEntryData(DataPosition data_position)
retreive entry data from the database to create an entry object
Definition: adatabase.cpp:371
bool removeMany(QList< DataPosition >)
deletes a list of entries from the database. Optimised for speed when deleting many entries.
Definition: adatabase.cpp:183
ACurrencyEntry getCurrencyEntry(ACurrencyEntry::CurrencyName currency_name)
Retreives a currency entry from the database.
Definition: adatabase.cpp:463
Definition: aaircraftentry.h:24
Definition: acurrencyentry.h:8
ATailEntry resolveForeignTail(RowId_T foreign_key)
Resolves the foreign key in a flight entry.
Definition: adatabase.cpp:635
int dbRevision() const
dbRevision returns the database Revision Number. The Revision refers to what iteration of the databas...
Definition: adatabase.cpp:43
const QMap< QString, RowId_T > getIdMap(ADatabaseTarget target)
returns a QMap<QString, RowId_t> of a human-readable database value and its row id....
Definition: adatabase.cpp:519
bool commit(AEntry entry)
commits an entry to the database, calls either insert or update, based on position data
Definition: adatabase.cpp:143
ADatabaseError lastError
lastError extends QSqlError. Holds information about the last error that ocurred during a SQL operati...
Definition: adatabase.h:113
The Entry class encapsulates table metadata(table name, row id) and data for new and existing entries...
Definition: aentry.h:40
bool insert(AEntry new_entry)
Create new entry in the databse based on UserInput.
Definition: adatabase.cpp:325
ColumnNames_T getTableColumns(TableName_T table_name) const
Return the names of a given table in the database.
Definition: adatabase.cpp:55
bool update(AEntry updated_entry)
Updates entry in database from existing entry tweaked by the user.
Definition: adatabase.cpp:289