ADatabase.3 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. .TH "ADatabase" 3 "Tue Jul 27 2021" "openPilotLog" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. ADatabase \- 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 <adatabase\&.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 "\fBADatabase\fP (const \fBADatabase\fP &)=delete"
  28. .br
  29. .ti -1c
  30. .RI "void \fBoperator=\fP (const \fBADatabase\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 "\fBADatabase::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 (\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 (\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 (\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 (\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 (\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 "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 (ADatabaseTarget target)"
  125. .br
  126. .RI "getCompletionList returns a QStringList of values for a QCompleter based on database values "
  127. .ti -1c
  128. .RI "const QMap< QString, RowId_T > \fBgetIdMap\fP (ADatabaseTarget target)"
  129. .br
  130. .RI "returns a QMap<QString, RowId_t> 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 "int \fBgetLastEntry\fP (ADatabaseTable 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, ADatabaseTable 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< ADatabaseSummaryKey, 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 "\fBADatabase::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 "\fBADatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
  163. .ti -1c
  164. .RI "QVector< RowData_T > \fBgetTable\fP (ADatabaseTable 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. .in -1c
  176. .SS "Static Public Member Functions"
  177. .in +1c
  178. .ti -1c
  179. .RI "static \fBADatabase\fP * \fBinstance\fP ()"
  180. .br
  181. .ti -1c
  182. .RI "static QSqlDatabase \fBdatabase\fP ()"
  183. .br
  184. .RI "Can be used to access the database connection\&. "
  185. .ti -1c
  186. .RI "static int \fBgetMinimumDatabaseRevision\fP ()"
  187. .br
  188. .RI "getMinimumDatabaseRevision returns the minimum required database revision number required by the application\&. "
  189. .in -1c
  190. .SS "Public Attributes"
  191. .in +1c
  192. .ti -1c
  193. .RI "QSqlError \fBlastError\fP"
  194. .br
  195. .RI "lastError extends QSqlError\&. 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\&. "
  196. .ti -1c
  197. .RI "const QFileInfo \fBdatabaseFile\fP"
  198. .br
  199. .in -1c
  200. .SH "Detailed Description"
  201. .PP
  202. The DB class encapsulates the SQL database by providing fast access to hot database data\&.
  203. .SH "Member Function Documentation"
  204. .PP
  205. .SS "bool ADatabase::createBackup (const QString & dest_file)"
  206. .PP
  207. \fBADatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&.
  208. .PP
  209. \fBParameters\fP
  210. .RS 4
  211. \fIdest_file\fP This is the full path and filename of where the backup will be created, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  212. .RE
  213. .PP
  214. .SS "QVector< QVariant > ADatabase::customQuery (QString statement, int return_values)"
  215. .PP
  216. Can be used to send a complex query to the database\&.
  217. .PP
  218. \fBParameters\fP
  219. .RS 4
  220. \fIquery\fP - the full sql query statement
  221. .br
  222. \fIreturnValues\fP - the number of return values
  223. .RE
  224. .PP
  225. .SS "QSqlDatabase ADatabase::database ()\fC [static]\fP"
  226. .PP
  227. Can be used to access the database connection\&.
  228. .PP
  229. \fBReturns\fP
  230. .RS 4
  231. The QSqlDatabase object pertaining to the connection\&.
  232. .RE
  233. .PP
  234. .SS "QMap< ADatabaseSummaryKey, QString > ADatabase::databaseSummary (const QString & db_path)"
  235. .PP
  236. 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 QMap<ADatabaseSummaryKey, 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\&.
  237. .SS "int ADatabase::dbRevision () const"
  238. .PP
  239. 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
  240. .PP
  241. \fBReturns\fP
  242. .RS 4
  243. .RE
  244. .PP
  245. .SS "\fBAAircraftEntry\fP ADatabase::getAircraftEntry (RowId_T row_id)"
  246. .PP
  247. 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\&.
  248. .SS "\fBAFlightEntry\fP ADatabase::getFlightEntry (RowId_T row_id)"
  249. .PP
  250. 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\&.
  251. .SS "const QMap< QString, RowId_T > ADatabase::getIdMap (ADatabaseTarget target)"
  252. .PP
  253. returns a QMap<QString, RowId_t> of a human-readable database value and its row id\&. Used in the Dialogs to map user input to unique database entries\&.
  254. .PP
  255. \fBTodo\fP
  256. .RS 4
  257. What is this QString semantically? As i understand its a 'QueryResult' QVariant cast to QString
  258. .RE
  259. .PP
  260. .SS "\fBAPilotEntry\fP ADatabase::getPilotEntry (RowId_T row_id)"
  261. .PP
  262. 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\&.
  263. .SS "QVector< RowData_T > ADatabase::getTable (ADatabaseTable table_name)"
  264. .PP
  265. getTable returns all contents of a given table from the database
  266. .PP
  267. \fBReturns\fP
  268. .RS 4
  269. .RE
  270. .PP
  271. .SS "\fBATailEntry\fP ADatabase::getTailEntry (RowId_T row_id)"
  272. .PP
  273. 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\&.
  274. .SS "\fBAPilotEntry\fP ADatabase::resolveForeignPilot (RowId_T foreign_key)"
  275. .PP
  276. Resolves the foreign key in a flight entry\&.
  277. .PP
  278. \fBReturns\fP
  279. .RS 4
  280. The Pilot Entry referencted by the foreign key\&.
  281. .RE
  282. .PP
  283. .SS "\fBATailEntry\fP ADatabase::resolveForeignTail (RowId_T foreign_key)"
  284. .PP
  285. Resolves the foreign key in a flight entry\&.
  286. .PP
  287. \fBReturns\fP
  288. .RS 4
  289. The Tail Entry referencted by the foreign key\&.
  290. .RE
  291. .PP
  292. .SS "bool ADatabase::restoreBackup (const QString & backup_file)"
  293. .PP
  294. \fBADatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&.
  295. .PP
  296. \fBParameters\fP
  297. .RS 4
  298. \fIbackup_file\fP This is the full path and filename of the backup, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  299. .RE
  300. .PP
  301. .SS "const QString ADatabase::sqliteVersion () const"
  302. .PP
  303. \fBADatabase::sqliteVersion\fP returns the database sqlite version\&. See also \fBdbRevision()\fP
  304. .PP
  305. \fBReturns\fP
  306. .RS 4
  307. sqlite version string
  308. .RE
  309. .PP
  310. .SH "Member Data Documentation"
  311. .PP
  312. .SS "QSqlError ADatabase::lastError"
  313. .PP
  314. lastError extends QSqlError\&. 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\&.
  315. .SH "Author"
  316. .PP
  317. Generated automatically by Doxygen for openPilotLog from the source code\&.