![]() |
openPilotLog
|
The DB class encapsulates the SQL database by providing fast access to hot database data. More...
#include <database.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 | |
Database (const Database &)=delete | |
void | operator= (const Database &)=delete |
const QString | version () const |
Return the database revision number (not the sqlite version number). | |
const QString | sqliteVersion () const |
Database::sqliteVersion returns the database sqlite version. See also dbRevision() More... | |
const QStringList | getTableNames () const |
Return the names of all tables in the database. | |
const QStringList | getTableColumns (OPL::DbTable 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. | |
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 (const OPL::Row &row) |
Checks if an entry exists in the database, based on position data. | |
bool | clear () |
clear resets the database, i.e. deletes all content in the tables containing userdata (pilots, flights, tails) | |
bool | commit (const OPL::Row &row) |
commits an entry to the database, calls either insert or update, based on position data | |
bool | commit (const QJsonArray &json_arr, const OPL::DbTable table) |
commits data imported from JSON More... | |
bool | insert (const OPL::Row &new_row) |
Create new entry in the databse based on UserInput. | |
bool | update (const OPL::Row &updated_row) |
Updates entry in database from existing entry tweaked by the user. | |
bool | remove (const OPL::Row &row) |
deletes an entry from the database. | |
bool | removeMany (OPL::DbTable table, const QList< int > &row_id_list) |
deletes a batch of entries from the database. Optimised for speed when deleting many entries. The entries are identified using their row id | |
OPL::Row | getRow (const OPL::DbTable table, const int row_id) |
retreive a Row from the database | |
RowData_T | getRowData (const OPL::DbTable table, const int row_id) |
retreive a Map of <column name, column content> for a specific row in the database. | |
OPL::PilotEntry | getPilotEntry (int row_id) |
retreives a PilotEntry from the database. More... | |
OPL::TailEntry | getTailEntry (int row_id) |
retreives a TailEntry from the database. More... | |
OPL::AircraftEntry | getAircraftEntry (int row_id) |
retreives a TailEntry from the database. More... | |
OPL::FlightEntry | getFlightEntry (int row_id) |
retreives a flight entry from the database. More... | |
OPL::SimulatorEntry | getSimEntry (int row_id) |
retreives a Simulator entry from the database. More... | |
OPL::CurrencyEntry | getCurrencyEntry (int row_id) |
Retreives a currency entry from the database. | |
int | getLastEntry (OPL::DbTable table) |
returns the ROWID for the newest entry in the respective database. | |
QList< int > | getForeignKeyConstraints (int foreign_row_id, OPL::DbTable table) |
returns a list of ROWID's in the flights table for which foreign key constraints exist. | |
bool | restoreBackup (const QString &backup_file) |
Database::restoreBackup restores the database from a given backup file and replaces the currently active database. More... | |
bool | createBackup (const QString &dest_file) |
Database::createBackup copies the currently used database to an external backup location provided by the user. More... | |
QVector< RowData_T > | getTable (OPL::DbTable table) |
getTable returns all contents of a given table from the database More... | |
const QList< OPL::DbTable > & | getUserTables () const |
getUserTables returns a list of the of the tables that contain user-created data (flights, pilots,..) | |
const QList< OPL::DbTable > & | getTemplateTables () const |
getTemplateTables returns a list of the tables that contain template data (aiports, aircraft,..) | |
const UserDataState | getUserDataState () const |
getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables. More... | |
bool | createSchema () |
Create or restore the database to its ready-to-use but empty state. More... | |
bool | importTemplateData (bool use_local_ressources) |
importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates. More... | |
bool | resetUserData () |
Delete all rows from the user data tables (flights, pliots, tails) | |
Static Public Member Functions | |
static Database * | instance () |
static QSqlDatabase | database () |
Can be used to access the database connection. More... | |
Public Attributes | |
QSqlError | lastError |
Holds information about the last error that ocurred during a SQL operation. If the error type is QSqlError::UnknownError, the error is related to data from the database (entry not found,...), otherwise the error is related to SQL execution. In this case error.type() provides further information. More... | |
const QFileInfo | databaseFile |
The DB class encapsulates the SQL database by providing fast access to hot database data.
bool OPL::Database::commit | ( | const QJsonArray & | json_arr, |
const OPL::DbTable | table | ||
) |
commits data imported from JSON
This function is used to import values to the databases which are held in JSON documents. These entries are pre-filled data used for providing completion data, such as Airport or Aircraft Type Data.
bool OPL::Database::createBackup | ( | const QString & | dest_file | ) |
Database::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' |
bool OPL::Database::createSchema | ( | ) |
Create or restore the database to its ready-to-use but empty state.
The SQL code for the database creation is stored in a .sql file which is available as a ressource. This file gets read, and the querys executed. If errors occur, returns false.
QVector< QVariant > OPL::Database::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.
|
inline |
retreives a TailEntry from the database.
This function is a wrapper for DataBase::getRowData, 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.
|
inline |
retreives a flight entry from the database.
This function is a wrapper for DataBase::getRowData, 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.
|
inline |
retreives a PilotEntry from the database.
This function is a wrapper for DataBase::getRowData, 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.
|
inline |
retreives a Simulator entry from the database.
This function is a wrapper for DataBase::getRowData, where the table is already set and which returns an ASimEntry instead of an AEntry. It allows for easy access to a Simulator entry with only the RowId required as input.
QVector< RowData_T > OPL::Database::getTable | ( | OPL::DbTable | table | ) |
getTable returns all contents of a given table from the database
|
inline |
const UserDataState OPL::Database::getUserDataState | ( | ) | const |
getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables.
bool OPL::Database::importTemplateData | ( | bool | use_local_ressources | ) |
importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates.
use_local_ressources | determines whether the included ressource files or a previously downloaded file should be used. |
bool OPL::Database::restoreBackup | ( | const QString & | backup_file | ) |
Database::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 OPL::Database::sqliteVersion | ( | ) | const |
Database::sqliteVersion returns the database sqlite version. See also dbRevision()
QSqlError OPL::Database::lastError |
Holds information about the last error that ocurred during a SQL operation. If the error type is QSqlError::UnknownError, the error is related to data from the database (entry not found,...), otherwise the error is related to SQL execution. In this case error.type() provides further information.
If the error type is QSqlError::NoError, the last executed database query was successful.