Browse Source

Removed deprecated code

Removed: 
aircraft.h / aircraft.cpp
pilot.h / pilot.cpp
flight.h / flight.cpp
entry_deprecated.h / entry_deprecated.cpp
db.h / db.cpp
dbinfo.h / dbinfo.cpp

Tweaks in entry and database classes to prepare removal of namespace experimental and prefer use of QStringLiterals where possible.
Also changed some entry logic to better seperate database logic from entry data.
Felix 4 years ago
parent
commit
223227f473

+ 1 - 1
mainwindow.cpp

@@ -173,6 +173,6 @@ void MainWindow::on_actionNewAircraft_triggered()
 
 void MainWindow::on_actionNewPilot_triggered()
 {
-    NewPilotDialog np = NewPilotDialog(Db::createNew, this);
+    NewPilotDialog np = NewPilotDialog(this);
     np.exec();
 }

+ 0 - 14
openPilotLog.pro

@@ -19,16 +19,9 @@ SOURCES += \
     main.cpp \
     mainwindow.cpp \
     src/classes/adownload.cpp \
-    src/classes/aircraft.cpp \
     src/classes/arunguard.cpp \
     src/classes/asettings.cpp \
-    src/classes/astrictrxvalidator.cpp \
-    src/classes/flight.cpp \
-    src/classes/pilot.cpp \
     src/database/adatabasesetup.cpp \
-    src/database/db.cpp \
-    src/database/dbinfo.cpp \
-    src/database/entry_deprecated.cpp \
     src/experimental/aaircraftentry.cpp \
     src/experimental/adatabase.cpp \
     src/experimental/aentry.cpp \
@@ -55,16 +48,9 @@ SOURCES += \
 HEADERS += \
     mainwindow.h \
     src/classes/adownload.h \
-    src/classes/aircraft.h \
     src/classes/arunguard.h \
     src/classes/asettings.h \
-    src/classes/astrictrxvalidator.h \
-    src/classes/flight.h \
-    src/classes/pilot.h \
     src/database/adatabasesetup.h \
-    src/database/db.h \
-    src/database/dbinfo.h \
-    src/database/entry_deprecated.h \
     src/database/tablecolumnliterals.h \
     src/experimental/UserInput.h \
     src/experimental/aaircraftentry.h \

+ 0 - 86
src/classes/aircraft.cpp

@@ -1,86 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "aircraft.h"
-#include "src/testing/adebug.h"
-
-
-Aircraft::Aircraft()
-{
-
-}
-
-Aircraft::Aircraft(int tail_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    auto table = QLatin1String("tails");
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << tail_id );
-        position.second = 0;
-    } else {
-        //DEB("Retreiving data for row id: " << tail_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = tail_id;
-            position.first = "tails";
-        }
-    }
-}
-
-Aircraft::Aircraft(QMap<QString, QString> newData)
-{
-    QString table = "tails";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 36
src/classes/aircraft.h

@@ -1,36 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef AIRCRAFT_H
-#define AIRCRAFT_H
-#include <QCoreApplication>
-#include "src/database/entry_deprecated.h"
-
-/*!
- * \brief The aircraft class
- *
- */
-class Aircraft : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Aircraft();
-    Aircraft(int tail_id);
-    Aircraft(QMap<QString, QString> newData);
-};
-
-#endif // AIRCRAFT_H

+ 0 - 27
src/classes/astrictrxvalidator.cpp

@@ -1,27 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "astrictrxvalidator.h"
-
-QValidator::State AStrictRxValidator::validate(QString &txt, int &pos) const
-{
-    auto validation = QRegularExpressionValidator::validate(txt, pos);
-    if (validation == QValidator::Intermediate) {
-        return QValidator::Invalid;
-    }
-    return validation;
-}

+ 0 - 34
src/classes/astrictrxvalidator.h

@@ -1,34 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef STRICTRXVALIDATOR_H
-#define STRICTRXVALIDATOR_H
-
-#include <QRegularExpression>
-#include <QValidator>
-
-/*!
- * \brief The AStrictRxValidator class only returns Invalid or Acceptable
- */
-class AStrictRxValidator : public QRegularExpressionValidator
-{
-    using QRegularExpressionValidator::QRegularExpressionValidator;
-public:
-    QValidator::State validate(QString &txt, int &pos) const;
-};
-
-#endif

+ 0 - 88
src/classes/flight.cpp

@@ -1,88 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "flight.h"
-#include "src/testing/adebug.h"
-
-Flight::Flight()
-{
-
-}
-
-Flight::Flight(int flight_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    auto table = QLatin1String("flights");
-
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(flight_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << flight_id );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << flight_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(flight_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = flight_id;
-            position.first = "flights";
-        }
-    }
-}
-
-Flight::Flight(QMap<QString, QString> newData)
-{
-    QString table = "flights";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 36
src/classes/flight.h

@@ -1,36 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef FLIGHT_H
-#define FLIGHT_H
-
-#include <QCoreApplication>
-#include <QDateTime>
-#include <QDebug>
-#include "src/database/entry_deprecated.h"
-
-
-class Flight : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Flight();
-    Flight(int flight_id);
-    Flight(QMap<QString, QString> newData);
-};
-
-#endif // FLIGHT_H

+ 0 - 88
src/classes/pilot.cpp

@@ -1,88 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "pilot.h"
-#include "src/testing/adebug.h"
-
-
-
-Pilot::Pilot()
-{
-
-}
-
-Pilot::Pilot(int pilot_id)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    auto table = QLatin1String("pilots");
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(pilot_id);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << pilot_id );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << pilot_id);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(pilot_id);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-            position.first = "invalid";
-        } else {
-            position.second = pilot_id;
-            position.first = "pilots";
-        }
-    }
-}
-
-Pilot::Pilot(QMap<QString, QString> newData)
-{
-    QString table = "pilots";
-
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(table);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-    position.first = table;
-    position.second = 0;
-}

+ 0 - 32
src/classes/pilot.h

@@ -1,32 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef PILOT_H
-#define PILOT_H
-#include "src/database/entry_deprecated.h"
-
-
-class Pilot : public Entry_deprecated
-{
-//    using Entry::Entry;
-public:
-    Pilot();
-    Pilot(int pilot_id);
-    Pilot(QMap<QString, QString> newData);
-};
-
-#endif // PILOT_H

+ 9 - 4
src/database/adatabasesetup.cpp

@@ -19,7 +19,7 @@
 #include "src/testing/adebug.h"
 
 
-// Statements for creation of database tables, Revision 13
+// Statements for creation of database tables, Revision 15
 
 const QString createTablePilots = "CREATE TABLE pilots ( "
             " pilot_id       INTEGER NOT NULL, "
@@ -257,6 +257,7 @@ const QStringList templateTables= {
 
 bool ADataBaseSetup::createDatabase()
 {
+
     DEB("Creating tables...");
     if (!createSchemata(tables)) {
         DEB("Creating tables has failed.");
@@ -269,6 +270,9 @@ bool ADataBaseSetup::createDatabase()
         return false;
     }
 
+    // call connect again to (re-)populate tableNames and columnNames
+    experimental::aDB()->connect();
+
     DEB("Populating tables...");
     if (!importDefaultData()) {
         DEB("Populating tables failed.");
@@ -352,6 +356,7 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
         query.exec();
         if(!query.isActive()) {
             errors << statement.section(QLatin1Char(' '),2,2) + " ERROR - " + query.lastError().text();
+            DEB("Query: " << query.lastQuery());
         } else {
             DEB("Schema added: " << statement.section(QLatin1Char(' '),2,2));
         }
@@ -378,9 +383,9 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
  */
 bool ADataBaseSetup::commitData(QVector<QStringList> fromCSV, const QString &tableName)
 {
+    DEB("Table names: " << experimental::aDB()->getTableNames());
     DEB("Importing Data to" << tableName);
-    auto dbLayout = DbInfo();
-    if (!dbLayout.tables.contains(tableName)){
+    if (!experimental::aDB()->getTableNames().contains(tableName)){
         DEB(tableName << "is not a table in the database. Aborting.");
         DEB("Please check input data.");
         return false;
@@ -389,7 +394,7 @@ bool ADataBaseSetup::commitData(QVector<QStringList> fromCSV, const QString &tab
     QString statement = "INSERT INTO " + tableName + " (";
     QString placeholder = ") VALUES (";
     for (auto& csvColumn : fromCSV) {
-        if(dbLayout.format.value(tableName).contains(csvColumn.first())){
+        if(experimental::aDB()->getTableColumns().value(tableName).contains(csvColumn.first())) {
             statement += csvColumn.first() + ',';
             csvColumn.removeFirst();
             placeholder.append("?,");

+ 1 - 2
src/database/adatabasesetup.h

@@ -19,8 +19,7 @@
 #define DBSETUP_H
 
 #include <QCoreApplication>
-#include "src/database/db.h"
-#include "src/database/dbinfo.h"
+#include "src/experimental/adatabase.h"
 #include "src/functions/areadcsv.h"
 
 /*!

+ 0 - 276
src/database/db.cpp

@@ -1,276 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "db.h"
-#include "dbinfo.h"
-#include "src/testing/adebug.h"
-
-/*!
- * \brief Db::iconnect - see Db::connect
- */
-void Db::iconnect()
-{
-    const QString driver("QSQLITE");
-
-    if (QSqlDatabase::isDriverAvailable(driver)) {
-
-        QDir directory("data");
-        QString databaseLocation = directory.filePath("logbook.db");
-        QSqlDatabase db = QSqlDatabase::addDatabase(driver);
-        db.setDatabaseName(databaseLocation);
-
-        if (!db.open()) {
-            DEB("DatabaseConnect - ERROR: " << db.lastError().text());
-        } else {
-            DEB("Database connection established.");
-            //Enable foreign key restrictions
-            QSqlQuery query("PRAGMA foreign_keys = ON;");
-        }
-    } else {
-        DEB("DatabaseConnect - ERROR: no driver " << driver << " available");
-    }
-}
-
-void Db::idisconnect()
-{
-    auto db = Db::Database();
-    db.close();
-    db.removeDatabase(db.connectionName());
-    DEB("Database connection closed.");
-}
-
-QSqlDatabase Db::iDatabase()
-{
-    auto db = QSqlDatabase::database("qt_sql_default_connection");
-    return db;
-}
-/*!
- * \brief Db::iexists - see Db::exists
- */
-bool Db::iexists(QString column, QString table, QString checkColumn, QString value,
-                Db::matchType match)
-{
-    bool output = false;
-    QString statement = "SELECT " + column + " FROM " + table + " WHERE " + checkColumn;
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-    } else {
-        output = true;
-        if (q.next()) {
-            DEB("More than one result in Database for your query");
-        }
-    }
-// Debug:
-    q.first();
-    q.previous();
-    while (q.next()) {
-        DEB("Query result: " << q.value(0).toString());
-    }
-// end of Debug
-    return output;
-}
-
-/*!
- * \brief Db::isingleSelect - see Db::singleSelect
- */
-QString Db::isingleSelect(QString column, QString table, QString checkColumn, QString value,
-                         Db::matchType match)
-{
-    QString statement = "SELECT " + column + " FROM " + table + " WHERE " + checkColumn;
-    QString result;
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QString();
-    } else {
-        result.append(q.value(0).toString());
-        if (q.next()) {
-            DEB("More than one result in Database for your query");
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::imultiSelect - see Db::multiSelect
- */
-QVector<QString> Db::imultiSelect(QVector<QString> columns, QString table, QString checkColumn,
-                                 QString value, Db::matchType match)
-{
-    QString statement = "SELECT ";
-    for (const auto &column : columns) {
-        statement.append(column);
-        if (column != columns.last()) {
-            statement.append(QLatin1String(", "));
-        }
-    }
-    statement.append(" FROM " + table + " WHERE " + checkColumn);
-
-    switch (match) {
-    case Db::exactMatch:
-        statement += " = '" + value + QLatin1Char('\'');
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(" LIKE '" + value + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < columns.size() ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::imultiSelect - see Db::multiSelect
- */
-QVector<QString> Db::imultiSelect(QVector<QString> columns, QString table)
-{
-    QString statement = "SELECT ";
-    for (const auto &column : columns) {
-        statement.append(column);
-        if (column != columns.last()) {
-            statement.append(QLatin1String(", "));
-        }
-    }
-    statement.append(" FROM " + table);
-
-    QSqlQuery q(statement);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < columns.size() ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}
-
-/*!
- * \brief Db::isingleUpdate - see Db::singleUpdate
- */
-bool Db::isingleUpdate(QString table, QString column, QString value, QString checkColumn,
-                      QString checkvalue, Db::matchType match)
-{
-    QString statement = "UPDATE " + table;
-    statement.append(QLatin1String(" SET ") + column + QLatin1String(" = '") + value);
-    statement.append(QLatin1String("' WHERE "));
-
-    switch (match) {
-    case Db::exactMatch:
-        statement.append(checkColumn + " = '" + checkvalue + QLatin1Char('\''));
-        break;
-    case Db::partialMatch:
-        value.append(QLatin1Char('%'));
-        value.prepend(QLatin1Char('%'));
-        statement.append(checkColumn + " LIKE '" + checkvalue + QLatin1Char('\''));
-        break;
-    }
-
-    QSqlQuery q(statement);
-    q.exec();
-    QString error = q.lastError().text();
-
-    if (error.length() > 1) {
-        DEB("Errors have occured: " << error);
-        return false;
-    } else {
-        DEB("Success!");
-        return true;
-    }
-}
-/*!
- * \brief Db::icustomQuery - see Db::customQuery
- */
-QVector<QString> Db::icustomQuery(QString query, int returnValues)
-{
-    QSqlQuery q(query);
-    q.exec();
-
-    if (!q.first()) {
-        DEB("No result found. Check Query and Error.");
-        DEB("Error: " << q.lastError().text());
-        return QVector<QString>();
-    } else {
-        q.first();
-        q.previous();
-        QVector<QString> result;
-        while (q.next()) {
-            for (int i = 0; i < returnValues ; i++) {
-                result.append(q.value(i).toString());
-            }
-        }
-        return result;
-    }
-}

+ 0 - 169
src/database/db.h

@@ -1,169 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef DB_H
-#define DB_H
-
-#include <QCoreApplication>
-#include <QSqlDatabase>
-#include <QSqlDriver>
-#include <QSqlError>
-#include <QSqlQuery>
-#include <QSqlRecord>
-#include <QSqlField>
-#include <QDir>
-#include <QDebug>
-
-/*!
- * \brief The Db class provides a basic API for accessing the database programatically.
- * It is used to set up the initial connection and various basic queries can be
- * executed using a set of static functions. When interfacing with the database
- * for the purpose of adding, deleting or updating entries, the use of the entry class
- * and its subclasses is recommended. This clas is not supposed to be instantiated,
- * if you need a database object, use QSqlDatabase::database("qt_sql_default_connection");
- */
-class Db
-{
-    public:
-        static Db& get()
-        {
-            static Db instance;
-
-            return instance;
-        }
-        /*!
-         * \brief The editRole enum {createNew, editExisting} is used to differentiate
-         * between creating a new entry in the database vs editing an existing one
-         */
-        enum editRole {createNew, editExisting};
-        /*!
-         * \brief The matchType enum {exactMatch, partialMatch} is used to determine the
-         * matching when using a WHERE sql statement. exactMatch results in a "=" operator,
-         * whereas partiasMatch results in a "LIKE" operator
-         */
-        enum matchType {exactMatch, partialMatch};       
-        /*!
-         * \brief connect establishes the database connection. Only needs to be called once
-         * within the application. Database is available thereafter, objects can be
-         * instantiated with QSqlDatabase::database("qt_sql_default_connection") as required.
-         */
-        static void             connect(){get().iconnect();}
-        /*!
-         * \brief disconnect Closes and removes the default database connection.
-         */
-        static void             disconnect(){get().idisconnect();}
-
-        /*!
-         * \brief Can be used to access the database connection.
-         * \return a pointer to the default database connection
-         */
-        static QSqlDatabase     Database(){return get().iDatabase();}
-
-        /*!
-         * \brief Db::exists checks if a certain value exists in the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param column - Name of the column
-         * \param value - The value to be checked
-         * \return
-         */
-        static bool             exists(QString column, QString table, QString checkColumn,
-                                       QString value, Db::matchType match)
-        {
-            return get().iexists(column, table, checkColumn, value, match);
-        }
-        /*!
-         * \brief Db::singleUpdate Updates a single value in the database.
-         * Query format: UPDATE table SET column = value WHERE checkcolumn =/LIKE checkvalue
-         * \param table Name of the table to be updated
-         * \param column Name of the column to be updated
-         * \param checkColumn Name of the column for WHERE statement
-         * \param value The value to be set
-         * \param checkvalue The value for the WHERE statement
-         * \param match enum Db::exactMatch or Db::partialMatch
-         * \return true on success, otherwise error messages in debug out
-         */
-        static bool             singleUpdate(QString table, QString column, QString value,
-                                             QString checkColumn, QString checkvalue, Db::matchType match){
-            return get().isingleUpdate(table,column,value,checkColumn,checkvalue,match);
-        }
-        /*!
-         * \brief singleSelect Returns a single value from the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param column - Name of the column
-         * \param value - Identifier for WHERE statement
-         * \param match - enum Db::exactMatch or Db::partialMatch
-         * \return QString
-         */
-        static QString          singleSelect(QString column, QString table, QString checkColumn,
-                                             QString value, Db::matchType match){
-            return get().isingleSelect(column,table,checkColumn,value,match);
-        }
-        /*!
-         * \brief Db::multiSelect Returns multiple values from the database with a sqlite WHERE statement
-         * \param table - Name of the table
-         * \param columns - QVector<QString> Names of the columns to be queried
-         * \param value - Identifier for WHERE statement
-         * \param checkColumn - column to match value to
-         * \param match - enum Db::exactMatch or Db::partialMatch
-         * \return QVector<QString>
-         */
-        static QVector<QString> multiSelect(QVector<QString> columns, QString table,
-                                            QString checkColumn, QString value, Db::matchType match){
-            return get().imultiSelect(columns,table,checkColumn,value,match);
-        }
-        /*!
-         * \brief Db::multiSelect Returns a complete column(s) for a given table.
-         * \param column - QVector<QString> Names of the columns to be queried
-         * \param table - QString Name of the table
-         * \return
-         */
-        static QVector<QString> multiSelect(QVector<QString> columns, QString table){
-            return get().imultiSelect(columns, table);
-        }
-        /*!
-         * \brief Db::customQuery Can be used to send a complex query to the database.
-         * \param query - the full sql query statement
-         * \param returnValues - the number of expected return values
-         * \return QVector<QString> of results
-         */
-        static QVector<QString> customQuery(QString query, int returnValues){
-            return get().icustomQuery(query, returnValues);
-        }
-
-    private:
-        Db() {}
-        void             iconnect();
-        void             idisconnect();
-        QSqlDatabase     iDatabase();
-        bool             iexists(QString column, QString table, QString checkColumn,
-                                       QString value, Db::matchType match);
-        bool             isingleUpdate(QString table, QString column, QString value,
-                                             QString checkColumn, QString checkvalue, Db::matchType match);
-        QString          isingleSelect(QString column, QString table, QString checkColumn,
-                                             QString value, Db::matchType match);
-        QVector<QString> imultiSelect(QVector<QString> columns, QString table,
-                                            QString checkColumn, QString value, Db::matchType match);
-        QVector<QString> imultiSelect(QVector<QString> columns, QString table);
-        QVector<QString> icustomQuery(QString query, int returnValues);
-
-    public:
-        // [George]: Why delete these in particular?
-        Db(Db const&)              = delete;
-        void operator=(Db const&)  = delete;
-};
-
-#endif // DB_H

+ 0 - 57
src/database/dbinfo.cpp

@@ -1,57 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "dbinfo.h"
-#include "src/testing/adebug.h"
-
-DbInfo::DbInfo()
-{
-    QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
-    tables = db.tables().toVector();
-    getColumnNames();
-    sqliteversion();
-}
-
-/*!
- * \brief DbInfo::getColumnNames Looks up column names for all tables
- * in the database.
- */
-void DbInfo::getColumnNames()
-{
-    QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
-    QVector<QString> columnNames;
-    for (const auto &table : tables) {
-        columnNames.clear();
-        QSqlRecord fields = db.record(table);
-        for (int i = 0; i < fields.count(); i++) {
-            columnNames << fields.field(i).name();
-            format.insert(table, columnNames);
-        }
-    }
-}
-
-/*!
- * \brief db::sqliteversion queries database version.
- */
-void DbInfo::sqliteversion()
-{
-    QSqlQuery q;
-    q.prepare("SELECT sqlite_version()");
-    q.exec();
-    q.next();
-    version = q.value(0).toString();
-}

+ 0 - 41
src/database/dbinfo.h

@@ -1,41 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef DBINFO_H
-#define DBINFO_H
-
-#include <QCoreApplication>
-#include <QDebug>
-#include "db.h"
-
-class DbInfo
-{
-public:
-    DbInfo();
-
-    QString version = QString();
-
-    QMap<QString, QVector<QString>> format;
-
-    QVector<QString> tables;
-
-    void getColumnNames();
-
-    void sqliteversion();
-};
-
-#endif // DBINFO_H

+ 0 - 247
src/database/entry_deprecated.cpp

@@ -1,247 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#include "entry_deprecated.h"
-#include "src/testing/adebug.h"
-#include "db.h"
-
-Entry_deprecated::Entry_deprecated()
-{
-}
-
-Entry_deprecated::Entry_deprecated(QString table, int row)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    if (dbContent.tables.contains(table)) {
-        position.first = table;
-        columns = dbContent.format.value(table);
-    } else {
-        DEB(table << " not a table in database. Unable to create Entry object.");
-        position.first = QString();
-    }
-
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(row);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows == 0) {
-        DEB("No Entry found for row id: " << row );
-        position.second = 0;
-    } else {
-        DEB("Retreiving data for row id: " << row);
-        QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(row);
-
-        QSqlQuery q(statement);
-        q.exec();
-        q.next();
-        for (int i = 0; i < dbContent.format.value(table).length(); i++) {
-            data.insert(dbContent.format.value(table)[i], q.value(i).toString());
-        }
-
-        error = q.lastError().text();
-        if (error.length() > 2) {
-            DEB("Error: " << q.lastError().text());
-            position.second = 0;
-        } else {
-            position.second = row;
-        }
-    }
-}
-
-Entry_deprecated::Entry_deprecated(QString table, QMap<QString, QString> newData)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-
-    if (dbContent.tables.contains(table)) {
-        position.first = table;
-        position.second = 0;
-        columns = dbContent.format.value(table);
-    } else {
-        DEB(table << " not a table in database. Unable to create Entry object.");
-        position.first = QString();
-    }
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = newData.begin(); i != newData.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << table << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        newData.remove(var);
-    }
-    data = newData;
-}
-
-void Entry_deprecated::setData(QMap<QString, QString> &value)
-{
-    //retreive database layout
-    const auto dbContent = DbInfo();
-    columns = dbContent.format.value(position.first);
-
-    //Check validity of newData
-    QVector<QString> badkeys;
-    QMap<QString, QString>::iterator i;
-    for (i = value.begin(); i != value.end(); ++i) {
-        if (!columns.contains(i.key())) {
-            DEB(i.key() << "Not in column list for table " << position.first << ". Discarding.");
-            badkeys << i.key();
-        }
-    }
-    for (const auto &var : badkeys) {
-        value.remove(var);
-    }
-    data = value;
-}
-
-bool Entry_deprecated::commit()
-{
-    if (exists()) {
-        return update();
-    } else {
-        return insert();
-    }
-}
-
-bool Entry_deprecated::remove()
-{
-    if (exists()) {
-        QString statement = "DELETE FROM " + position.first +
-                            " WHERE _rowid_=" + QString::number(position.second);
-        QSqlQuery q(statement);
-        error = q.lastError().text();
-
-        if (error.length() > 1) {
-            DEB("Errors have occured: " << error);
-            return false;
-        } else {
-            DEB("Entry removed.");
-            return true;
-        }
-    } else {
-        return false;
-    }
-}
-
-bool Entry_deprecated::exists()
-{
-    //Check database for row id
-    QString statement = "SELECT COUNT(*) FROM " + position.first +
-                        " WHERE _rowid_=" + QString::number(position.second);
-    QSqlQuery q(statement);
-    q.next();
-    int rows = q.value(0).toInt();
-    if (rows) {
-        DEB("Entry exists. " << rows);
-        return true;
-    } else {
-        DEB("Entry does not exist. " << rows);
-        return false;
-    }
-}
-
-bool Entry_deprecated::insert()
-{
-    DEB("Inserting...");
-    //check prerequisites
-
-    if (data.isEmpty()) {
-        DEB("Object Contains no data. Aborting.");
-        return false;
-    }
-    QString statement = "INSERT INTO " + position.first + QLatin1String(" (");
-    QMap<QString, QString>::iterator i;
-    for (i = data.begin(); i != data.end(); ++i) {
-        statement += i.key() + QLatin1String(", ");
-    }
-    statement.chop(2);
-    statement += QLatin1String(") VALUES (");
-    for (i = data.begin(); i != data.end(); ++i) {
-        statement += QLatin1String("'") + i.value() + QLatin1String("', ");
-    }
-    statement.chop(2);
-    statement += QLatin1String(")");
-
-    QSqlQuery q(statement);
-    error = q.lastError().text();
-    if (error.length() < 2) {
-        DEB("Entry successfully committed.");
-        return true;
-    } else {
-        DEB("Unable to commit. Query Error: " << q.lastError().text());
-        return false;
-    }
-}
-
-bool Entry_deprecated::update()
-{
-    //create query
-    QString statement = "UPDATE " + position.first + " SET ";
-
-    QMap<QString, QString>::const_iterator i;
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        if (i.key() != QString()) {
-            statement += i.key() + QLatin1String("='") + i.value() + QLatin1String("', ");
-        } else {
-            DEB(i.key() << "is empty key. skipping.");
-        }
-    }
-    statement.chop(2); // Remove last comma
-    statement.append(QLatin1String(" WHERE _rowid_=") + QString::number(position.second));
-
-    //execute query
-    DEB("UPDATE QUERY: " << statement);
-    QSqlQuery q(statement);
-    //check result. Upon success, error should be " "
-    error = q.lastError().text();
-    if (error.length() < 2) {
-        DEB("Object successfully updated.");
-        return true;
-    } else {
-        DEB("Query Error: " << q.lastError().text());
-        return false;
-    }
-}
-
-//Debug
-void Entry_deprecated::print()
-{
-    QString v = "Object status:\t\033[38;2;0;255;0;48;2;0;0;0m VALID \033[0m\n";
-    QString nv = "Object status:\t\033[38;2;255;0;0;48;2;0;0;0m INVALID \033[0m\n";
-    QTextStream cout(stdout, QIODevice::WriteOnly);
-
-    cout << "=========Database Entry=========\n";
-    //if(isValid){cout << v;}else{cout << nv;}
-    cout << "Record from table: " << position.first << ", row: " << position.second << "\n";
-    cout << "=================================\n";
-    QMap<QString, QString>::const_iterator i;
-    for (i = data.constBegin(); i != data.constEnd(); ++i) {
-        cout << i.key() << ":\t" << i.value() << "\n";
-    }
-}
-
-QString Entry_deprecated::debug()
-{
-    print();
-    return QString();
-}

+ 0 - 60
src/database/entry_deprecated.h

@@ -1,60 +0,0 @@
-/*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020  Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-#ifndef ENTRY1_H
-#define ENTRY1_H
-
-#include <QCoreApplication>
-#include "db.h"
-#include "dbinfo.h"
-/*!
- * \brief The Entry class is the base class for database entries.
- * It can be seen as a row in a table within the database.
- *
- */
-class Entry_deprecated
-{
-public:
-    Entry_deprecated();
-    Entry_deprecated(QString table, int row);
-    Entry_deprecated(QString table, QMap<QString, QString> newData);
-
-    QPair   <QString, int>       position = QPair<QString, int>();    // Position within the database, i.e. <table,row>
-    QVector <QString>            columns  = QVector<QString>();       // The columns within the table
-    QMap    <QString, QString>   data     = QMap<QString, QString>(); // Tha data to fill that table, <column,value>
-    QString                      error    = QString();                // holds sql errors (if they ocurred)
-
-    void setData(QMap<QString, QString> &value);
-
-    bool commit();
-    bool remove();
-    bool exists();
-
-    // Debug functionality
-    void print();
-    QString debug();
-    operator QString()
-    {
-        return debug();    //overload for compatibility with qDebug()
-    }
-
-private:
-    bool insert();
-    bool update();
-};
-
-#endif // ENTRY_H

+ 40 - 7
src/experimental/adatabase.cpp

@@ -16,7 +16,10 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "adatabase.h"
-#include "src/database/tablecolumnliterals.h"
+#include "src/testing/adebug.h"
+
+const auto SQL_DRIVER = QStringLiteral("QSQLITE");
+
 
 namespace experimental {
 
@@ -31,6 +34,16 @@ QString ADatabaseError::text() const
 
 ADatabase* ADatabase::instance = nullptr;
 
+TableNames ADatabase::getTableNames() const
+{
+    return tableNames;
+}
+
+TableColumns ADatabase::getTableColumns() const
+{
+    return tableColumns;
+}
+
 ADatabase* ADatabase::getInstance()
 {
     if(!instance)
@@ -38,22 +51,33 @@ ADatabase* ADatabase::getInstance()
     return instance;
 }
 
-bool ADatabase::connect()
+/*!
+ * \brief ADatabase::sqliteVersion returns database sqlite version.
+ * \return sqlite version string
+ */
+const QString ADatabase::sqliteVersion()
 {
-    const QString driver("QSQLITE");
+    QSqlQuery query;
+    query.prepare("SELECT sqlite_version()");
+    query.exec();
+    query.next();
+    return query.value(0).toString();
+}
 
-    if (!QSqlDatabase::isDriverAvailable(driver))
+bool ADatabase::connect()
+{
+    if (!QSqlDatabase::isDriverAvailable(SQL_DRIVER))
         return false;
 
     QDir directory("data");
     QString databaseLocation = directory.filePath("logbook.db");
-    QSqlDatabase db = QSqlDatabase::addDatabase(driver);
+    QSqlDatabase db = QSqlDatabase::addDatabase(SQL_DRIVER);
     db.setDatabaseName(databaseLocation);
 
     if (!db.open())
         return false;
 
-    DEB("Database connection established.");
+    DEB("Database connection established." << db.lastError().text());
     // Enable foreign key restrictions
     QSqlQuery query("PRAGMA foreign_keys = ON;");
     tableNames = db.tables();
@@ -76,7 +100,6 @@ void ADatabase::disconnect()
 {
     auto db = ADatabase::database();
     db.close();
-    db.removeDatabase(db.connectionName());
     DEB("Database connection closed.");
 }
 
@@ -561,6 +584,16 @@ QList<int> ADatabase::getForeignKeyConstraints(int foreign_row_id, ADatabaseTarg
     return row_ids;
 }
 
+APilotEntry ADatabase::resolveForeignPilot(int foreign_key)
+{
+    return aDB()->getPilotEntry(foreign_key);
+}
+
+ATailEntry ADatabase::resolveForeignTail(int foreign_key)
+{
+    return aDB()->getTailEntry(foreign_key);
+}
+
 QVector<QString> ADatabase::customQuery(QString statement, int return_values)
 {
     QSqlQuery query(statement);

+ 31 - 8
src/experimental/adatabase.h

@@ -15,18 +15,24 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef __DB_H__
-#define __DB_H__
+#ifndef ADATABASE_H
+#define ADATABASE_H
 
 #include <QPair>
 #include <QMap>
 #include <QString>
+#include <QDir>
+#include <QSqlDatabase>
+#include <QSqlDriver>
 #include <QSqlQuery>
 #include <QSqlError>
 #include <QSqlTableModel>
-#include "src/database/dbinfo.h"
-#include "src/testing/adebug.h"
+#include <QSqlQuery>
+#include <QSqlRecord>
+#include <QSqlField>
 
+#include "decl.h"
+#include "src/database/tablecolumnliterals.h"
 #include "aentry.h"
 #include "apilotentry.h"
 #include "atailentry.h"
@@ -38,18 +44,18 @@ namespace experimental {
 
 // [G]: Suspicious documentation -,O
 /*!
- * \brief The DBTarget enum provides the items for which QCompleter
- * completion lists are provided from the database.
+ * \brief The DBTarget enum lists database items that are
+ * used by completers, for content matching or need to be accessed programatically.
  */
 enum class ADatabaseTarget
 {
+    aircraft,
     airport_identifier_icao,
     airport_identifier_iata,
     airport_identifier_all,
     airport_names,
     pilots,
     registrations,
-    aircraft,
     companies,
     tails
 };
@@ -85,6 +91,9 @@ public:
     void operator=(const ADatabase&) = delete;
     static ADatabase* getInstance();
     ADatabaseError lastError;
+    TableNames getTableNames() const;
+    TableColumns getTableColumns() const;
+    const QString sqliteVersion();
 
     /*!
      * \brief Connect to the database and populate database information.
@@ -215,6 +224,20 @@ public:
      */
     QList<int> getForeignKeyConstraints(int foreign_row_id, ADatabaseTarget target);
 
+    /*!
+     * \brief Resolves the foreign key in a flight entry
+     * \return The Pilot Entry referencted by the foreign key.
+     */
+    APilotEntry resolveForeignPilot(int foreign_key);
+
+    /*!
+     * \brief Resolves the foreign key in a flight entry
+     * \return The Tail Entry referencted by the foreign key.
+     */
+    ATailEntry resolveForeignTail(int foreign_key);
+
+
+
 signals:
     /*!
      * \brief updated is emitted whenever the database contents have been updated.
@@ -236,4 +259,4 @@ ADatabase* aDB();
 
 }  // namespace experimental
 
-#endif
+#endif // ADATABASE_H

+ 3 - 3
src/experimental/aentry.h

@@ -15,8 +15,8 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef ENTRY_H
-#define ENTRY_H
+#ifndef AENTRY_H
+#define AENTRY_H
 
 #include <QString>
 #include <QStringList>
@@ -62,4 +62,4 @@ public:
 
 }
 
-#endif // ENTRY_H
+#endif // AENTRY_H

+ 39 - 42
src/experimental/aflightentry.cpp

@@ -1,5 +1,23 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
 #include "aflightentry.h"
 #include "src/experimental/adatabase.h"
+#include "src/database/tablecolumnliterals.h"
 
 namespace experimental {
 
@@ -8,7 +26,7 @@ AFlightEntry::AFlightEntry()
 {}
 
 AFlightEntry::AFlightEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QStringLiteral("flights"), row_id))
+    : AEntry::AEntry(DataPosition(DB_TABLE_FLIGHTS, row_id))
 {}
 
 AFlightEntry::AFlightEntry(TableData table_data)
@@ -21,61 +39,40 @@ const QString AFlightEntry::summary()
         return QString();
 
     QString flight_summary;
-    flight_summary.append(tableData.value("doft").toString() + " ");
-    flight_summary.append(tableData.value("dept").toString() + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value("tofb").toString()) + " ");
-    flight_summary.append(ACalc::minutesToString(tableData.value("tonb").toString()) + " ");
-    flight_summary.append(tableData.value("dest").toString() + " ");
+    flight_summary.append(tableData.value(DB_FLIGHTS_DOFT).toString() + " ");
+    flight_summary.append(tableData.value(DB_FLIGHTS_DEPT).toString() + " ");
+    flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TOFB).toString()) + " ");
+    flight_summary.append(ACalc::minutesToString(tableData.value(DB_FLIGHTS_TONB).toString()) + " ");
+    flight_summary.append(tableData.value(DB_FLIGHTS_DEST).toString() + " ");
 
     return flight_summary;
 }
 
 const QString AFlightEntry::getRegistration()
 {
-    QString tail_id = tableData.value(QLatin1String("acft")).toString();
-    if(tail_id.isEmpty())
-        return QString();
-
-    QString statement = "SELECT registration "
-                        "FROM tails "
-                        "WHERE ROWID =" + tail_id;
-
-    auto tail_registration = aDB()->customQuery(statement, 1);
-
-    if(tail_registration.isEmpty()) {
-        return QString();
-    } else {
-        return tail_registration.first();
-    }
+    ATailEntry acft = aDB()->resolveForeignTail(tableData.value(DB_FLIGHTS_ACFT).toInt());
+    return acft.registration();
 }
 
 const QString AFlightEntry::getPilotName(pilot pilot_)
 {
-    QString row_id;
     switch (pilot_) {
-    case pilot::pic:
-        row_id = tableData.value(QLatin1String("pic")).toString();
-        break;
-    case pilot::sic:
-        row_id = tableData.value(QLatin1String("sic")).toString();
-        break;
-    case pilot::thirdPilot:
-        row_id = tableData.value(QLatin1String("thirdPilot")).toString();
+    case pilot::pic: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_PIC).toInt());
+        return foreign_pilot.name();
         break;
     }
-    if(row_id == QString())
-        return row_id;
-
-    QString statement = "SELECT lastname||', '||firstname "
-                        "FROM pilots "
-                        "WHERE ROWID =" + row_id;
-
-    auto pilot_name = aDB()->customQuery(statement, 1);
-    if(pilot_name.isEmpty()) {
-        return QString();
-    } else {
-        return pilot_name.first();
+    case pilot::sic: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_SECONDPILOT).toInt());
+        return foreign_pilot.name();
     }
+    case pilot::thirdPilot: {
+        auto foreign_pilot = aDB()->resolveForeignPilot(tableData.value(DB_FLIGHTS_THIRDPILOT).toInt());
+        return foreign_pilot.name();
+        break;
+    } // case scope
+    } // switch (pilot_)
+    return QString();
 }
 
 } // namespace experimental

+ 17 - 0
src/experimental/aflightentry.h

@@ -1,3 +1,20 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
 #ifndef AFLIGHTENTRY_H
 #define AFLIGHTENTRY_H
 

+ 5 - 4
src/experimental/apilotentry.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "apilotentry.h"
+#include "src/database/tablecolumnliterals.h"
 
 namespace experimental {
 
@@ -24,7 +25,7 @@ APilotEntry::APilotEntry()
 {}
 
 APilotEntry::APilotEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QStringLiteral("pilots"), row_id))
+    : AEntry::AEntry(DataPosition(DB_TABLE_PILOTS, row_id))
 {}
 
 APilotEntry::APilotEntry(TableData table_data)
@@ -34,10 +35,10 @@ APilotEntry::APilotEntry(TableData table_data)
 const QString APilotEntry::name()
 {
     if (tableData.isEmpty())
-        return QLatin1String("");
+        return DB_NULL;
 
-    return tableData.value(QStringLiteral("lastname")).toString() + ','
-           +tableData.value(QStringLiteral("firstname")).toString().left(1) + '.';
+    return tableData.value(DB_PILOTS_LASTNAME).toString() + ','
+           +tableData.value(DB_PILOTS_FIRSTNAME).toString().left(1) + '.';
 }
 
 } // namespace experimental

+ 9 - 8
src/experimental/atailentry.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "atailentry.h"
+#include "src/database/tablecolumnliterals.h"
 
 namespace experimental {
 
@@ -24,7 +25,7 @@ ATailEntry::ATailEntry()
 {}
 
 ATailEntry::ATailEntry(int row_id)
-    : AEntry::AEntry(DataPosition(QLatin1String("tails"), row_id))
+    : AEntry::AEntry(DataPosition(DB_TABLE_TAILS, row_id))
 {}
 
 ATailEntry::ATailEntry(TableData table_data)
@@ -33,18 +34,18 @@ ATailEntry::ATailEntry(TableData table_data)
 
 const QString ATailEntry::registration()
 {
-    return getData().value(QLatin1String("registration")).toString();
+    return getData().value(DB_TAILS_REGISTRATION).toString();
 }
 
 const QString ATailEntry::type()
 {
     QString type_string;
-    if (!getData().value(QLatin1String("make")).toString().isEmpty())
-        type_string.append(getData().value(QLatin1String("make")).toString() + ' ');
-    if (!getData().value(QLatin1String("model")).toString().isEmpty())
-        type_string.append(getData().value(QLatin1String("model")).toString());
-    if (!getData().value(QLatin1String("variant")).toString().isEmpty())
-        type_string.append('-' + getData().value(QLatin1String("variant")).toString() + ' ');
+    if (!getData().value(DB_TAILS_MAKE).toString().isEmpty())
+        type_string.append(getData().value(DB_TAILS_MAKE).toString() + ' ');
+    if (!getData().value(DB_TAILS_MODEL).toString().isEmpty())
+        type_string.append(getData().value(DB_TAILS_MODEL).toString());
+    if (!getData().value(DB_TAILS_VARIANT).toString().isEmpty())
+        type_string.append('-' + getData().value(DB_TAILS_VARIANT).toString() + ' ');
 
     return type_string;
 }

+ 4 - 4
src/experimental/decl.h

@@ -55,10 +55,10 @@ struct DataPosition : QPair<TableName, RowId> {
     DataPosition(const DataPosition& other) = default;
     DataPosition& operator=(const DataPosition& other) = default;
 };
-auto const DEFAULT_PILOT_POSITION = DataPosition("pilots", 0);
-auto const DEFAULT_TAIL_POSITION = DataPosition("tails", 0);
-auto const DEFAULT_AIRCRAFT_POSITION = DataPosition("aircraft", 0);
-auto const DEFAULT_FLIGHT_POSITION = DataPosition("flights", 0);
+auto const DEFAULT_PILOT_POSITION    = DataPosition(QStringLiteral("pilots"), 0);
+auto const DEFAULT_TAIL_POSITION     = DataPosition(QStringLiteral("tails"), 0);
+auto const DEFAULT_AIRCRAFT_POSITION = DataPosition(QStringLiteral("aircraft"), 0);
+auto const DEFAULT_FLIGHT_POSITION   = DataPosition(QStringLiteral("flights"), 0);
 
 }
 

+ 1 - 0
src/functions/acalc.cpp

@@ -1,6 +1,7 @@
 #include "acalc.h"
 #include "src/testing/adebug.h"
 #include "src/experimental/adatabase.h"
+#include "src/classes/asettings.h"
 
 using namespace ACalc;
 using namespace experimental;

+ 0 - 6
src/functions/acalc.h

@@ -1,10 +1,6 @@
 #ifndef ACALC_H
 #define ACALC_H
 
-#include "src/database/db.h"
-#include "src/classes/aircraft.h"
-#include "src/classes/flight.h"
-#include "src/classes/asettings.h"
 #include <QDateTime>
 #include <cmath>
 #include <QDebug>
@@ -201,8 +197,6 @@ QString formatTimeInput(QString user_input);
 
 void updateAutoTimes(int acft_id);
 
-void autoTimes(Flight, Aircraft);
-
 void updateNightTimes();
 } // namespace ACalc
 

+ 0 - 1
src/gui/dialogues/newpilotdialog.h

@@ -23,7 +23,6 @@
 #include <QRegularExpression>
 #include <QRegularExpressionValidator>
 #include <QCompleter>
-#include "src/classes/pilot.h"
 
 #include "src/experimental/adatabase.h"
 #include "src/experimental/aentry.h"

+ 0 - 1
src/gui/dialogues/newtaildialog.h

@@ -24,7 +24,6 @@
 #include <QRegularExpression>
 
 #include "src/classes/asettings.h"
-#include "src/classes/aircraft.h"
 #include "src/functions/acalc.h"
 #include "src/experimental/adatabase.h"
 #include "src/experimental/atailentry.h"

+ 0 - 2
src/gui/widgets/aircraftwidget.h

@@ -26,8 +26,6 @@
 
 #include "src/classes/asettings.h"
 #include "src/gui/dialogues/newtaildialog.h"
-//#include "src/classes/aircraft.h"
-//#include "src/database/db.h"
 #include "src/experimental/adatabase.h"
 #include "src/experimental/atailentry.h"
 #include "src/experimental/aflightentry.h"

+ 8 - 32
src/gui/widgets/debugwidget.cpp

@@ -8,7 +8,7 @@ DebugWidget::DebugWidget(QWidget *parent) :
     ui(new Ui::DebugWidget)
 {
     ui->setupUi(this);
-    for (const auto& table : DbInfo().tables) {
+    for (const auto& table : aDB()->getTableNames()) {
         if( table != "sqlite_sequence") {
             ui->tableComboBox->addItem(table);
         }
@@ -59,17 +59,20 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
         loop.exec(); // event loop waits for download done signal before allowing loop to continue
         dl->deleteLater();
     }
+
     //close database connection
     aDB()->disconnect();
 
-    // back up old database
+    // back up and remove old database
     auto oldDatabase = QFile("data/logbook.db");
     if (oldDatabase.exists()) {
         auto dateString = QDateTime::currentDateTime().toString(Qt::ISODate);
-        DEB("Backing up old database as: " << "logbook-backup-" + dateString);
-        if (!oldDatabase.rename("data/logbook-backup-" + dateString + ".db")) {
-            DEB("Warning: Creating backup of old database has failed.");
+        DEB("Backing up old database as: " << "logbook-backup-" + dateString + ".db");
+        if (oldDatabase.copy("data/logbook-backup-" + dateString + ".db")) {
+            oldDatabase.remove();
+            DEB("Old Database removed.");
         }
+
     }
     // re-connct and create new database
     aDB()->connect();
@@ -167,33 +170,6 @@ void DebugWidget::on_importCsvPushButton_clicked()
 
 void DebugWidget::on_debugPushButton_clicked()
 {
-    qlonglong number_of_runs = 500;
-            long time1 = 0;
-            using namespace experimental;
-            {
-
-                ATimer timer;
-                for (int i = 0; i < number_of_runs; i++) {
-                    // first block, do stuff here...
-                    auto acft = aDB()->getTailEntry(5);
-                    auto pilot = aDB()->getPilotEntry(7);
-                    auto flight = aDB()->getFlightEntry(15);
-                    QList<AEntry> list = {acft, pilot, flight};
-                    for (auto entry : list) {
-                        for (auto column : entry.getData()) {
-                            QString value = column.toString();
-                        }
-                    }
-                }
-
-                time1 = timer.timeNow();
-            }
-
-            DEB("First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
-            // 116 - 134 milliseconds with legacy exp db api
-            // 108 - 110 milliseconds with improved exp api
-            // to do: with string literals*/
-
 
 }
 

+ 0 - 2
src/gui/widgets/debugwidget.h

@@ -8,9 +8,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QProcess>
-#include "src/database/db.h"
 #include "src/database/adatabasesetup.h"
-#include "src/database/dbinfo.h"
 #include "src/classes/adownload.h"
 #include "src/functions/areadcsv.h"
 

+ 0 - 3
src/gui/widgets/homewidget.h

@@ -22,13 +22,10 @@
 #include <QStackedLayout>
 #include <QLabel>
 #include <QLineEdit>
-#include "src/database/db.h"
 #include "src/functions/astat.h"
 #include "src/functions/acalc.h"
 #include "src/gui/dialogues/newtaildialog.h"
-#include "src/classes/aircraft.h"
 #include "src/gui/dialogues/newpilotdialog.h"
-#include "src/database/entry_deprecated.h"
 #include "src/gui/widgets/totalswidget.h"
 #include "src/gui/dialogues/firstrundialog.h"
 #include "src/gui/dialogues/newflightdialog.h"

+ 0 - 2
src/gui/widgets/logbookwidget.h

@@ -27,8 +27,6 @@
 #include <QTableView>
 
 #include "src/classes/asettings.h"
-#include "src/database/db.h"
-#include "src/classes/flight.h"
 #include "src/gui/dialogues/newflightdialog.h"
 #include "src/experimental/aflightentry.h"
 

+ 0 - 1
src/gui/widgets/pilotswidget.h

@@ -24,7 +24,6 @@
 #include <QDebug>
 #include <QTableView>
 #include "src/classes/asettings.h"
-#include "src/classes/pilot.h"
 #include "src/gui/dialogues/newpilotdialog.h"
 
 namespace Ui {

+ 1 - 2
src/gui/widgets/settingswidget.cpp

@@ -17,7 +17,6 @@
  */
 #include "settingswidget.h"
 #include "ui_settingswidget.h"
-#include "src/database/dbinfo.h"
 #include "src/testing/adebug.h"
 
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
@@ -325,7 +324,7 @@ void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
 void SettingsWidget::on_aboutPushButton_clicked()
 {
     auto message_box = QMessageBox(this);
-    QString SQLITE_VERSION = DbInfo().version;
+    QString SQLITE_VERSION = aDB()->sqliteVersion();
     QString text = QMessageBox::tr(
 
                        "<h3><center>About openPilotLog</center></h3>"

+ 0 - 1
src/gui/widgets/totalswidget.h

@@ -6,7 +6,6 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QSettings>
-#include "src/database/db.h"
 #include "src/functions/astat.h"
 
 namespace Ui {