Browse Source

Merge pull request #66 from fiffty-50/develop-issue-65

Edited DB views to fix issue #65
Felix Turowsky 4 years ago
parent
commit
66aef59672

+ 6 - 5
assets/database/README.md

@@ -1,11 +1,12 @@
-This is merely a copy of the database.
+# Sample Database
+
+This is a sample databes filled with data for testing and debugging the application.
 
 In order to use it with the application, it needs to be put in the
-data folder in the application directory, i.e. the folder the application
-is executed in.
+[data location](https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum) of your device, for example:
+
+`~/.local/share/opl/openPilotLog` or `C:/Users/<USER>/AppData/Local/opl`
 
 # Changelog
 
 When making changes to the database layout, schemas or pragmas make a comment in the changelog table detailing the changes you have made.
-
-Current Revision: 12

BIN
assets/database/logbook.db


+ 2 - 1
assets/database/templates/changelog.csv

@@ -13,4 +13,5 @@ revision,comment,date
 12,reworked views to display self or picname according CASE,2020-12-11
 13,Reworked viewEASA to incorporate NULL handling,2020-12-17
 14,Edited tails and aircraft tables - engineClass and weightClass instead of columns for each element,2020-12-19
-15,Renamed some columns to have consistent naming.,2020-12-26
+15,Renamed some columns to have consistent naming,2020-12-26
+16,Added CASE for views to account for occasions where aircraft variant is NULL,2021-02-03

+ 23 - 16
mainwindow.cpp

@@ -72,22 +72,20 @@ MainWindow::MainWindow(QWidget *parent)
     ui->stackedWidget->addWidget(debugWidget);
     ui->stackedWidget->setCurrentWidget(debugWidget);
 
-    //// START DEBUG ////
-    /// [F] I understand how it is annoying to not have the database
-    /// working when something has changed. Hopefully this check
-    /// helps to avoid that in the future! 
-    #if DATABASE < 15
-    DEB << "Your database is up to date with the latest revision.";
-    #else
-    DEB << "##########################################";
-    DEB << "Your database is out of date.";
-    DEB << "Current Revision:  " << DATABASE_REVISION_NUMBER;
-    DEB << "You have revision: " << query.value(0).toInt();
-    DEB << "Use of DebugWidget to udpate recommended.";
-    DEB << "##########################################";
-    #endif
-    //// END DEBUG ////
-
+    // check database version (Debug)
+    int db_ver = checkDbVersion();
+    if (db_ver != DATABASE_REVISION) {
+        DEB << "############## WARNING ####################";
+        DEB << "Your database is out of date.";
+        DEB << "Current Revision:\t" << DATABASE_REVISION;
+        DEB << "You have revision:\t" << db_ver;
+        DEB << "############## WARNING ###################";
+        QMessageBox message_box(this); //error box
+        message_box.setText(tr("Database revision out of date!"));
+        message_box.exec();
+    } else {
+        DEB << "Your database is up to date with the latest revision:" << db_ver;
+    }
 }
 
 MainWindow::~MainWindow()
@@ -182,3 +180,12 @@ void MainWindow::on_actionNewPilot_triggered()
     NewPilotDialog np(this);
     np.exec();
 }
+
+// Debug
+
+int MainWindow::checkDbVersion()
+{
+    QSqlQuery query("SELECT COUNT(*) FROM changelog");
+    query.next();
+    return query.value(0).toInt();
+}

+ 1 - 0
mainwindow.h

@@ -95,5 +95,6 @@ private:
 
     void readSettings();
 
+    int checkDbVersion();
 };
 #endif // MAINWINDOW_H

+ 0 - 1
src/database/adatabase.h

@@ -39,7 +39,6 @@
 #include "src/classes/aflightentry.h"
 #include "src/classes/astandardpaths.h"
 
-#define DATABASE_VERSION 15
 #define SQLITE_DRIVER QStringLiteral("QSQLITE")
 
 /*!

+ 10 - 4
src/database/adatabasesetup.cpp

@@ -24,8 +24,6 @@
 #include "src/oplconstants.h"
 #include "src/functions/adatetime.h"
 
-// Statements for creation of database tables, Revision 15
-
 const auto createTablePilots = QStringLiteral("CREATE TABLE pilots ( "
             " pilot_id       INTEGER NOT NULL, "
             " lastname       TEXT    NOT NULL, "
@@ -137,7 +135,11 @@ const auto createViewDefault = QStringLiteral("CREATE VIEW viewDefault AS "
         " ELSE lastname||', '||substr(firstname, 1, 1)||'.' "
         " END "
         " AS 'Name PIC', "
-        " make||' '||model||'-'||variant AS 'Type', "
+        " CASE "
+        " WHEN variant IS NOT NULL THEN make||' '||model||'-'||variant "
+        " ELSE make||' '||model "
+        " END "
+        " AS 'Type', "
         " registration AS 'Registration', "
         " FlightNumber AS 'Flight #', "
         " remarks AS 'Remarks'"
@@ -152,7 +154,11 @@ const auto createViewEASA = QStringLiteral("CREATE VIEW viewEASA AS "
         " dept AS 'Dept', "
         " printf('%02d',(tofb/60))||':'||printf('%02d',(tofb%60)) AS 'Time', "
         " dest AS 'Dest', printf('%02d',(tonb/60))||':'||printf('%02d',(tonb%60)) AS 'Time ', "
-        " make||' '||model||'-'||variant AS 'Type', "
+        " CASE "
+        " WHEN variant IS NOT NULL THEN make||' '||model||'-'||variant "
+        " ELSE make||' '||model "
+        " END "
+        " AS 'Type', "
         " registration AS 'Registration', "
         " (SELECT printf('%02d',(tSPSE/60))||':'||printf('%02d',(tSPSE%60)) WHERE tSPSE IS NOT NULL) AS 'SP SE', "
         " (SELECT printf('%02d',(tSPME/60))||':'||printf('%02d',(tSPME%60)) WHERE tSPME IS NOT NULL) AS 'SP ME', "

+ 2 - 0
src/database/adatabasesetup.h

@@ -22,6 +22,8 @@
 #include <QStringBuilder>
 #include <QEventLoop>
 
+#define DATABASE_REVISION 16
+
 const auto TEMPLATE_URL = QStringLiteral("https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/");
 
 /*!