2
0

ADatabase.3 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. .TH "Database" 3 "Fri Mar 4 2022" "openPilotLog" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. Database \- The DB class encapsulates the SQL database by providing fast access to hot database data\&.
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .PP
  10. \fC#include <database\&.h>\fP
  11. .PP
  12. Inherits QObject\&.
  13. .SS "Signals"
  14. .in +1c
  15. .ti -1c
  16. .RI "void \fBdataBaseUpdated\fP ()"
  17. .br
  18. .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\&. "
  19. .ti -1c
  20. .RI "void \fBconnectionReset\fP ()"
  21. .br
  22. .RI "connectionReset is emitted whenever the database connection is reset, for example when creating or restoring a backup\&. "
  23. .in -1c
  24. .SS "Public Member Functions"
  25. .in +1c
  26. .ti -1c
  27. .RI "\fBDatabase\fP (const \fBDatabase\fP &)=delete"
  28. .br
  29. .ti -1c
  30. .RI "void \fBoperator=\fP (const \fBDatabase\fP &)=delete"
  31. .br
  32. .ti -1c
  33. .RI "int \fBdbRevision\fP () const"
  34. .br
  35. .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 "
  36. .ti -1c
  37. .RI "const TableNames_T \fBgetTableNames\fP () const"
  38. .br
  39. .RI "Return the names of all tables in the database\&. "
  40. .ti -1c
  41. .RI "const ColumnNames_T \fBgetTableColumns\fP (TableName_T table_name) const"
  42. .br
  43. .RI "Return the names of a given table in the database\&. "
  44. .ti -1c
  45. .RI "void \fBupdateLayout\fP ()"
  46. .br
  47. .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\&. "
  48. .ti -1c
  49. .RI "const QString \fBsqliteVersion\fP () const"
  50. .br
  51. .RI "\fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also \fBdbRevision()\fP "
  52. .ti -1c
  53. .RI "bool \fBconnect\fP ()"
  54. .br
  55. .RI "Connect to the database and populate database information\&. "
  56. .ti -1c
  57. .RI "void \fBdisconnect\fP ()"
  58. .br
  59. .RI "closes the database connection\&. "
  60. .ti -1c
  61. .RI "QVector< QVariant > \fBcustomQuery\fP (QString statement, int return_values)"
  62. .br
  63. .RI "Can be used to send a complex query to the database\&. "
  64. .ti -1c
  65. .RI "bool \fBexists\fP (const \fBAEntry\fP &entry)"
  66. .br
  67. .RI "Checks if an entry exists in the database, based on position data\&. "
  68. .ti -1c
  69. .RI "bool \fBexists\fP (\fBDataPosition\fP data_position)"
  70. .br
  71. .ti -1c
  72. .RI "bool \fBclear\fP ()"
  73. .br
  74. .RI "clear resets the database, i\&.e\&. deletes all content in the tables containing userdata (pilots, flights, tails) "
  75. .ti -1c
  76. .RI "bool \fBcommit\fP (const \fBAEntry\fP &entry)"
  77. .br
  78. .RI "commits an entry to the database, calls either insert or update, based on position data "
  79. .ti -1c
  80. .RI "bool \fBinsert\fP (const \fBAEntry\fP &new_entry)"
  81. .br
  82. .RI "Create new entry in the databse based on UserInput\&. "
  83. .ti -1c
  84. .RI "bool \fBupdate\fP (const \fBAEntry\fP &updated_entry)"
  85. .br
  86. .RI "Updates entry in database from existing entry tweaked by the user\&. "
  87. .ti -1c
  88. .RI "bool \fBremove\fP (const \fBAEntry\fP &entry)"
  89. .br
  90. .RI "deletes an entry from the database\&. "
  91. .ti -1c
  92. .RI "bool \fBremoveMany\fP (QList< \fBDataPosition\fP >)"
  93. .br
  94. .RI "deletes a list of entries from the database\&. Optimised for speed when deleting many entries\&. "
  95. .ti -1c
  96. .RI "OPL::RowData_T \fBgetEntryData\fP (\fBDataPosition\fP data_position)"
  97. .br
  98. .RI "retreive entry data from the database to create an entry object "
  99. .ti -1c
  100. .RI "\fBAEntry\fP \fBgetEntry\fP (\fBDataPosition\fP data_position)"
  101. .br
  102. .RI "retreive an Entry from the database\&. "
  103. .ti -1c
  104. .RI "\fBAPilotEntry\fP \fBgetPilotEntry\fP (RowId_T row_id)"
  105. .br
  106. .RI "retreives a PilotEntry from the database\&. "
  107. .ti -1c
  108. .RI "\fBATailEntry\fP \fBgetTailEntry\fP (RowId_T row_id)"
  109. .br
  110. .RI "retreives a TailEntry from the database\&. "
  111. .ti -1c
  112. .RI "\fBAAircraftEntry\fP \fBgetAircraftEntry\fP (RowId_T row_id)"
  113. .br
  114. .RI "retreives a TailEntry from the database\&. "
  115. .ti -1c
  116. .RI "\fBAFlightEntry\fP \fBgetFlightEntry\fP (RowId_T row_id)"
  117. .br
  118. .RI "retreives a flight entry from the database\&. "
  119. .ti -1c
  120. .RI "\fBACurrencyEntry\fP \fBgetCurrencyEntry\fP (ACurrencyEntry::CurrencyName currency_name)"
  121. .br
  122. .RI "Retreives a currency entry from the database\&. "
  123. .ti -1c
  124. .RI "const QStringList \fBgetCompletionList\fP (DatabaseTarget target)"
  125. .br
  126. .RI "getCompletionList returns a QStringList of values for a QCompleter based on database values "
  127. .ti -1c
  128. .RI "const QHash< RowId_T, QString > \fBgetIdMap\fP (DatabaseTarget target)"
  129. .br
  130. .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\&. "
  131. .ti -1c
  132. .RI "RowId_T \fBgetLastEntry\fP (DatabaseTable table)"
  133. .br
  134. .RI "returns the ROWID for the newest entry in the respective database\&. "
  135. .ti -1c
  136. .RI "QList< RowId_T > \fBgetForeignKeyConstraints\fP (RowId_T foreign_row_id, DatabaseTable target)"
  137. .br
  138. .RI "returns a list of ROWID's in the flights table for which foreign key constraints exist\&. "
  139. .ti -1c
  140. .RI "\fBAPilotEntry\fP \fBresolveForeignPilot\fP (RowId_T foreign_key)"
  141. .br
  142. .RI "Resolves the foreign key in a flight entry\&. "
  143. .ti -1c
  144. .RI "\fBATailEntry\fP \fBresolveForeignTail\fP (RowId_T foreign_key)"
  145. .br
  146. .RI "Resolves the foreign key in a flight entry\&. "
  147. .ti -1c
  148. .RI "QMap< DatabaseSummaryKey, QString > \fBdatabaseSummary\fP (const QString &db_path)"
  149. .br
  150. .RI "Return a summary of a database\&. "
  151. .ti -1c
  152. .RI "const QString \fBdatabaseSummaryString\fP (const QString &db_path)"
  153. .br
  154. .RI "returns a short summary string of the database, containing total time and date of last flight\&. "
  155. .ti -1c
  156. .RI "bool \fBrestoreBackup\fP (const QString &backup_file)"
  157. .br
  158. .RI "\fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&. "
  159. .ti -1c
  160. .RI "bool \fBcreateBackup\fP (const QString &dest_file)"
  161. .br
  162. .RI "\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
  163. .ti -1c
  164. .RI "QVector< OPL::RowData_T > \fBgetTable\fP (DatabaseTable table_name)"
  165. .br
  166. .RI "getTable returns all contents of a given table from the database "
  167. .ti -1c
  168. .RI "QStringList \fBgetUserTableNames\fP ()"
  169. .br
  170. .RI "getUserTableNames returns a list of the table names of tables that contain user-created data (flights, pilots,\&.\&.) "
  171. .ti -1c
  172. .RI "QStringList \fBgetTemplateTableNames\fP ()"
  173. .br
  174. .RI "getTemplateTableNames returns a list of the table names of tables that contain template data (aiports, aircraft,\&.\&.) "
  175. .ti -1c
  176. .RI "\fBUserDataState\fP \fBgetUserDataState\fP ()"
  177. .br
  178. .RI "getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&. "
  179. .in -1c
  180. .SS "Static Public Member Functions"
  181. .in +1c
  182. .ti -1c
  183. .RI "static \fBDatabase\fP * \fBinstance\fP ()"
  184. .br
  185. .ti -1c
  186. .RI "static QSqlDatabase \fBdatabase\fP ()"
  187. .br
  188. .RI "Can be used to access the database connection\&. "
  189. .ti -1c
  190. .RI "static int \fBgetMinimumDatabaseRevision\fP ()"
  191. .br
  192. .RI "getMinimumDatabaseRevision returns the minimum required database revision number required by the application\&. "
  193. .in -1c
  194. .SS "Public Attributes"
  195. .in +1c
  196. .ti -1c
  197. .RI "QSqlError \fBlastError\fP"
  198. .br
  199. .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\&. "
  200. .ti -1c
  201. .RI "const QFileInfo \fBdatabaseFile\fP"
  202. .br
  203. .in -1c
  204. .SH "Detailed Description"
  205. .PP
  206. The DB class encapsulates the SQL database by providing fast access to hot database data\&.
  207. .SH "Member Function Documentation"
  208. .PP
  209. .SS "bool Database::createBackup (const QString & dest_file)"
  210. .PP
  211. \fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&.
  212. .PP
  213. \fBParameters\fP
  214. .RS 4
  215. \fIdest_file\fP This is the full path and filename of where the backup will be created, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  216. .RE
  217. .PP
  218. .SS "QVector< QVariant > Database::customQuery (QString statement, int return_values)"
  219. .PP
  220. Can be used to send a complex query to the database\&.
  221. .PP
  222. \fBParameters\fP
  223. .RS 4
  224. \fIquery\fP - the full sql query statement
  225. .br
  226. \fIreturnValues\fP - the number of return values
  227. .RE
  228. .PP
  229. .SS "QSqlDatabase Database::database ()\fC [static]\fP"
  230. .PP
  231. Can be used to access the database connection\&.
  232. .PP
  233. \fBReturns\fP
  234. .RS 4
  235. The QSqlDatabase object pertaining to the connection\&.
  236. .RE
  237. .PP
  238. .SS "QMap< DatabaseSummaryKey, QString > Database::databaseSummary (const QString & db_path)"
  239. .PP
  240. 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\&.
  241. .SS "int Database::dbRevision () const"
  242. .PP
  243. 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
  244. .PP
  245. \fBReturns\fP
  246. .RS 4
  247. .RE
  248. .PP
  249. .SS "\fBAAircraftEntry\fP Database::getAircraftEntry (RowId_T row_id)"
  250. .PP
  251. 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\&.
  252. .SS "\fBAFlightEntry\fP Database::getFlightEntry (RowId_T row_id)"
  253. .PP
  254. 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\&.
  255. .SS "\fBAPilotEntry\fP Database::getPilotEntry (RowId_T row_id)"
  256. .PP
  257. 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\&.
  258. .SS "QVector< OPL::RowData_T > Database::getTable (DatabaseTable table_name)"
  259. .PP
  260. getTable returns all contents of a given table from the database
  261. .PP
  262. \fBReturns\fP
  263. .RS 4
  264. .RE
  265. .PP
  266. .SS "\fBATailEntry\fP Database::getTailEntry (RowId_T row_id)"
  267. .PP
  268. 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\&.
  269. .SS "\fBUserDataState\fP Database::getUserDataState ()"
  270. .PP
  271. getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&.
  272. .PP
  273. \fBReturns\fP
  274. .RS 4
  275. .RE
  276. .PP
  277. .SS "\fBAPilotEntry\fP Database::resolveForeignPilot (RowId_T foreign_key)"
  278. .PP
  279. Resolves the foreign key in a flight entry\&.
  280. .PP
  281. \fBReturns\fP
  282. .RS 4
  283. The Pilot Entry referencted by the foreign key\&.
  284. .RE
  285. .PP
  286. .SS "\fBATailEntry\fP Database::resolveForeignTail (RowId_T foreign_key)"
  287. .PP
  288. Resolves the foreign key in a flight entry\&.
  289. .PP
  290. \fBReturns\fP
  291. .RS 4
  292. The Tail Entry referencted by the foreign key\&.
  293. .RE
  294. .PP
  295. .SS "bool Database::restoreBackup (const QString & backup_file)"
  296. .PP
  297. \fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&.
  298. .PP
  299. \fBParameters\fP
  300. .RS 4
  301. \fIbackup_file\fP This is the full path and filename of the backup, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  302. .RE
  303. .PP
  304. .SS "const QString Database::sqliteVersion () const"
  305. .PP
  306. \fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also \fBdbRevision()\fP
  307. .PP
  308. \fBReturns\fP
  309. .RS 4
  310. sqlite version string
  311. .RE
  312. .PP
  313. .SH "Member Data Documentation"
  314. .PP
  315. .SS "QSqlError Database::lastError"
  316. .PP
  317. 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\&.
  318. .SH "Author"
  319. .PP
  320. Generated automatically by Doxygen for openPilotLog from the source code\&.