forked from Sepanta/console-emulator
5 changed files with 62 additions and 13 deletions
@ -1,13 +1,19 @@ |
|||
#ifndef DatabaseManager_H |
|||
#define DatabaseManager_H |
|||
#ifndef DATABASEMANAGER_H |
|||
#define DATABASEMANAGER_H |
|||
|
|||
#include <QSqlDatabase> |
|||
#include <QDebug> |
|||
|
|||
class DatabaseManager |
|||
{ |
|||
private: |
|||
char _functionCode; |
|||
QSqlDatabase _db; |
|||
|
|||
public: |
|||
DatabaseManager(char functionCode); |
|||
DatabaseManager(const QString& databasePath); |
|||
~DatabaseManager(); |
|||
|
|||
QList<QVariant> getProbeIds(); |
|||
}; |
|||
|
|||
#endif //DatabaseManager_H
|
|||
#endif //DATABASEMANAGER_H
|
|||
|
@ -1,6 +1,47 @@ |
|||
#include "model/DatabaseManager.h" |
|||
|
|||
DatabaseManager::DatabaseManager(char functionCode) |
|||
#include <QDebug> |
|||
#include <QSqlQuery> |
|||
#include <QSqlError> |
|||
|
|||
DatabaseManager::DatabaseManager(const QString& databasePath) |
|||
{ |
|||
_db = QSqlDatabase::addDatabase("QSQLITE"); |
|||
_db.setDatabaseName(databasePath); |
|||
|
|||
if(!_db.open()) |
|||
{ |
|||
qDebug() << "Error: " << _db.lastError().text(); |
|||
} |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
DatabaseManager::~DatabaseManager() |
|||
{ |
|||
_functionCode = functionCode; |
|||
if(_db.isOpen()) |
|||
{ |
|||
_db.close(); |
|||
} |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
QList<QVariant> DatabaseManager::getProbeIds() |
|||
{ |
|||
QList<QVariant> globalIds; |
|||
|
|||
QSqlQuery query; |
|||
if(query.exec("SELECT globalId FROM Probe")) |
|||
{ |
|||
while(query.next()) |
|||
{ |
|||
QString globalId = query.value(0).toString(); |
|||
globalIds.append(QVariant(globalId)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
qDebug() << "Error executing query: " << query.lastError().text(); |
|||
} |
|||
|
|||
return globalIds; |
|||
} |
|||
|
Loading…
Reference in new issue