OPL_Database.3 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. .TH "OPL::Database" 3 "Mon Jul 11 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 ()"
  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 "const QString \fBversion\fP () const"
  34. .br
  35. .RI "Return the database revision number (not the sqlite version number)\&. "
  36. .ti -1c
  37. .RI "const QString \fBsqliteVersion\fP () const"
  38. .br
  39. .RI "\fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also dbRevision() "
  40. .ti -1c
  41. .RI "const QStringList \fBgetTableNames\fP () const"
  42. .br
  43. .RI "Return the names of all tables in the database\&. "
  44. .ti -1c
  45. .RI "const QStringList \fBgetTableColumns\fP (\fBOPL::DbTable\fP table_name) const"
  46. .br
  47. .RI "Return the names of a given table in the database\&. "
  48. .ti -1c
  49. .RI "void \fBupdateLayout\fP ()"
  50. .br
  51. .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\&. "
  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 \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\&. "
  108. .ti -1c
  109. .RI "\fBOPL::TailEntry\fP \fBgetTailEntry\fP (int row_id)"
  110. .br
  111. .RI "retreives a \fBTailEntry\fP from the database\&. "
  112. .ti -1c
  113. .RI "\fBOPL::AircraftEntry\fP \fBgetAircraftEntry\fP (int row_id)"
  114. .br
  115. .RI "retreives a \fBTailEntry\fP from the database\&. "
  116. .ti -1c
  117. .RI "\fBOPL::FlightEntry\fP \fBgetFlightEntry\fP (int row_id)"
  118. .br
  119. .RI "retreives a flight entry from the database\&. "
  120. .ti -1c
  121. .RI "\fBOPL::SimulatorEntry\fP \fBgetSimEntry\fP (int row_id)"
  122. .br
  123. .RI "retreives a Simulator entry from the database\&. "
  124. .ti -1c
  125. .RI "\fBOPL::CurrencyEntry\fP \fBgetCurrencyEntry\fP (int row_id)"
  126. .br
  127. .RI "Retreives a currency entry from the database\&. "
  128. .ti -1c
  129. .RI "int \fBgetLastEntry\fP (\fBOPL::DbTable\fP table)"
  130. .br
  131. .RI "returns the ROWID for the newest entry in the respective database\&. "
  132. .ti -1c
  133. .RI "QList< int > \fBgetForeignKeyConstraints\fP (int foreign_row_id, \fBOPL::DbTable\fP table)"
  134. .br
  135. .RI "returns a list of ROWID's in the flights table for which foreign key constraints exist\&. "
  136. .ti -1c
  137. .RI "bool \fBrestoreBackup\fP (const QString &backup_file)"
  138. .br
  139. .RI "\fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&. "
  140. .ti -1c
  141. .RI "bool \fBcreateBackup\fP (const QString &dest_file)"
  142. .br
  143. .RI "\fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&. "
  144. .ti -1c
  145. .RI "QVector< RowData_T > \fBgetTable\fP (\fBOPL::DbTable\fP table)"
  146. .br
  147. .RI "getTable returns all contents of a given table from the database "
  148. .ti -1c
  149. .RI "const QList< \fBOPL::DbTable\fP > & \fBgetUserTables\fP () const"
  150. .br
  151. .RI "getUserTables returns a list of the of the tables that contain user-created data (flights, pilots,\&.\&.) "
  152. .ti -1c
  153. .RI "const QList< \fBOPL::DbTable\fP > & \fBgetTemplateTables\fP () const"
  154. .br
  155. .RI "getTemplateTables returns a list of the tables that contain template data (aiports, aircraft,\&.\&.) "
  156. .ti -1c
  157. .RI "const \fBUserDataState\fP \fBgetUserDataState\fP () const"
  158. .br
  159. .RI "getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&. "
  160. .ti -1c
  161. .RI "bool \fBcreateSchema\fP ()"
  162. .br
  163. .RI "Create or restore the database to its ready-to-use but empty state\&. "
  164. .ti -1c
  165. .RI "bool \fBimportTemplateData\fP (bool use_local_ressources)"
  166. .br
  167. .RI "importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&. "
  168. .ti -1c
  169. .RI "bool \fBresetUserData\fP ()"
  170. .br
  171. .RI "Delete all rows from the user data tables (flights, pliots, tails) "
  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. .ti -1c
  190. .RI "const QFileInfo \fBdatabaseFile\fP"
  191. .br
  192. .in -1c
  193. .SH "Detailed Description"
  194. .PP
  195. The DB class encapsulates the SQL database by providing fast access to hot database data\&.
  196. .SH "Member Function Documentation"
  197. .PP
  198. .SS "bool OPL::Database::commit (const QJsonArray & json_arr, const \fBOPL::DbTable\fP table)"
  199. .PP
  200. 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\&.
  201. .SS "bool OPL::Database::createBackup (const QString & dest_file)"
  202. .PP
  203. \fBDatabase::createBackup\fP copies the currently used database to an external backup location provided by the user\&.
  204. .PP
  205. \fBParameters\fP
  206. .RS 4
  207. \fIdest_file\fP This is the full path and filename of where the backup will be created, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  208. .RE
  209. .PP
  210. .SS "bool OPL::Database::createSchema ()"
  211. .PP
  212. 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\&.
  213. .SS "QVector< QVariant > OPL::Database::customQuery (QString statement, int return_values)"
  214. .PP
  215. Can be used to send a complex query to the database\&.
  216. .PP
  217. \fBParameters\fP
  218. .RS 4
  219. \fIquery\fP - the full sql query statement
  220. .br
  221. \fIreturnValues\fP - the number of return values
  222. .RE
  223. .PP
  224. .SS "QSqlDatabase OPL::Database::database ()\fC [static]\fP"
  225. .PP
  226. Can be used to access the database connection\&.
  227. .PP
  228. \fBReturns\fP
  229. .RS 4
  230. The QSqlDatabase object pertaining to the connection\&.
  231. .RE
  232. .PP
  233. .SS "\fBOPL::AircraftEntry\fP OPL::Database::getAircraftEntry (int row_id)\fC [inline]\fP"
  234. .PP
  235. retreives a \fBTailEntry\fP from the database\&. This function is a wrapper for DataBase::getRowData, where the table is already set and which returns an \fBAAircraftEntry\fP instead of an AEntry\&. It allows for easy access to an aircraft entry with only the RowId required as input\&.
  236. .SS "\fBOPL::FlightEntry\fP OPL::Database::getFlightEntry (int row_id)\fC [inline]\fP"
  237. .PP
  238. retreives a flight entry from the database\&. This function is a wrapper for DataBase::getRowData, where the table is already set and which returns an AFlightEntry instead of an AEntry\&. It allows for easy access to a flight entry with only the RowId required as input\&.
  239. .SS "\fBOPL::PilotEntry\fP OPL::Database::getPilotEntry (int row_id)\fC [inline]\fP"
  240. .PP
  241. retreives a \fBPilotEntry\fP from the database\&. This function is a wrapper for DataBase::getRowData, where the table is already set and which returns a \fBPilotEntry\fP instead of an Entry\&. It allows for easy access to a pilot entry with only the RowId required as input\&.
  242. .SS "\fBOPL::SimulatorEntry\fP OPL::Database::getSimEntry (int row_id)\fC [inline]\fP"
  243. .PP
  244. retreives a Simulator entry from the database\&. This function is a wrapper for DataBase::getRowData, where the table is already set and which returns an ASimEntry instead of an AEntry\&. It allows for easy access to a Simulator entry with only the RowId required as input\&.
  245. .SS "QVector< RowData_T > OPL::Database::getTable (\fBOPL::DbTable\fP table)"
  246. .PP
  247. getTable returns all contents of a given table from the database
  248. .PP
  249. \fBReturns\fP
  250. .RS 4
  251. .RE
  252. .PP
  253. .SS "\fBOPL::TailEntry\fP OPL::Database::getTailEntry (int row_id)\fC [inline]\fP"
  254. .PP
  255. retreives a \fBTailEntry\fP from the database\&. This function is a wrapper for DataBase::getRowData, where the table is already set and which returns a \fBTailEntry\fP instead of an Entry\&. It allows for easy access to a tail entry with only the RowId required as input\&.
  256. .SS "const \fBUserDataState\fP OPL::Database::getUserDataState () const"
  257. .PP
  258. getUserDataState returns a struct containing the current amount of entries in the tails and pilots tables\&.
  259. .PP
  260. \fBReturns\fP
  261. .RS 4
  262. .RE
  263. .PP
  264. .SS "bool OPL::Database::importTemplateData (bool use_local_ressources)"
  265. .PP
  266. importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&.
  267. .PP
  268. \fBParameters\fP
  269. .RS 4
  270. \fIuse_local_ressources\fP determines whether the included ressource files or a previously downloaded file should be used\&.
  271. .RE
  272. .PP
  273. \fBReturns\fP
  274. .RS 4
  275. .RE
  276. .PP
  277. .SS "bool OPL::Database::restoreBackup (const QString & backup_file)"
  278. .PP
  279. \fBDatabase::restoreBackup\fP restores the database from a given backup file and replaces the currently active database\&.
  280. .PP
  281. \fBParameters\fP
  282. .RS 4
  283. \fIbackup_file\fP This is the full path and filename of the backup, e\&.g\&. 'home/Sully/myBackups/backupFromOpl\&.db'
  284. .RE
  285. .PP
  286. .SS "const QString OPL::Database::sqliteVersion () const"
  287. .PP
  288. \fBDatabase::sqliteVersion\fP returns the database sqlite version\&. See also dbRevision()
  289. .PP
  290. \fBReturns\fP
  291. .RS 4
  292. sqlite version string
  293. .RE
  294. .PP
  295. .SH "Member Data Documentation"
  296. .PP
  297. .SS "QSqlError OPL::Database::lastError"
  298. .PP
  299. 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\&.
  300. .SH "Author"
  301. .PP
  302. Generated automatically by Doxygen for openPilotLog from the source code\&.