.TH "Database" 3 "Fri Mar 4 2022" "openPilotLog" \" -*- nroff -*-
.ad l
.nh
.SH NAME
Database \- The DB class encapsulates the SQL database by providing fast access to hot database data\&.  

.SH SYNOPSIS
.br
.PP
.PP
\fC#include <database\&.h>\fP
.PP
Inherits QObject\&.
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBdataBaseUpdated\fP ()"
.br
.RI "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\&. "
.ti -1c
.RI "void \fBconnectionReset\fP ()"
.br
.RI "connectionReset is emitted whenever the database connection is reset, for example when creating or restoring a backup\&. "
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBDatabase\fP (const \fBDatabase\fP &)=delete"
.br
.ti -1c
.RI "void \fBoperator=\fP (const \fBDatabase\fP &)=delete"
.br
.ti -1c
.RI "int \fBdbRevision\fP () const"
.br
.RI "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 \fBsqliteVersion()\fP "
.ti -1c
.RI "const TableNames_T \fBgetTableNames\fP () const"
.br
.RI "Return the names of all tables in the database\&. "
.ti -1c
.RI "const ColumnNames_T \fBgetTableColumns\fP (TableName_T table_name) const"
.br
.RI "Return the names of a given table in the database\&. "
.ti -1c
.RI "void \fBupdateLayout\fP ()"
.br
.RI "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\&. "
.ti -1c
.RI "const QString \fBsqliteVersion\fP () const"
.br
.RI "\fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also \fBdbRevision()\fP "
.ti -1c
.RI "bool \fBconnect\fP ()"
.br
.RI "Connect to the database and populate database information\&. "
.ti -1c
.RI "void \fBdisconnect\fP ()"
.br
.RI "closes the database connection\&. "
.ti -1c
.RI "QVector< QVariant > \fBcustomQuery\fP (QString statement, int return_values)"
.br
.RI "Can be used to send a complex query to the database\&. "
.ti -1c
.RI "bool \fBexists\fP (const \fBAEntry\fP &entry)"
.br
.RI "Checks if an entry exists in the database, based on position data\&. "
.ti -1c
.RI "bool \fBexists\fP (\fBDataPosition\fP data_position)"
.br
.ti -1c
.RI "bool \fBclear\fP ()"
.br
.RI "clear resets the database, i\&.e\&. deletes all content in the tables containing userdata (pilots, flights, tails) "
.ti -1c
.RI "bool \fBcommit\fP (const \fBAEntry\fP &entry)"
.br
.RI "commits an entry to the database, calls either insert or update, based on position data "
.ti -1c
.RI "bool \fBinsert\fP (const \fBAEntry\fP &new_entry)"
.br
.RI "Create new entry in the databse based on UserInput\&. "
.ti -1c
.RI "bool \fBupdate\fP (const \fBAEntry\fP &updated_entry)"
.br
.RI "Updates entry in database from existing entry tweaked by the user\&. "
.ti -1c
.RI "bool \fBremove\fP (const \fBAEntry\fP &entry)"
.br
.RI "deletes an entry from the database\&. "
.ti -1c
.RI "bool \fBremoveMany\fP (QList< \fBDataPosition\fP >)"
.br
.RI "deletes a list of entries from the database\&. Optimised for speed when deleting many entries\&. "
.ti -1c
.RI "OPL::RowData_T \fBgetEntryData\fP (\fBDataPosition\fP data_position)"
.br
.RI "retreive entry data from the database to create an entry object "
.ti -1c
.RI "\fBAEntry\fP \fBgetEntry\fP (\fBDataPosition\fP data_position)"
.br
.RI "retreive an Entry from the database\&. "
.ti -1c
.RI "\fBAPilotEntry\fP \fBgetPilotEntry\fP (RowId_T row_id)"
.br
.RI "retreives a PilotEntry from the database\&. "
.ti -1c
.RI "\fBATailEntry\fP \fBgetTailEntry\fP (RowId_T row_id)"
.br
.RI "retreives a TailEntry from the database\&. "
.ti -1c
.RI "\fBAAircraftEntry\fP \fBgetAircraftEntry\fP (RowId_T row_id)"
.br
.RI "retreives a TailEntry from the database\&. "
.ti -1c
.RI "\fBAFlightEntry\fP \fBgetFlightEntry\fP (RowId_T row_id)"
.br
.RI "retreives a flight entry from the database\&. "
.ti -1c
.RI "\fBACurrencyEntry\fP \fBgetCurrencyEntry\fP (ACurrencyEntry::CurrencyName currency_name)"
.br
.RI "Retreives a currency entry from the database\&. "
.ti -1c
.RI "const QStringList \fBgetCompletionList\fP (DatabaseTarget target)"
.br
.RI "getCompletionList returns a QStringList of values for a QCompleter based on database values "
.ti -1c
.RI "const QHash< RowId_T, QString > \fBgetIdMap\fP (DatabaseTarget target)"
.br
.RI "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\&. "
.ti -1c
.RI "RowId_T \fBgetLastEntry\fP (DatabaseTable table)"
.br
.RI "returns the ROWID for the newest entry in the respective database\&. "
.ti -1c
.RI "QList< RowId_T > \fBgetForeignKeyConstraints\fP (RowId_T foreign_row_id, DatabaseTable target)"
.br
.RI "returns a list of ROWID's in the flights table for which foreign key constraints exist\&. "
.ti -1c
.RI "\fBAPilotEntry\fP \fBresolveForeignPilot\fP (RowId_T foreign_key)"
.br
.RI "Resolves the foreign key in a flight entry\&. "
.ti -1c
.RI "\fBATailEntry\fP \fBresolveForeignTail\fP (RowId_T foreign_key)"
.br
.RI "Resolves the foreign key in a flight entry\&. "
.ti -1c
.RI "QMap< DatabaseSummaryKey, QString > \fBdatabaseSummary\fP (const QString &db_path)"
.br
.RI "Return a summary of a database\&. "
.ti -1c
.RI "const QString \fBdatabaseSummaryString\fP (const QString &db_path)"
.br
.RI "returns a short summary string of the database, containing total time and date of last flight\&. "
.ti -1c
.RI "bool \fBrestoreBackup\fP (const QString &backup_file)"
.br
.RI "\fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&. "
.ti -1c
.RI "bool \fBcreateBackup\fP (const QString &dest_file)"
.br
.RI "\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
.ti -1c
.RI "QVector< OPL::RowData_T > \fBgetTable\fP (DatabaseTable table_name)"
.br
.RI "getTable returns all contents of a given table from the database "
.ti -1c
.RI "QStringList \fBgetUserTableNames\fP ()"
.br
.RI "getUserTableNames returns a list of the table names of tables that contain user-created data (flights, pilots,\&.\&.) "
.ti -1c
.RI "QStringList \fBgetTemplateTableNames\fP ()"
.br
.RI "getTemplateTableNames returns a list of the table names of tables that contain template data (aiports, aircraft,\&.\&.) "
.ti -1c
.RI "\fBUserDataState\fP \fBgetUserDataState\fP ()"
.br
.RI "getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&. "
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "static \fBDatabase\fP * \fBinstance\fP ()"
.br
.ti -1c
.RI "static QSqlDatabase \fBdatabase\fP ()"
.br
.RI "Can be used to access the database connection\&. "
.ti -1c
.RI "static int \fBgetMinimumDatabaseRevision\fP ()"
.br
.RI "getMinimumDatabaseRevision returns the minimum required database revision number required by the application\&. "
.in -1c
.SS "Public Attributes"

.in +1c
.ti -1c
.RI "QSqlError \fBlastError\fP"
.br
.RI "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\&. "
.ti -1c
.RI "const QFileInfo \fBdatabaseFile\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
The DB class encapsulates the SQL database by providing fast access to hot database data\&. 
.SH "Member Function Documentation"
.PP 
.SS "bool Database::createBackup (const QString & dest_file)"

.PP
\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. 
.PP
\fBParameters\fP
.RS 4
\fIdest_file\fP This is the full path and filename of where the backup will be created, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db' 
.RE
.PP

.SS "QVector< QVariant > Database::customQuery (QString statement, int return_values)"

.PP
Can be used to send a complex query to the database\&. 
.PP
\fBParameters\fP
.RS 4
\fIquery\fP - the full sql query statement 
.br
\fIreturnValues\fP - the number of return values 
.RE
.PP

.SS "QSqlDatabase Database::database ()\fC [static]\fP"

.PP
Can be used to access the database connection\&. 
.PP
\fBReturns\fP
.RS 4
The QSqlDatabase object pertaining to the connection\&. 
.RE
.PP

.SS "QMap< DatabaseSummaryKey, QString > Database::databaseSummary (const QString & db_path)"

.PP
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\&. 
.SS "int Database::dbRevision () const"

.PP
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 \fBsqliteVersion()\fP 
.PP
\fBReturns\fP
.RS 4

.RE
.PP

.SS "\fBAAircraftEntry\fP Database::getAircraftEntry (RowId_T row_id)"

.PP
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 \fBAAircraftEntry\fP instead of an \fBAEntry\fP\&. It allows for easy access to an aircraft entry with only the RowId required as input\&. 
.SS "\fBAFlightEntry\fP Database::getFlightEntry (RowId_T row_id)"

.PP
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 \fBAFlightEntry\fP instead of an \fBAEntry\fP\&. It allows for easy access to a flight entry with only the RowId required as input\&. 
.SS "\fBAPilotEntry\fP Database::getPilotEntry (RowId_T row_id)"

.PP
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\&. 
.SS "QVector< OPL::RowData_T > Database::getTable (DatabaseTable table_name)"

.PP
getTable returns all contents of a given table from the database 
.PP
\fBReturns\fP
.RS 4

.RE
.PP

.SS "\fBATailEntry\fP Database::getTailEntry (RowId_T row_id)"

.PP
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\&. 
.SS "\fBUserDataState\fP Database::getUserDataState ()"

.PP
getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&. 
.PP
\fBReturns\fP
.RS 4

.RE
.PP

.SS "\fBAPilotEntry\fP Database::resolveForeignPilot (RowId_T foreign_key)"

.PP
Resolves the foreign key in a flight entry\&. 
.PP
\fBReturns\fP
.RS 4
The Pilot Entry referencted by the foreign key\&. 
.RE
.PP

.SS "\fBATailEntry\fP Database::resolveForeignTail (RowId_T foreign_key)"

.PP
Resolves the foreign key in a flight entry\&. 
.PP
\fBReturns\fP
.RS 4
The Tail Entry referencted by the foreign key\&. 
.RE
.PP

.SS "bool Database::restoreBackup (const QString & backup_file)"

.PP
\fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&. 
.PP
\fBParameters\fP
.RS 4
\fIbackup_file\fP This is the full path and filename of the backup, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db' 
.RE
.PP

.SS "const QString Database::sqliteVersion () const"

.PP
\fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also \fBdbRevision()\fP 
.PP
\fBReturns\fP
.RS 4
sqlite version string 
.RE
.PP

.SH "Member Data Documentation"
.PP 
.SS "QSqlError Database::lastError"

.PP
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\&. 

.SH "Author"
.PP 
Generated automatically by Doxygen for openPilotLog from the source code\&.