#include <QSqlDatabase>#include <QObject>#include "querythread.h"#include "progresswidget.h"#include <QSqlQueryModel>#include <QSqlRelationalTableModel>#include <QWidget>

Go to the source code of this file.
Classes | |
| class | Database |
| The main database object used throughout the program. More... | |
| class | SqlHelper |
| Has some extra functions used by the custom SQL model classes. More... | |
| class | SqlQueryModel |
| Extension of QSqlQueryModel class and used throughout the application. More... | |
| class | SqlTableModel |
| Extension of QSqlTableModel class and used throughout the application. More... | |
| class | DatabaseAuditLogView |
| View used to show audit logs. More... | |
Functions | |
| QSqlDatabase | createConnection (const QueryThreadConnSpecs &specs, const char *connName) |
| void | connectToDatabase (QSqlDatabase db) |
| void connectToDatabase | ( | QSqlDatabase | db | ) |
Local function to open a connections.
{
static QMutex mutex;
QMutexLocker lock(&mutex);
qDebug() << "Opening connection " << db.connectionName() << " ...";
if (db.open())
{
qDebug() << "Connection " << db.connectionName() << " was successfully established with the server.";
Q_ASSERT(db.driver()->hasFeature(QSqlDriver::QuerySize));
Q_ASSERT(db.driver()->hasFeature(QSqlDriver::Transactions));
Q_ASSERT(db.driver()->hasFeature(QSqlDriver::PreparedQueries));
//Q_ASSERT(db.driver()->hasFeature(QSqlDriver::BatchOperations));
Q_ASSERT(db.driver()->hasFeature(QSqlDriver::EventNotifications));
//config
db.exec("SET search_path TO \"$user\",public,application,application_deprecated");
}
else
{
qWarning() << "Unable to connect to database:" << db.lastError().text();
}
}
| QSqlDatabase createConnection | ( | const QueryThreadConnSpecs & | specs, | |
| const char * | connName | |||
| ) |
Local function to setup connection parameteres.
{
static QMutex mutex;
QMutexLocker lock(&mutex);
qDebug() << "Creating database connection " << connName << " ...";
QSqlDatabase db = QSqlDatabase::addDatabase(specs.driver, connName);
db.setDatabaseName(specs.dbName);
db.setHostName(specs.host);
db.setPort(specs.port);
db.setUserName(specs.user);
db.setPassword(specs.passwd);
if (specs.driver == "QPSQL"){
db.setConnectOptions("connect_timeout = 1");
}
Q_ASSERT(!db.isOpen());
return db;
}
1.7.1