Mercurial > dedupe
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 80:9bf00625988d | 81:69a30d9f126e |
|---|---|
| 8 #include <QtSql/QSqlRecord> | 8 #include <QtSql/QSqlRecord> |
| 9 | 9 |
| 10 #include "Exception/SQLException.hpp" | 10 #include "Exception/SQLException.hpp" |
| 11 #include "Exception/IOException.hpp" | 11 #include "Exception/IOException.hpp" |
| 12 | 12 |
| 13 const QString SqliteDBLink::connectionName("SqliteDBLink"); | |
| 14 | |
| 15 | |
| 13 SqliteDBLink::SqliteDBLink(const QString& dbPath) | 16 SqliteDBLink::SqliteDBLink(const QString& dbPath) |
| 14 { | 17 { |
| 15 db = QSqlDatabase::addDatabase("QSQLITE", "SqliteDBLink"); | 18 if (!QSqlDatabase::contains(connectionName)) |
| 19 db = QSqlDatabase::addDatabase("QSQLITE", connectionName); | |
| 20 else { | |
| 21 db = QSqlDatabase::database(connectionName); | |
| 22 } | |
| 16 db.setDatabaseName(dbPath); | 23 db.setDatabaseName(dbPath); |
| 17 if (!db.open()) | 24 if (!db.open()) |
| 18 throw | 25 throw |
| 19 IOException(QString("Unable to open SQLite database with path '%1'") | 26 IOException(QString("Unable to open SQLite database with path '%1'") |
| 20 .arg(dbPath)); | 27 .arg(dbPath)); |
