OPL::Database(3)

NAME
OPL::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 (const DbTable table)
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
bool connect ()
Connect to the database and populate database information.
void disconnect ()
closes the database connection.
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 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()
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.
QVector< QVariant > customQuery (QString statement, int return_values)
Can be used to send a complex query to the database.
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
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. See row class for details.
OPL::TailEntry getTailEntry (int row_id)
retreives a TailEntry from the database. See row class for details.
OPL::AircraftEntry getAircraftEntry (int row_id)
retreives a TailEntry from the database. See row class for details.
OPL::FlightEntry getFlightEntry (int row_id)
retreives a flight entry from the database. See row class for details.
OPL::SimulatorEntry getSimEntry (int row_id)
retreives a Simulator entry from the database. See row class for details.
OPL::CurrencyEntry getCurrencyEntry (int row_id)
Retreives a currency entry from the database. See row class for details.
OPL::AirportEntry getAirportEntry (int row_id)
Retreives an airport entry from the database. See row class for details.
int getLastEntry (OPL::DbTable table)
returns the ROWID for the newest entry in the respective table.
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.
QVector< RowData_T > getTable (OPL::DbTable table)
getTable returns all contents of a given table from the database
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,..)
bool createSchema ()
Create or restore the database to its ready-to-use but empty state.
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.
bool resetUserData ()
Delete all rows from the user data tables (flights, pliots, tails)
bool createBackup (const QString &dest_file)
Database::createBackup copies the currently used database to an external backup location provided by the user.
bool restoreBackup (const QString &backup_file)
Database::restoreBackup restores the database from a given backup file and replaces the currently active database.

  Static Public Member Functions
static Database * instance ()
static QSqlDatabase database ()
Can be used to access the database connection.

  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.

Detailed Description

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

Member Function Documentation

  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.

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

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

  QSqlDatabase OPL::Database::database () [static]

Can be used to access the database connection.

Returns
    The QSqlDatabase object pertaining to the connection.

  QVector< RowData_T > OPL::Database::getTable (OPL::DbTable table)

getTable returns all contents of a given table from the database

Returns

  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.

Parameters
    use_local_ressources determines whether the included ressource files or a previously downloaded file should be used.

Returns

  bool OPL::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 OPL::Database::sqliteVersion () const

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

Returns
    sqlite version string

Member Data Documentation

  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.

Author

Generated automatically by Doxygen for openPilotLog from the source code.