Classes | Functions

querythread.h File Reference

#include "querythreadcommand.h"
#include <QMutex>
#include <QQueue>
#include <QObject>
#include <QThread>
#include <QVariant>
#include "libpq-fe.h"
Include dependency graph for querythread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  QueryThreadConnSpecs
 QueryThreadConnSpecs is a command struct used to pass the connection specs. More...
class  QueryQueue
 QueryQueue is used by QueryWorker to extract the QueryThreadCommand and query with it the database. More...
class  QueryWorker
 The class that does all the work with the database. More...
class  QueryThread
 This is the thread in which QueryWorker works. More...

Functions

QSqlDatabase createConnection (const QueryThreadConnSpecs &specs, const char *connName)
void connectToDatabase (QSqlDatabase db)
 Q_DECLARE_METATYPE (PGconn *)

Function Documentation

void connectToDatabase ( QSqlDatabase  db  ) 

Local function to open a connections.

Referenced by QueryWorker::slotExecute().

{
    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.

Referenced by QueryWorker::QueryWorker().

{
    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;
}

Q_DECLARE_METATYPE ( PGconn *   )