OPL_Database.3 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. .TH "OPL::Database" 3 "Tue Aug 9 2022" "openPilotLog" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. OPL::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 (const \fBDbTable\fP table)"
  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 "bool \fBconnect\fP ()"
  34. .br
  35. .RI "Connect to the database and populate database information\&. "
  36. .ti -1c
  37. .RI "void \fBdisconnect\fP ()"
  38. .br
  39. .RI "closes the database connection\&. "
  40. .ti -1c
  41. .RI "void \fBupdateLayout\fP ()"
  42. .br
  43. .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\&. "
  44. .ti -1c
  45. .RI "const QString \fBversion\fP () const"
  46. .br
  47. .RI "Return the database revision number (not the sqlite version number)\&. "
  48. .ti -1c
  49. .RI "const QString \fBsqliteVersion\fP () const"
  50. .br
  51. .RI "\fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also dbRevision() "
  52. .ti -1c
  53. .RI "const QStringList \fBgetTableNames\fP () const"
  54. .br
  55. .RI "Return the names of all tables in the database\&. "
  56. .ti -1c
  57. .RI "const QStringList \fBgetTableColumns\fP (\fBOPL::DbTable\fP table_name) const"
  58. .br
  59. .RI "Return the names of a given table in the database\&. "
  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 \fBOPL::Row\fP &row)"
  66. .br
  67. .RI "Checks if an entry exists in the database, based on position data\&. "
  68. .ti -1c
  69. .RI "bool \fBclear\fP ()"
  70. .br
  71. .RI "clear resets the database, i\&.e\&. deletes all content in the tables containing userdata (pilots, flights, tails) "
  72. .ti -1c
  73. .RI "bool \fBcommit\fP (const \fBOPL::Row\fP &row)"
  74. .br
  75. .RI "commits an entry to the database, calls either insert or update, based on position data "
  76. .ti -1c
  77. .RI "bool \fBcommit\fP (const QJsonArray &json_arr, const \fBOPL::DbTable\fP table)"
  78. .br
  79. .RI "commits data imported from JSON "
  80. .ti -1c
  81. .RI "bool \fBinsert\fP (const \fBOPL::Row\fP &new_row)"
  82. .br
  83. .RI "Create new entry in the databse based on UserInput\&. "
  84. .ti -1c
  85. .RI "bool \fBupdate\fP (const \fBOPL::Row\fP &updated_row)"
  86. .br
  87. .RI "Updates entry in database from existing entry tweaked by the user\&. "
  88. .ti -1c
  89. .RI "bool \fBremove\fP (const \fBOPL::Row\fP &row)"
  90. .br
  91. .RI "deletes an entry from the database\&. "
  92. .ti -1c
  93. .RI "bool \fBremoveMany\fP (\fBOPL::DbTable\fP table, const QList< int > &row_id_list)"
  94. .br
  95. .RI "deletes a batch of entries from the database\&. Optimised for speed when deleting many entries\&. The entries are identified using their row id "
  96. .ti -1c
  97. .RI "\fBOPL::Row\fP \fBgetRow\fP (const \fBOPL::DbTable\fP table, const int row_id)"
  98. .br
  99. .RI "retreive a \fBRow\fP from the database "
  100. .ti -1c
  101. .RI "RowData_T \fBgetRowData\fP (const \fBOPL::DbTable\fP table, const int row_id)"
  102. .br
  103. .RI "retreive a Map of <column name, column content> for a specific row in the database\&. "
  104. .ti -1c
  105. .RI "\fBOPL::PilotEntry\fP \fBgetPilotEntry\fP (int row_id)"
  106. .br
  107. .RI "retreives a \fBPilotEntry\fP from the database\&. See row class for details\&. "
  108. .ti -1c
  109. .RI "\fBOPL::TailEntry\fP \fBgetTailEntry\fP (int row_id)"
  110. .br
  111. .RI "retreives a \fBTailEntry\fP from the database\&. See row class for details\&. "
  112. .ti -1c
  113. .RI "\fBOPL::AircraftEntry\fP \fBgetAircraftEntry\fP (int row_id)"
  114. .br
  115. .RI "retreives a \fBTailEntry\fP from the database\&. See row class for details\&. "
  116. .ti -1c
  117. .RI "\fBOPL::FlightEntry\fP \fBgetFlightEntry\fP (int row_id)"
  118. .br
  119. .RI "retreives a flight entry from the database\&. See row class for details\&. "
  120. .ti -1c
  121. .RI "\fBOPL::SimulatorEntry\fP \fBgetSimEntry\fP (int row_id)"
  122. .br
  123. .RI "retreives a Simulator entry from the database\&. See row class for details\&. "
  124. .ti -1c
  125. .RI "\fBOPL::CurrencyEntry\fP \fBgetCurrencyEntry\fP (int row_id)"
  126. .br
  127. .RI "Retreives a currency entry from the database\&. See row class for details\&. "
  128. .ti -1c
  129. .RI "\fBOPL::AirportEntry\fP \fBgetAirportEntry\fP (int row_id)"
  130. .br
  131. .RI "Retreives an airport entry from the database\&. See row class for details\&. "
  132. .ti -1c
  133. .RI "int \fBgetLastEntry\fP (\fBOPL::DbTable\fP table)"
  134. .br
  135. .RI "returns the ROWID for the newest entry in the respective table\&. "
  136. .ti -1c
  137. .RI "QList< int > \fBgetForeignKeyConstraints\fP (int foreign_row_id, \fBOPL::DbTable\fP table)"
  138. .br
  139. .RI "returns a list of ROWID's in the flights table for which foreign key constraints exist\&. "
  140. .ti -1c
  141. .RI "QVector< RowData_T > \fBgetTable\fP (\fBOPL::DbTable\fP table)"
  142. .br
  143. .RI "getTable returns all contents of a given table from the database "
  144. .ti -1c
  145. .RI "const QList< \fBOPL::DbTable\fP > & \fBgetUserTables\fP () const"
  146. .br
  147. .RI "getUserTables returns a list of the of the tables that contain user-created data (flights, pilots,\&.\&.) "
  148. .ti -1c
  149. .RI "const QList< \fBOPL::DbTable\fP > & \fBgetTemplateTables\fP () const"
  150. .br
  151. .RI "getTemplateTables returns a list of the tables that contain template data (aiports, aircraft,\&.\&.) "
  152. .ti -1c
  153. .RI "bool \fBcreateSchema\fP ()"
  154. .br
  155. .RI "Create or restore the database to its ready-to-use but empty state\&. "
  156. .ti -1c
  157. .RI "bool \fBimportTemplateData\fP (bool use_local_ressources)"
  158. .br
  159. .RI "importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&. "
  160. .ti -1c
  161. .RI "bool \fBresetUserData\fP ()"
  162. .br
  163. .RI "Delete all rows from the user data tables (flights, pliots, tails) "
  164. .ti -1c
  165. .RI "bool \fBcreateBackup\fP (const QString &dest_file)"
  166. .br
  167. .RI "\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
  168. .ti -1c
  169. .RI "bool \fBrestoreBackup\fP (const QString &backup_file)"
  170. .br
  171. .RI "\fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&. "
  172. .in -1c
  173. .SS "Static Public Member Functions"
  174. .in +1c
  175. .ti -1c
  176. .RI "static \fBDatabase\fP * \fBinstance\fP ()"
  177. .br
  178. .ti -1c
  179. .RI "static QSqlDatabase \fBdatabase\fP ()"
  180. .br
  181. .RI "Can be used to access the database connection\&. "
  182. .in -1c
  183. .SS "Public Attributes"
  184. .in +1c
  185. .ti -1c
  186. .RI "QSqlError \fBlastError\fP"
  187. .br
  188. .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\&. "
  189. .in -1c
  190. .SH "Detailed Description"
  191. .PP
  192. The DB class encapsulates the SQL database by providing fast access to hot database data\&.
  193. .SH "Member Function Documentation"
  194. .PP
  195. .SS "bool OPL::Database::commit (const QJsonArray & json_arr, const \fBOPL::DbTable\fP table)"
  196. .PP
  197. 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\&.
  198. .SS "bool OPL::Database::createBackup (const QString & dest_file)"
  199. .PP
  200. \fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&.
  201. .PP
  202. \fBParameters\fP
  203. .RS 4
  204. \fIdest_file\fP This is the full path and filename of where the backup will be created, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  205. .RE
  206. .PP
  207. .SS "bool OPL::Database::createSchema ()"
  208. .PP
  209. 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\&.
  210. .SS "QVector< QVariant > OPL::Database::customQuery (QString statement, int return_values)"
  211. .PP
  212. Can be used to send a complex query to the database\&.
  213. .PP
  214. \fBParameters\fP
  215. .RS 4
  216. \fIquery\fP - the full sql query statement
  217. .br
  218. \fIreturnValues\fP - the number of return values
  219. .RE
  220. .PP
  221. .SS "QSqlDatabase OPL::Database::database ()\fC [static]\fP"
  222. .PP
  223. Can be used to access the database connection\&.
  224. .PP
  225. \fBReturns\fP
  226. .RS 4
  227. The QSqlDatabase object pertaining to the connection\&.
  228. .RE
  229. .PP
  230. .SS "QVector< RowData_T > OPL::Database::getTable (\fBOPL::DbTable\fP table)"
  231. .PP
  232. getTable returns all contents of a given table from the database
  233. .PP
  234. \fBReturns\fP
  235. .RS 4
  236. .RE
  237. .PP
  238. .SS "bool OPL::Database::importTemplateData (bool use_local_ressources)"
  239. .PP
  240. importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&.
  241. .PP
  242. \fBParameters\fP
  243. .RS 4
  244. \fIuse_local_ressources\fP determines whether the included ressource files or a previously downloaded file should be used\&.
  245. .RE
  246. .PP
  247. \fBReturns\fP
  248. .RS 4
  249. .RE
  250. .PP
  251. .SS "bool OPL::Database::restoreBackup (const QString & backup_file)"
  252. .PP
  253. \fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&.
  254. .PP
  255. \fBParameters\fP
  256. .RS 4
  257. \fIbackup_file\fP This is the full path and filename of the backup, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  258. .RE
  259. .PP
  260. .SS "const QString OPL::Database::sqliteVersion () const"
  261. .PP
  262. \fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also dbRevision()
  263. .PP
  264. \fBReturns\fP
  265. .RS 4
  266. sqlite version string
  267. .RE
  268. .PP
  269. .SH "Member Data Documentation"
  270. .PP
  271. .SS "QSqlError OPL::Database::lastError"
  272. .PP
  273. 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\&.
  274. .SH "Author"
  275. .PP
  276. Generated automatically by Doxygen for openPilotLog from the source code\&.