Browse Source

Removed ADatabaseSetup

The ADatabaseSetup namespace contained the String Literals of the SQL code needed to set up the database, it is now moved to the .sql file.
Functionality of the functions is incorporated into ADatabase and FirstRunDialog.
Added a fix for aircraft recognition in NewFlightDialog
Felix Turo 3 years ago
parent
commit
c4631ae706

+ 0 - 2
CMakeLists.txt

@@ -122,8 +122,6 @@ set(PROJECT_SOURCES
     src/database/adatabasetypes.h
     src/database/adatabase.h
     src/database/adatabase.cpp
-    src/database/adbsetup.h
-    src/database/adbsetup.cpp
 
     # Ressources
     assets/icons.qrc

+ 1 - 0
assets/database/database_schema.md5

@@ -0,0 +1 @@
+c71c34d120dbc8fe7186c303d5cfb6bb  database_schema.sql

+ 2 - 11
mainwindow.cpp

@@ -30,7 +30,7 @@
 // Quick and dirty Debug area
 void MainWindow::doDebugStuff()
 {
-    QSqlQuery query;
+    //QSqlQuery query;
     QFile f(OPL::Assets::DATABASE_SCHEMA);
     f.open(QIODevice::ReadOnly);
     QByteArray filedata = f.readAll();
@@ -52,19 +52,10 @@ MainWindow::MainWindow(QWidget *parent)
     // connect to the Database
     QFileInfo database_file(AStandardPaths::directory(AStandardPaths::Database).
                                          absoluteFilePath(QStringLiteral("logbook.db")));
-    bool db_invalid = false;
-    if (!database_file.exists()) {
-        WARN(tr("Error: Database file not found."));
-        db_invalid = true;
-    } else if (database_file.size() == 0) { // To Do: Check for database errors instead of just checking for empty
-        WARN(tr("Database file invalid."));
-        db_invalid = true;
-    }
 
-    if (db_invalid)
+    if (database_file.size() == 0)
         onDatabaseInvalid();
 
-
     if(!aDB->connect()){
         WARN(tr("Error establishing database connection."));
     }

+ 2 - 2
src/classes/ajson.cpp

@@ -16,7 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "ajson.h"
-#include "src/database/adbsetup.h"
+#include "src/database/adatabase.h"
 
 const QList<QPair<TableName_T, ADatabaseTable>> AJson::tables {
     qMakePair(OPL::Db::TABLE_TAILS, ADatabaseTable::tails),
@@ -53,7 +53,7 @@ void AJson::importDatabase()
         q.exec();
         const auto doc = readFileToDoc(AStandardPaths::asChildOfDir(AStandardPaths::JSON,
                                                                pair.first + QLatin1String(".json")));
-        aDbSetup::commitData(doc.array(), pair.first);
+        aDB->commit(doc.array(), pair.first);
     }
 }
 

+ 125 - 3
src/database/adatabase.cpp

@@ -20,6 +20,7 @@
 #include "src/classes/astandardpaths.h"
 #include "src/opl.h"
 #include "src/functions/alog.h"
+#include "src/classes/ajson.h"
 
 const int ADatabase::minimumDatabaseRevision = 0;
 
@@ -59,11 +60,16 @@ int ADatabase::getMinimumDatabaseRevision()
     return minimumDatabaseRevision;
 }
 
-QStringList ADatabase::getTemplateTableNames()
+const QStringList &ADatabase::getTemplateTableNames() const
 {
     return templateTableNames;
 }
 
+const QStringList& ADatabase::getUserTableNames() const
+{
+    return userTableNames;
+}
+
 UserDataState ADatabase::getUserDataState()
 {
     QSqlQuery q;
@@ -80,9 +86,17 @@ UserDataState ADatabase::getUserDataState()
     return UserDataState(tails, pilots);
 }
 
-QStringList ADatabase::getUserTableNames()
+bool ADatabase::resetUserData()
 {
-    return userTableNames;
+    QSqlQuery query;
+    for (const auto& table : userTableNames) {
+        query.prepare(QLatin1String("DELETE FROM ") + table);
+        if (!query.exec()) {
+            DEB << "Error: " << query.lastError().text();
+            return false;
+        }
+    }
+    return true;
 }
 
 const ColumnNames_T ADatabase::getTableColumns(TableName_T table_name) const
@@ -120,6 +134,76 @@ ADatabase* ADatabase::instance()
     return self;
 }
 
+bool ADatabase::createSchema()
+{
+    // Read Database layout from sql file
+    QFile f(OPL::Assets::DATABASE_SCHEMA);
+    f.open(QIODevice::ReadOnly);
+    QByteArray filedata = f.readAll();
+    // create individual queries for each table/view
+    auto list = filedata.split(';');
+
+    // Create Tables
+    QSqlQuery q;
+    QVector<QSqlError> errors;
+    for (const auto &query_string : list) {
+        q.prepare(query_string);
+        if (!q.exec()) {
+            errors.append(q.lastError());
+            LOG << "Unable to execute query: ";
+            LOG << q.lastQuery();
+            LOG << q.lastError();
+        }
+    }
+    updateLayout();
+
+    if (errors.isEmpty()) {
+        LOG << "Database succesfully created.";
+        return true;
+    } else {
+        LOG << "Database creation has failed. The following error(s) have ocurred: ";
+        for (const auto &error : qAsConst(errors)) {
+            LOG << error.type() << error.text();
+        }
+        return false;
+    }
+}
+
+bool ADatabase::importTemplateData(bool use_local_ressources)
+{
+    for (const auto& table_name : templateTableNames) {
+
+        //clear table
+        QSqlQuery q;
+        q.prepare(QLatin1String("DELETE FROM ") + table_name);
+        if (!q.exec()) {
+            LOG << "Error clearing tables: " << q.lastError().text();
+            return false;
+        }
+
+        //Prepare data
+        QJsonArray data_to_commit;
+        QString error_message("Error importing data ");
+
+        if (use_local_ressources) {
+            data_to_commit = AJson::readFileToDoc(QLatin1String(":database/templates/")
+                                      + table_name + QLatin1String(".json")).array();
+            error_message.append(QLatin1String(" (ressource) "));
+        } else {
+            data_to_commit = AJson::readFileToDoc(AStandardPaths::directory(
+                                          AStandardPaths::Templates).absoluteFilePath(
+                                          table_name + QLatin1String(".json"))).array();
+            error_message.append(QLatin1String(" (downloaded) "));
+        }
+
+        // commit Data from Array
+        if (!commit(data_to_commit, table_name)) {
+            LOG << error_message;
+            return false;
+        }
+    } // for table_name
+    return true;
+}
 
 const QString ADatabase::sqliteVersion() const
 {
@@ -162,6 +246,7 @@ void ADatabase::disconnect()
 {
     auto db = ADatabase::database();
     db.close();
+    db.removeDatabase(db.connectionName());
     LOG << "Database connection closed.";
 }
 
@@ -179,6 +264,43 @@ bool ADatabase::commit(const AEntry &entry)
     }
 }
 
+bool ADatabase::commit(const QJsonArray &json_arr, const QString &table_name)
+{
+    // create statement
+    QString statement = QLatin1String("INSERT INTO ") + table_name + QLatin1String(" (");
+    QString placeholder = QStringLiteral(") VALUES (");
+    for (const auto &column_name : aDB->getTableColumns(table_name)) {
+        statement += column_name + ',';
+        placeholder.append(QLatin1Char(':') + column_name + QLatin1Char(','));
+    }
+
+    statement.chop(1);
+    placeholder.chop(1);
+    placeholder.append(')');
+    statement.append(placeholder);
+
+    // Create query and commit
+    QSqlQuery q;
+    q.prepare(QStringLiteral("BEGIN EXCLUSIVE TRANSACTION"));
+    q.exec();
+    for (const auto &entry : json_arr) {
+        q.prepare(statement);
+        auto object = entry.toObject();
+        const auto keys = object.keys();
+        for (const auto &key : keys){
+            object.value(key).isNull() ? q.bindValue(key, QVariant(QVariant::String)) : // refactor to use QMetaType with Qt6
+                                         q.bindValue(QLatin1Char(':') + key, object.value(key).toVariant());
+        }
+        q.exec();
+    }
+
+    q.prepare(QStringLiteral("COMMIT"));
+    if (q.exec())
+        return true;
+    else
+        return false;
+}
+
 bool ADatabase::remove(const AEntry &entry)
 {
     if (!exists(entry)) {

+ 37 - 6
src/database/adatabase.h

@@ -157,7 +157,12 @@ private:
     const static QStringList userTableNames;
     const static QStringList templateTableNames;
     const static int minimumDatabaseRevision;
+
 public:
+    ADatabase(const ADatabase&) = delete;
+    void operator=(const ADatabase&) = delete;
+    static ADatabase* instance();
+
     /*!
      * \brief Holds information about the last error that ocurred during
      * a SQL operation. If the error type is QSqlError::UnknownError, the error is related to data
@@ -170,10 +175,24 @@ public:
 
     const QFileInfo databaseFile;
 
-    // Ensure DB is not copiable or assignable
-    ADatabase(const ADatabase&) = delete;
-    void operator=(const ADatabase&) = delete;
-    static ADatabase* instance();
+
+
+    /*!
+     * \brief Create or restore the database to its ready-to-use but empty state
+     * \details The SQL code for the database creation is stored in a .sql file which is available as a ressource.
+     * This file gets read, and the querys executed. If errors occur, returns false.
+     */
+    bool createSchema();
+
+    /*!
+     * \brief importTemplateData fills an empty database with the template
+     * data (Aircraft, Airports, currencies, changelog) as read from the JSON
+     * templates.
+     * \param use_local_ressources determines whether the included ressource files
+     * or a previously downloaded file should be used.
+     * \return
+     */
+    bool importTemplateData(bool use_local_ressources = true);
 
     /*!
      * \brief dbRevision returns the database Revision Number. The Revision refers to what iteration
@@ -245,6 +264,13 @@ public:
      */
     bool commit(const AEntry &entry);
 
+    /*!
+     * \brief commits data imported from JSON
+     * \details This function is used to import values to the databases which are held in JSON documents.
+     * These entries are pre-filled data used for providing completion data, such as Airport or Aircraft Type Data.
+     */
+    bool commit(const QJsonArray &json_arr, const QString &table_name);
+
     /*!
      * \brief Create new entry in the databse based on UserInput
      */
@@ -394,13 +420,13 @@ public:
      * \brief getUserTableNames returns a list of the table names of tables that contain user-created data
      * (flights, pilots,..)
      */
-    QStringList getUserTableNames();
+    const QStringList &getUserTableNames() const;
 
     /*!
      * \brief getTemplateTableNames returns a list of the table names of tables that contain template data
      * (aiports, aircraft,..)
      */
-    QStringList getTemplateTableNames();
+    const QStringList &getTemplateTableNames() const;
 
     /*!
      * \brief getUserDataState returns a struct containing the current amount of entries in the tails and
@@ -409,6 +435,11 @@ public:
      */
     UserDataState getUserDataState();
 
+    /*!
+     * \brief Delete all rows from the user data tables (flights, pliots, tails)
+     */
+    bool resetUserData();
+
     /*!
      * \brief getMinimumDatabaseRevision returns the minimum required database revision number required by the application.
      */

+ 0 - 171
src/database/adbsetup.cpp

@@ -1,171 +0,0 @@
-/*
- *openPilotLog - A FOSS Pilot Logbook Application
- *Copyright (C) 2020-2021 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 "adbsetup.h"
-#include "src/opl.h"
-#include "src/database/adatabase.h"
-#include "src/functions/alog.h"
-#include "src/classes/ajson.h"
-
-namespace aDbSetup {
-
-// const auto TEMPLATE_URL = QStringLiteral("https://raw.githubusercontent.com/fiffty-50/openpilotlog/tree/main/assets/database/templates/");
-const static auto TEMPLATE_URL = QStringLiteral("https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/");
-
-const static QStringList USER_TABLES = {
-    QStringLiteral("flights"),
-    QStringLiteral("pilots"),
-    QStringLiteral("tails")
-};
-const static QStringList TEMPLATE_TABLES= {
-    QStringLiteral("aircraft"),
-    QStringLiteral("airports"),
-    QStringLiteral("currencies"),
-    QStringLiteral("changelog")
-};
-
-bool createDatabase()
-{
-    // Read Database layout from sql file
-    QFile f(OPL::Assets::DATABASE_SCHEMA);
-    f.open(QIODevice::ReadOnly);
-    QByteArray filedata = f.readAll();
-    // create individual queries for each table/view
-    auto list = filedata.split(';');
-
-    // Commit
-    QSqlQuery q;
-    QVector<QSqlError> errors;
-    // Create Tables
-    for (const auto &query_string : list) {
-        q.prepare(query_string);
-        if (!q.exec()) {
-            errors.append(q.lastError());
-            LOG << "Unable to execute query: ";
-            LOG << q.lastQuery();
-            LOG << q.lastError();
-        }
-    }
-
-    aDB->updateLayout();
-
-    if (errors.isEmpty()) {
-        LOG << "Database succesfully created.";
-        return true;
-    } else {
-        LOG << "Database creation has failed. The following error(s) have ocurred: ";
-        for (const auto &error : qAsConst(errors)) {
-            LOG << error.type() << error.text();
-        }
-        return false;
-    }
-}
-
-bool commitData(const QJsonArray &json_arr, const QString &table_name)
-{
-    //aDB->updateLayout(); // needed?
-    QSqlQuery q;
-
-    // create insert statement
-    QString statement = QLatin1String("INSERT INTO ") + table_name + QLatin1String(" (");
-    QString placeholder = QStringLiteral(") VALUES (");
-    for (const auto &column_name : aDB->getTableColumns(table_name)) {
-        statement += column_name + ',';
-        placeholder.append(QLatin1Char(':') + column_name + QLatin1Char(','));
-    }
-
-    statement.chop(1);
-    placeholder.chop(1);
-    placeholder.append(')');
-    statement.append(placeholder);
-
-    q.prepare(QStringLiteral("BEGIN EXCLUSIVE TRANSACTION"));
-    q.exec();
-    //DEB << statement;
-    for (const auto &entry : json_arr) {
-        q.prepare(statement);
-
-        auto object = entry.toObject();
-        const auto keys = object.keys();
-        for (const auto &key : keys){
-            object.value(key).isNull() ? q.bindValue(key, QVariant(QVariant::String)) :
-                                         q.bindValue(QLatin1Char(':') + key, object.value(key).toVariant());
-        }
-
-        q.exec();
-    }
-
-    q.prepare(QStringLiteral("COMMIT"));
-    if (q.exec())
-        return true;
-    else
-        return false;
-}
-
-bool importTemplateData(bool use_local_ressources)
-{
-    //QSqlQuery q;
-    // reset template tables
-    const auto table_names = aDB->getTemplateTableNames();
-    for (const auto& table_name : table_names) {
-
-        //clear table
-        //q.prepare(QLatin1String("DELETE FROM ") + table_name);
-        //if (!q.exec()) {
-        //    DEB << "Error: " << q.lastError().text();
-        //    return false;
-        //}
-
-        //Prepare data
-        QJsonArray data_to_commit;
-        QString error_message("Error importing data ");
-
-        if (use_local_ressources) {
-            data_to_commit = AJson::readFileToDoc(QLatin1String(":database/templates/")
-                                      + table_name + QLatin1String(".json")).array();
-            error_message.append(QLatin1String(" (ressource) "));
-        } else {
-            data_to_commit = AJson::readFileToDoc(AStandardPaths::directory(
-                                          AStandardPaths::Templates).absoluteFilePath(
-                                          table_name + QLatin1String(".json"))).array();
-            error_message.append(QLatin1String(" (downloaded) "));
-        }
-
-        // commit Data from Array
-        if (!commitData(data_to_commit, table_name)) {
-            LOG << error_message;
-            return false;
-        }
-    } // for table_name
-    return true;
-}
-
-bool resetUserData()
-{
-    QSqlQuery query;
-
-    // clear user tables
-    for (const auto& table : USER_TABLES) {
-        query.prepare("DELETE FROM " + table);
-        if (!query.exec()) {
-            DEB << "Error: " << query.lastError().text();
-        }
-    }
-    return true;
-}
-
-} // namespace aDbSetup

+ 0 - 59
src/database/adbsetup.h

@@ -1,59 +0,0 @@
-/*
- *openPilotLog - A FOSS Pilot Logbook Application
- *Copyright (C) 2020-2021 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 ADBSETUP_H
-#define ADBSETUP_H
-
-#include <QCoreApplication>
-
-/*!
- * \brief The aDbSetup 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.
- */
-namespace aDbSetup
-{
-
-/*!
- * \brief createDatabase runs a number of CREATE queries that create the database tables and columns.
- * \return
- */
-bool createDatabase();
-
-/*!
- * \brief commitData commits the data read from a JSON file into a table in the database.
- */
-bool commitData(const QJsonArray &json_arr, const QString &table_name);
-
-/*!
- * \brief importTemplateData fills an empty database with the template
- * data (Aircraft, Airports, currencies, changelog) as read from the JSON
- * templates.
- * \param use_local_ressources determines whether the included ressource files
- * or a previously downloaded file should be used.
- * \return
- */
-bool importTemplateData(bool use_local_ressources);
-
-/*!
- * \brief  Empties all user-generated content in the database.
- * \return true on success
- */
-bool resetUserData();
-}; // namespace aDbSetup
-
-#endif // ADBSETUP_H

+ 3 - 5
src/gui/dialogues/firstrundialog.cpp

@@ -21,7 +21,6 @@
 #include "src/functions/alog.h"
 #include "src/database/adatabase.h"
 #include "src/gui/widgets/backupwidget.h"
-#include "src/database/adbsetup.h"
 #include "src/classes/apilotentry.h"
 #include "src/classes/adownload.h"
 #include "src/classes/asettings.h"
@@ -29,6 +28,7 @@
 #include "src/classes/astyle.h"
 #include "src/functions/adatetime.h"
 #include "src/classes/ahash.h"
+#include "src/testing/atimer.h"
 #include <QErrorMessage>
 #include <QFileDialog>
 #include <QKeyEvent>
@@ -300,19 +300,17 @@ bool FirstRunDialog::setupDatabase()
         useRessourceData = true;
     }
 
-    if(!aDbSetup::createDatabase()) {
+    if(!aDB->createSchema()) {
         WARN(tr("Database creation has been unsuccessful. The following error has ocurred:<br><br>%1")
              .arg(aDB->lastError.text()));
         return false;
     }
 
-
-    if(!aDbSetup::importTemplateData(useRessourceData)) {
+    if(!aDB->importTemplateData(useRessourceData)) {
         WARN(tr("Database creation has been unsuccessful. Unable to fill template data.<br><br>%1")
              .arg(aDB->lastError.text()));
         return false;
     }
-
     return true;
 }
 

+ 18 - 4
src/gui/dialogues/newflightdialog.cpp

@@ -29,6 +29,8 @@
 #include <QCompleter>
 #include <QKeyEvent>
 
+const auto CAT_3 = QLatin1String(OPL::GLOBALS->getApproachTypes()[3].toLatin1());
+
 NewFlightDialog::NewFlightDialog(ACompletionData &completion_data,
                                        QWidget *parent)
     : QDialog(parent),
@@ -132,7 +134,6 @@ void NewFlightDialog::setupRawInputValidation()
     completer->setCompletionMode(QCompleter::PopupCompletion);
     completer->setFilterMode(Qt::MatchContains);
     ui->acftLineEdit->setCompleter(completer);
-
 }
 
 void NewFlightDialog::setupSignalsAndSlots()
@@ -459,7 +460,7 @@ RowData_T NewFlightDialog::prepareFlightEntryData()
         new_data.insert(OPL::Db::FLIGHTS_LDGNIGHT, 0);
         new_data.insert(OPL::Db::FLIGHTS_LDGDAY, ui->landingSpinBox->value());
     }
-    if (ui->approachComboBox->currentText() == OPL::GLOBALS->getApproachTypes()[3]) // ILS CAT III
+    if (ui->approachComboBox->currentText() == CAT_3) // ILS CAT III
         new_data.insert(OPL::Db::FLIGHTS_AUTOLAND, ui->landingSpinBox->value());
 
     // Additional Data
@@ -606,12 +607,21 @@ void NewFlightDialog::on_acftLineEdit_editingFinished()
 {
     const auto line_edit = ui->acftLineEdit;
     int acft_id = completionData.tailsIdMap.key(line_edit->text());
-    DEB << "acft_id: " << acft_id;
+    DEB << line_edit->text() << " has acft_id: " << acft_id;
 
     if (acft_id != 0) { // Success
         onGoodInputReceived(line_edit);
         return;
     }
+    // check for whitespaces
+    acft_id = completionData.tailsIdMap.key(line_edit->text().split(" ").first());
+    if (acft != 0) {
+        line_edit->setText(completionData.tailsIdMap.value(acft_id));
+        onGoodInputReceived(line_edit);
+        return;
+    }
+
+
 
     // try to use a completion
     if (!line_edit->completer()->currentCompletion().isEmpty() && !line_edit->text().isEmpty()) {
@@ -658,7 +668,9 @@ void NewFlightDialog::on_pilotFlyingCheckBox_stateChanged(int arg1)
 
 void NewFlightDialog::on_approachComboBox_currentTextChanged(const QString &arg1)
 {
-    if (arg1 == QLatin1String("OTHER"))
+    if (arg1 == CAT_3)
+        ui->remarksLineEdit->setText(QStringLiteral("Autoland"));
+    else if (arg1 == QLatin1String("OTHER"))
         INFO(tr("Please specify the approach type in the remarks field."));
 }
 
@@ -727,6 +739,8 @@ void NewFlightDialog::on_buttonBox_accepted()
 {
     // Debug
     validationState.printValidationStatus();
+    for (const auto& le : *mandatoryLineEdits)
+        emit le->editingFinished();
     // If input verification is passed, continue, otherwise prompt user to correct
     if (!validationState.allValid()) {
         const auto display_names = QHash<ValidationItem, QString> {

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

@@ -196,6 +196,7 @@ private slots:
     void on_pilotFlyingCheckBox_stateChanged(int arg1);
     void on_approachComboBox_currentTextChanged(const QString &arg1);
     void on_functionComboBox_currentIndexChanged(int index);
+
 protected:
     bool eventFilter(QObject* object, QEvent* event) override;
 };

+ 3 - 4
src/gui/widgets/debugwidget.cpp

@@ -28,7 +28,6 @@
 #include "src/functions/astat.h"
 #include "src/classes/acurrencyentry.h"
 #include "src/classes/atranslator.h"
-#include "src/database/adbsetup.h"
 #include "src/classes/ahash.h"
 #include "src/classes/ajson.h"
 #include "src/functions/adate.h"
@@ -76,7 +75,7 @@ DebugWidget::~DebugWidget()
 void DebugWidget::on_resetUserTablesPushButton_clicked()
 {
     ATimer timer(this);
-    if (aDbSetup::resetUserData()){
+    if (aDB->resetUserData()){
         LOG << "Database successfully reset";
         emit aDB->dataBaseUpdated();
     } else
@@ -140,14 +139,14 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
             LOG << "ssl/network error";
     }
     // Create Database
-    if (!aDbSetup::createDatabase()) {
+    if (!aDB->createSchema()) {
         WARN(QString("Unable to create database.<br>%1").arg(aDB->lastError.text()));
         return;
     }
 
     // Load ressources
     bool use_ressource_data = false; // do not use local data, download from github
-    if(!aDbSetup::importTemplateData(use_ressource_data)) {
+    if(!aDB->importTemplateData(use_ressource_data)) {
         WARN(tr("Database creation has been unsuccessful. Unable to fill template data.<br><br>%1")
              .arg(aDB->lastError.text()));
         return ;