Browse Source

implemented foreign key restrictions on qsql database connection

fiffty-50 4 years ago
parent
commit
340d4e5626
3 changed files with 3 additions and 4 deletions
  1. BIN
      assets/database/logbook.db
  2. 2 0
      src/database/db.cpp
  3. 1 4
      src/database/entry.h

BIN
assets/database/logbook.db


+ 2 - 0
src/database/db.cpp

@@ -39,6 +39,8 @@ void Db::iconnect()
             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");

+ 1 - 4
src/database/entry.h

@@ -33,9 +33,7 @@ public:
     Entry(QString table, int row);
     Entry(QString table, QMap<QString, QString> newData);
 
-
-
-    QPair   <QString, int>       position = QPair<QString, int>();   // Position within the database, i.e. <table,row>
+    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>
 
@@ -54,7 +52,6 @@ public:
     }
 
 private:
-
     bool insert();
     bool update();
 };