openPilotLog
|
The DB class encapsulates the SQL database by providing fast access to hot database data. More...
#include <adatabase.h>
Signals | |
void | dataBaseUpdated () |
updated is emitted whenever the database contents have been updated. This can be either a commit, update or remove. This signal should be used to trigger an update to the models of the views displaying database contents in the user interface so that a user is always presented with up-to-date information. | |
void | connectionReset () |
connectionReset is emitted whenever the database connection is reset, for example when creating or restoring a backup. | |
Public Member Functions | |
ADatabase (const ADatabase &)=delete | |
void | operator= (const ADatabase &)=delete |
int | dbRevision () const |
dbRevision returns the database Revision Number. The Revision refers to what iteration of the database layout is used. For the sqlite version of the database refer to sqliteVersion() More... | |
TableNames_T | getTableNames () const |
Return the names of all tables in the database. | |
ColumnNames_T | getTableColumns (TableName_T table_name) const |
Return the names of a given table in the database. | |
void | updateLayout () |
Updates the member variables tableNames and tableColumns with up-to-date layout information if the database has been altered. This function is normally only required during database setup or maintenance. | |
const QString | sqliteVersion () const |
ADatabase::sqliteVersion returns the database sqlite version. See also dbRevision() More... | |
bool | connect () |
Connect to the database and populate database information. | |
void | disconnect () |
closes the database connection. | |
QVector< QVariant > | customQuery (QString statement, int return_values) |
Can be used to send a complex query to the database. More... | |
bool | exists (AEntry entry) |
Checks if an entry exists in the database, based on position data. | |
bool | exists (DataPosition data_position) |
bool | commit (AEntry entry) |
commits an entry to the database, calls either insert or update, based on position data | |
bool | insert (AEntry new_entry) |
Create new entry in the databse based on UserInput. | |
bool | update (AEntry updated_entry) |
Updates entry in database from existing entry tweaked by the user. | |
bool | remove (AEntry entry) |
deletes an entry from the database. | |
bool | removeMany (QList< DataPosition >) |
deletes a list of entries from the database. Optimised for speed when deleting many entries. | |
RowData_T | getEntryData (DataPosition data_position) |
retreive entry data from the database to create an entry object | |
AEntry | getEntry (DataPosition data_position) |
retreive an Entry from the database. | |
APilotEntry | getPilotEntry (RowId_T row_id) |
retreives a PilotEntry from the database. More... | |
ATailEntry | getTailEntry (RowId_T row_id) |
retreives a TailEntry from the database. More... | |
AAircraftEntry | getAircraftEntry (RowId_T row_id) |
retreives a TailEntry from the database. More... | |
AFlightEntry | getFlightEntry (RowId_T row_id) |
retreives a flight entry from the database. More... | |
ACurrencyEntry | getCurrencyEntry (ACurrencyEntry::CurrencyName currency_name) |
Retreives a currency entry from the database. | |
const QStringList | getCompletionList (ADatabaseTarget target) |
getCompletionList returns a QStringList of values for a QCompleter based on database values | |
const QMap< QString, RowId_T > | getIdMap (ADatabaseTarget target) |
returns a QMap<QString, RowId_t> of a human-readable database value and its row id. Used in the Dialogs to map user input to unique database entries. More... | |
int | getLastEntry (ADatabaseTarget target) |
returns the ROWID for the newest entry in the respective database. | |
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. | |
APilotEntry | resolveForeignPilot (RowId_T foreign_key) |
Resolves the foreign key in a flight entry. More... | |
ATailEntry | resolveForeignTail (RowId_T foreign_key) |
Resolves the foreign key in a flight entry. More... | |
QMap< ADatabaseSummaryKey, QString > | databaseSummary (const QString &db_path) |
Return a summary of a database. More... | |
const QString | databaseSummaryString (const QString &db_path) |
returns a short summary string of the database, containing total time and date of last flight. | |
bool | restoreBackup (const QString &backup_file) |
ADatabase::restoreBackup restores the database from a given backup file and replaces the currently active database. More... | |
bool | createBackup (const QString &dest_file) |
ADatabase::createBackup copies the currently used database to an external backup location provided by the user. More... | |
Static Public Member Functions | |
static ADatabase * | instance () |
static QSqlDatabase | database () |
Can be used to access the database connection. More... | |
Public Attributes | |
ADatabaseError | lastError |
lastError extends QSqlError. Holds information about the last error that ocurred during a SQL operation. | |
const QFileInfo | databaseFile |
The DB class encapsulates the SQL database by providing fast access to hot database data.
bool ADatabase::createBackup | ( | const QString & | dest_file | ) |
ADatabase::createBackup copies the currently used database to an external backup location provided by the user.
dest_file | This is the full path and filename of where the backup will be created, e.g. 'home/Sully/myBackups/backupFromOpl.db' |
QVector< QVariant > ADatabase::customQuery | ( | QString | statement, |
int | return_values | ||
) |
Can be used to send a complex query to the database.
query | - the full sql query statement |
returnValues | - the number of return values |
|
static |
Can be used to access the database connection.
QMap< ADatabaseSummaryKey, QString > ADatabase::databaseSummary | ( | const QString & | db_path | ) |
Return a summary of a database.
Creates a summary of the database giving a quick overview of the relevant contents. The function runs several specialised SQL queries to create a QMap<ADatabaseSummaryKey, QString> containing Total Flight Time, Number of unique aircraft and pilots, as well as the date of last flight. Uses a temporary database connection separate from the default connection in order to not tamper with the currently active database connection.
int ADatabase::dbRevision | ( | ) | const |
dbRevision returns the database Revision Number. The Revision refers to what iteration of the database layout is used. For the sqlite version of the database refer to sqliteVersion()
AAircraftEntry ADatabase::getAircraftEntry | ( | RowId_T | row_id | ) |
retreives a TailEntry from the database.
This function is a wrapper for DataBase::getEntry(DataPosition), where the table is already set and which returns an AAircraftEntry instead of an AEntry. It allows for easy access to an aircraft entry with only the RowId required as input.
AFlightEntry ADatabase::getFlightEntry | ( | RowId_T | row_id | ) |
retreives a flight entry from the database.
This function is a wrapper for DataBase::getEntry(DataPosition), where the table is already set and which returns an AFlightEntry instead of an AEntry. It allows for easy access to a flight entry with only the RowId required as input.
const QMap< QString, RowId_T > ADatabase::getIdMap | ( | ADatabaseTarget | target | ) |
returns a QMap<QString, RowId_t> of a human-readable database value and its row id. Used in the Dialogs to map user input to unique database entries.
APilotEntry ADatabase::getPilotEntry | ( | RowId_T | row_id | ) |
retreives a PilotEntry from the database.
This function is a wrapper for DataBase::getEntry(DataPosition), where the table is already set and which returns a PilotEntry instead of an Entry. It allows for easy access to a pilot entry with only the RowId required as input.
ATailEntry ADatabase::getTailEntry | ( | RowId_T | row_id | ) |
retreives a TailEntry from the database.
This function is a wrapper for DataBase::getEntry(DataPosition), where the table is already set and which returns a TailEntry instead of an Entry. It allows for easy access to a tail entry with only the RowId required as input.
APilotEntry ADatabase::resolveForeignPilot | ( | RowId_T | foreign_key | ) |
Resolves the foreign key in a flight entry.
ATailEntry ADatabase::resolveForeignTail | ( | RowId_T | foreign_key | ) |
Resolves the foreign key in a flight entry.
bool ADatabase::restoreBackup | ( | const QString & | backup_file | ) |
ADatabase::restoreBackup restores the database from a given backup file and replaces the currently active database.
backup_file | This is the full path and filename of the backup, e.g. 'home/Sully/myBackups/backupFromOpl.db' |
const QString ADatabase::sqliteVersion | ( | ) | const |
ADatabase::sqliteVersion returns the database sqlite version. See also dbRevision()