diff SqliteDBLink.cpp @ 81:69a30d9f126e

Make the DBLink reusable.
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Thu, 10 Oct 2013 14:12:17 +0200
parents b9515dc35fe4
children 1f9e27a0bd7f
line wrap: on
line diff
--- a/SqliteDBLink.cpp	Thu Oct 10 14:08:25 2013 +0200
+++ b/SqliteDBLink.cpp	Thu Oct 10 14:12:17 2013 +0200
@@ -10,9 +10,16 @@
 #include "Exception/SQLException.hpp"
 #include "Exception/IOException.hpp"
 
+const QString SqliteDBLink::connectionName("SqliteDBLink");
+
+
 SqliteDBLink::SqliteDBLink(const QString& dbPath)
 {
-  db = QSqlDatabase::addDatabase("QSQLITE", "SqliteDBLink");
+  if (!QSqlDatabase::contains(connectionName))
+    db = QSqlDatabase::addDatabase("QSQLITE", connectionName);
+  else {
+    db = QSqlDatabase::database(connectionName);
+  }
   db.setDatabaseName(dbPath);
   if (!db.open())
     throw