Database(3)

NAME
Database - The DB class encapsulates the SQL database by providing fast access to hot database data.

SYNOPSIS

#include <database.h>

Inherits QObject.

  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
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()
const TableNames_T getTableNames () const
Return the names of all tables in the database.
const 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
Database::sqliteVersion returns the database sqlite version. See also dbRevision()
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.
bool exists (const AEntry &entry)
Checks if an entry exists in the database, based on position data.
bool exists (DataPosition data_position)
bool clear ()
clear resets the database, i.e. deletes all content in the tables containing userdata (pilots, flights, tails)
bool commit (const AEntry &entry)
commits an entry to the database, calls either insert or update, based on position data
bool insert (const AEntry &new_entry)
Create new entry in the databse based on UserInput.
bool update (const AEntry &updated_entry)
Updates entry in database from existing entry tweaked by the user.
bool remove (const 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.
OPL::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.
ATailEntry getTailEntry (RowId_T row_id)
retreives a TailEntry from the database.
AAircraftEntry getAircraftEntry (RowId_T row_id)
retreives a TailEntry from the database.
AFlightEntry getFlightEntry (RowId_T row_id)
retreives a flight entry from the database.
ACurrencyEntry getCurrencyEntry (ACurrencyEntry::CurrencyName currency_name)
Retreives a currency entry from the database.
const QStringList getCompletionList (DatabaseTarget target)
getCompletionList returns a QStringList of values for a QCompleter based on database values
const QHash< RowId_T, QString > getIdMap (DatabaseTarget target)
returns a QHash of a human-readable database value and its row id. Used in the Dialogs to map user input to unique database entries.
RowId_T getLastEntry (DatabaseTable table)
returns the ROWID for the newest entry in the respective database.
QList< RowId_T > getForeignKeyConstraints (RowId_T foreign_row_id, DatabaseTable 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.
ATailEntry resolveForeignTail (RowId_T foreign_key)
Resolves the foreign key in a flight entry.
QMap< DatabaseSummaryKey, QString > databaseSummary (const QString &db_path)
Return a summary of a database.
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)
Database::restoreBackup restores the database from a given backup file and replaces the currently active database.
bool createBackup (const QString &dest_file)
Database::createBackup copies the currently used database to an external backup location provided by the user.
QVector< OPL::RowData_T > getTable (DatabaseTable table_name)
getTable returns all contents of a given table from the database
QStringList getUserTableNames ()
getUserTableNames returns a list of the table names of tables that contain user-created data (flights, pilots,..)
QStringList getTemplateTableNames ()
getTemplateTableNames returns a list of the table names of tables that contain template data (aiports, aircraft,..)
UserDataState getUserDataState ()
getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables.

  Static Public Member Functions
static Database * instance ()
static QSqlDatabase database ()
Can be used to access the database connection.
static int getMinimumDatabaseRevision ()
getMinimumDatabaseRevision returns the minimum required database revision number required by the application.

  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.
const QFileInfo databaseFile

Detailed Description

The DB class encapsulates the SQL database by providing fast access to hot database data.

Member Function Documentation

  bool Database::createBackup (const QString & dest_file)

Database::createBackup copies the currently used database to an external backup location provided by the user.

Parameters
    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 > Database::customQuery (QString statement, int return_values)

Can be used to send a complex query to the database.

Parameters
    query - the full sql query statement
    returnValues - the number of return values

  QSqlDatabase Database::database () [static]

Can be used to access the database connection.

Returns
    The QSqlDatabase object pertaining to the connection.

  QMap< DatabaseSummaryKey, QString > Database::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 QHash<DatabaseSummaryKey, 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 Database::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()

Returns

  AAircraftEntry Database::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 Database::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.

  APilotEntry Database::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.

  QVector< OPL::RowData_T > Database::getTable (DatabaseTable table_name)

getTable returns all contents of a given table from the database

Returns

  ATailEntry Database::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.

  UserDataState Database::getUserDataState ()

getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables.

Returns

  APilotEntry Database::resolveForeignPilot (RowId_T foreign_key)

Resolves the foreign key in a flight entry.

Returns
    The Pilot Entry referencted by the foreign key.

  ATailEntry Database::resolveForeignTail (RowId_T foreign_key)

Resolves the foreign key in a flight entry.

Returns
    The Tail Entry referencted by the foreign key.

  bool Database::restoreBackup (const QString & backup_file)

Database::restoreBackup restores the database from a given backup file and replaces the currently active database.

Parameters
    backup_file This is the full path and filename of the backup, e.g. 'home/Sully/myBackups/backupFromOpl.db'

  const QString Database::sqliteVersion () const

Database::sqliteVersion returns the database sqlite version. See also dbRevision()

Returns
    sqlite version string

Member Data Documentation

  QSqlError 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.

Author

Generated automatically by Doxygen for openPilotLog from the source code.