2
0

aDbSetup.3 10 KB

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