aDbSetup.3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. .TH "aDbSetup" 3 "Fri Mar 4 2022" "openPilotLog" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. aDbSetup \- The \fBaDbSetup\fP namespace is responsible for the inital setup of the database when the application is first launched\&. It creates the database in the specified default location and creates all required tables and views\&.
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .SS "Functions"
  10. .in +1c
  11. .ti -1c
  12. .RI "bool \fBcreateDatabase\fP ()"
  13. .br
  14. .RI "createDatabase runs a number of CREATE queries that create the database tables and columns\&. "
  15. .ti -1c
  16. .RI "bool \fBcommitData\fP (const QJsonArray &json_arr, const QString &table_name)"
  17. .br
  18. .RI "commitData commits the data read from a JSON file into a table in the database\&. "
  19. .ti -1c
  20. .RI "bool \fBimportTemplateData\fP (bool use_local_ressources)"
  21. .br
  22. .RI "importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&. "
  23. .ti -1c
  24. .RI "bool \fBresetUserData\fP ()"
  25. .br
  26. .RI "Empties all user-generated content in the database\&. "
  27. .in -1c
  28. .SS "Variables"
  29. .in +1c
  30. .ti -1c
  31. .RI "const auto \fBTEMPLATE_URL\fP = QStringLiteral('https://raw\&.githubusercontent\&.com/fiffty\-50/openpilotlog/develop/assets/database/templates/')"
  32. .br
  33. .ti -1c
  34. .RI "const auto \fBCREATE_TABLE_PILOTS\fP"
  35. .br
  36. .ti -1c
  37. .RI "const auto \fBCREATE_TABLE_TAILS\fP"
  38. .br
  39. .ti -1c
  40. .RI "const auto \fBCREATE_TABLE_FLIGHTS\fP"
  41. .br
  42. .ti -1c
  43. .RI "const auto \fBCREATE_TABLE_AIRPORTS\fP"
  44. .br
  45. .ti -1c
  46. .RI "const auto \fBCREATE_TABLE_AIRCRAFT\fP"
  47. .br
  48. .ti -1c
  49. .RI "const auto \fBCREATE_TABLE_CHANGELOG\fP"
  50. .br
  51. .ti -1c
  52. .RI "const auto \fBCREATE_TABLE_CURRENCIES\fP"
  53. .br
  54. .ti -1c
  55. .RI "const auto \fBCREATE_VIEW_DEFAULT\fP"
  56. .br
  57. .ti -1c
  58. .RI "const auto \fBCREATE_VIEW_EASA\fP"
  59. .br
  60. .ti -1c
  61. .RI "const auto \fBCREATE_VIEW_TAILS\fP"
  62. .br
  63. .ti -1c
  64. .RI "const auto \fBCREATE_VIEW_PILOTS\fP"
  65. .br
  66. .ti -1c
  67. .RI "const auto \fBCREATE_VIEW_QCOMPLETER\fP"
  68. .br
  69. .ti -1c
  70. .RI "const auto \fBCREATE_VIEW_TOTALS\fP"
  71. .br
  72. .ti -1c
  73. .RI "const QList< QLatin1String > \fBDATABASE_TABLES\fP"
  74. .br
  75. .ti -1c
  76. .RI "const QList< QLatin1String > \fBDATABASE_VIEWS\fP"
  77. .br
  78. .ti -1c
  79. .RI "const QList< QLatin1String > \fBUSER_TABLES\fP"
  80. .br
  81. .ti -1c
  82. .RI "const QList< QLatin1String > \fBTEMPLATE_TABLES\fP"
  83. .br
  84. .in -1c
  85. .SH "Detailed Description"
  86. .PP
  87. The \fBaDbSetup\fP namespace is responsible for the inital setup of the database when the application is first launched\&. It creates the database in the specified default location and creates all required tables and views\&.
  88. .SH "Function Documentation"
  89. .PP
  90. .SS "bool aDbSetup::createDatabase ()"
  91. .PP
  92. createDatabase runs a number of CREATE queries that create the database tables and columns\&.
  93. .PP
  94. \fBReturns\fP
  95. .RS 4
  96. .RE
  97. .PP
  98. .SS "bool aDbSetup::importTemplateData (bool use_local_ressources)"
  99. .PP
  100. importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates\&.
  101. .PP
  102. \fBParameters\fP
  103. .RS 4
  104. \fIuse_local_ressources\fP determines whether the included ressource files or a previously downloaded file should be used\&.
  105. .RE
  106. .PP
  107. \fBReturns\fP
  108. .RS 4
  109. .RE
  110. .PP
  111. .SS "bool aDbSetup::resetUserData ()"
  112. .PP
  113. Empties all user-generated content in the database\&.
  114. .PP
  115. \fBReturns\fP
  116. .RS 4
  117. true on success
  118. .RE
  119. .PP
  120. .SH "Variable Documentation"
  121. .PP
  122. .SS "const auto aDbSetup::CREATE_TABLE_AIRCRAFT"
  123. \fBInitial value:\fP
  124. .PP
  125. .nf
  126. = QLatin1String("CREATE TABLE aircraft ("
  127. " aircraft_id INTEGER NOT NULL,"
  128. " make TEXT,"
  129. " model TEXT,"
  130. " variant TEXT,"
  131. " name TEXT,"
  132. " iata TEXT,"
  133. " icao TEXT,"
  134. " multipilot INTEGER,"
  135. " multiengine INTEGER,"
  136. " engineType INTEGER,"
  137. " weightClass INTEGER,"
  138. " PRIMARY KEY(aircraft_id AUTOINCREMENT)"
  139. ")")
  140. .fi
  141. .SS "const auto aDbSetup::CREATE_TABLE_AIRPORTS"
  142. \fBInitial value:\fP
  143. .PP
  144. .nf
  145. = QLatin1String("CREATE TABLE airports ( "
  146. " airport_id INTEGER NOT NULL, "
  147. " icao TEXT NOT NULL, "
  148. " iata TEXT, "
  149. " name TEXT, "
  150. " lat REAL, "
  151. " long REAL, "
  152. " country TEXT, "
  153. " alt INTEGER, "
  154. " utcoffset INTEGER, "
  155. " tzolson TEXT, "
  156. " PRIMARY KEY(airport_id AUTOINCREMENT) "
  157. ")")
  158. .fi
  159. .SS "const auto aDbSetup::CREATE_TABLE_CHANGELOG"
  160. \fBInitial value:\fP
  161. .PP
  162. .nf
  163. = QLatin1String("CREATE TABLE changelog ( "
  164. " revision INTEGER NOT NULL, "
  165. " comment TEXT, "
  166. " date NUMERIC, "
  167. " PRIMARY KEY(revision) "
  168. ")")
  169. .fi
  170. .SS "const auto aDbSetup::CREATE_TABLE_CURRENCIES"
  171. \fBInitial value:\fP
  172. .PP
  173. .nf
  174. = QLatin1String("CREATE TABLE currencies ( "
  175. " currency_id INTEGER PRIMARY KEY AUTOINCREMENT, "
  176. " description TEXT, "
  177. " expiryDate NUMERIC "
  178. ")"
  179. )
  180. .fi
  181. .SS "const auto aDbSetup::CREATE_TABLE_PILOTS"
  182. \fBInitial value:\fP
  183. .PP
  184. .nf
  185. = QLatin1String("CREATE TABLE pilots ( "
  186. " pilot_id INTEGER NOT NULL, "
  187. " lastname TEXT NOT NULL, "
  188. " firstname TEXT, "
  189. " alias TEXT, "
  190. " company TEXT, "
  191. " employeeid TEXT, "
  192. " phone TEXT, "
  193. " email TEXT, "
  194. " PRIMARY KEY(pilot_id AUTOINCREMENT)"
  195. ")")
  196. .fi
  197. .SS "const auto aDbSetup::CREATE_TABLE_TAILS"
  198. \fBInitial value:\fP
  199. .PP
  200. .nf
  201. = QLatin1String("CREATE TABLE tails ("
  202. " tail_id INTEGER NOT NULL,"
  203. " registration TEXT NOT NULL,"
  204. " company TEXT,"
  205. " make TEXT,"
  206. " model TEXT,"
  207. " variant TEXT,"
  208. " multipilot INTEGER,"
  209. " multiengine INTEGER,"
  210. " engineType INTEGER,"
  211. " weightClass INTEGER,"
  212. " PRIMARY KEY(tail_id AUTOINCREMENT)"
  213. ")")
  214. .fi
  215. .SS "const auto aDbSetup::CREATE_VIEW_DEFAULT"
  216. \fBInitial value:\fP
  217. .PP
  218. .nf
  219. = QLatin1String("CREATE VIEW viewDefault AS "
  220. " SELECT flight_id, doft as 'Date', "
  221. " dept AS 'Dept', "
  222. " printf('%02d',(tofb/60))||':'||printf('%02d',(tofb%60)) AS 'Time', "
  223. " dest AS 'Dest', printf('%02d',(tonb/60))||':'||printf('%02d',(tonb%60)) AS 'Time ', "
  224. " printf('%02d',(tblk/60))||':'||printf('%02d',(tblk%60)) AS 'Total', "
  225. " CASE "
  226. " WHEN pilot_id = 1 THEN alias "
  227. " ELSE lastname||', '||substr(firstname, 1, 1)||'\&.' "
  228. " END "
  229. " AS 'Name PIC', "
  230. " CASE "
  231. " WHEN variant IS NOT NULL THEN make||' '||model||'-'||variant "
  232. " ELSE make||' '||model "
  233. " END "
  234. " AS 'Type', "
  235. " registration AS 'Registration', "
  236. " FlightNumber AS 'Flight #', "
  237. " remarks AS 'Remarks'"
  238. " FROM flights "
  239. " INNER JOIN pilots on flights\&.pic = pilots\&.pilot_id "
  240. " INNER JOIN tails on flights\&.acft = tails\&.tail_id "
  241. " ORDER BY date DESC ")
  242. .fi
  243. .SS "const auto aDbSetup::CREATE_VIEW_PILOTS"
  244. \fBInitial value:\fP
  245. .PP
  246. .nf
  247. = QLatin1String("CREATE VIEW viewPilots AS "
  248. " SELECT "
  249. " pilot_id AS 'ID', "
  250. " lastname AS 'Last Name', "
  251. " firstname AS 'First Name', "
  252. " company AS 'Company' "
  253. " FROM pilots")
  254. .fi
  255. .SS "const auto aDbSetup::CREATE_VIEW_QCOMPLETER"
  256. \fBInitial value:\fP
  257. .PP
  258. .nf
  259. = QLatin1String("CREATE VIEW viewQCompleter AS "
  260. " SELECT airport_id, icao, iata, tail_id, registration, pilot_id, "
  261. " lastname||', '||firstname AS 'pilot_name', alias "
  262. " FROM airports "
  263. " LEFT JOIN tails ON airports\&.airport_id = tails\&.tail_id "
  264. " LEFT JOIN pilots ON airports\&.airport_id = pilots\&.pilot_id")
  265. .fi
  266. .SS "const auto aDbSetup::CREATE_VIEW_TAILS"
  267. \fBInitial value:\fP
  268. .PP
  269. .nf
  270. = QLatin1String("CREATE VIEW viewTails AS "
  271. " SELECT "
  272. " tail_id AS 'ID', "
  273. " registration AS 'Registration', "
  274. " make||' '||model AS 'Type', "
  275. " company AS 'Company' "
  276. " FROM tails WHERE model IS NOT NULL AND variant IS NULL "
  277. " UNION "
  278. " SELECT "
  279. " tail_id AS 'ID', "
  280. " registration AS 'Registration', "
  281. " make||' '||model||'-'||variant AS 'Type', "
  282. " company AS 'Company' "
  283. " FROM tails WHERE variant IS NOT NULL")
  284. .fi
  285. .SS "const auto aDbSetup::CREATE_VIEW_TOTALS"
  286. \fBInitial value:\fP
  287. .PP
  288. .nf
  289. = QLatin1String("CREATE VIEW viewTotals AS "
  290. " SELECT "
  291. " printf(\"%02d\",CAST(SUM(tblk) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tblk) AS INT)%60) AS \"TOTAL\", "
  292. " printf(\"%02d\",CAST(SUM(tSPSE) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tSPSE) AS INT)%60) AS \"SP SE\", "
  293. " printf(\"%02d\",CAST(SUM(tSPME) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tSPME) AS INT)%60) AS \"SP ME\", "
  294. " printf(\"%02d\",CAST(SUM(tNIGHT) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tNIGHT) AS INT)%60) AS \"NIGHT\", "
  295. " printf(\"%02d\",CAST(SUM(tIFR) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tIFR) AS INT)%60) AS \"IFR\", "
  296. " printf(\"%02d\",CAST(SUM(tPIC) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tPIC) AS INT)%60) AS \"PIC\", "
  297. " printf(\"%02d\",CAST(SUM(tPICUS) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tPICUS) AS INT)%60) AS \"PICUS\", "
  298. " printf(\"%02d\",CAST(SUM(tSIC) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tSIC) AS INT)%60) AS \"SIC\", "
  299. " printf(\"%02d\",CAST(SUM(tDual) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tDual) AS INT)%60) AS \"DUAL\", "
  300. " printf(\"%02d\",CAST(SUM(tFI) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tFI) AS INT)%60) AS \"INSTRUCTOR\", "
  301. " printf(\"%02d\",CAST(SUM(tSIM) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tSIM) AS INT)%60) AS \"SIMULATOR\", "
  302. " printf(\"%02d\",CAST(SUM(tMP) AS INT)/60)||\":\"||printf(\"%02d\",CAST(SUM(tMP) AS INT)%60) AS \"MultPilot\", "
  303. " CAST(SUM(toDay) AS INT) AS \"TO Day\", CAST(SUM(toNight) AS INT) AS \"TO Night\", "
  304. " CAST(SUM(ldgDay) AS INT) AS \"LDG Day\", CAST(SUM(ldgNight) AS INT) AS \"LDG Night\" "
  305. " FROM flights")
  306. .fi
  307. .SS "const QList<QLatin1String> aDbSetup::DATABASE_TABLES"
  308. \fBInitial value:\fP
  309. .PP
  310. .nf
  311. = {
  312. CREATE_TABLE_PILOTS,
  313. CREATE_TABLE_TAILS,
  314. CREATE_TABLE_FLIGHTS,
  315. CREATE_TABLE_AIRCRAFT,
  316. CREATE_TABLE_AIRPORTS,
  317. CREATE_TABLE_CURRENCIES,
  318. CREATE_TABLE_CHANGELOG
  319. }
  320. .fi
  321. .SS "const QList<QLatin1String> aDbSetup::DATABASE_VIEWS"
  322. \fBInitial value:\fP
  323. .PP
  324. .nf
  325. = {
  326. CREATE_VIEW_DEFAULT,
  327. CREATE_VIEW_EASA,
  328. CREATE_VIEW_TAILS,
  329. CREATE_VIEW_PILOTS,
  330. CREATE_VIEW_TOTALS,
  331. CREATE_VIEW_QCOMPLETER,
  332. }
  333. .fi
  334. .SS "const QList<QLatin1String> aDbSetup::TEMPLATE_TABLES"
  335. \fBInitial value:\fP
  336. .PP
  337. .nf
  338. = {
  339. QLatin1String("aircraft"),
  340. QLatin1String("airports"),
  341. QLatin1String("currencies"),
  342. QLatin1String("changelog")
  343. }
  344. .fi
  345. .SS "const QList<QLatin1String> aDbSetup::USER_TABLES"
  346. \fBInitial value:\fP
  347. .PP
  348. .nf
  349. = {
  350. QLatin1String("flights"),
  351. QLatin1String("pilots"),
  352. QLatin1String("tails")
  353. }
  354. .fi
  355. .SH "Author"
  356. .PP
  357. Generated automatically by Doxygen for openPilotLog from the source code\&.