#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include "connectoracle.h"
#include <stdlib.h>
int main(int argc, char *argv[])
{
qWarning("Executing ConnectionTester");
ConnectOracle nmb;
//a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
#include "connectoracle.h"
#include <qsqlrecord.h>
ConnectOracle::ConnectOracle()
{
int ProcessingFreq;
EstablishOracleConnection();
IdleTimer
= new QTimer( this);
ProcessingFreq = 5000; //Default is 3 seconds
connect( IdleTimer, SIGNAL(timeout()), this, SLOT(IdleTimerTimeout()) );
IdleTimer->start( ProcessingFreq, TRUE );
qWarning("Timer initialization complete.");
}
ConnectOracle::~ConnectOracle()
{
}
void ConnectOracle::IdleTimerTimeout()
{
//Check if there are any messages on either the Notes or TCA table
if (DBReconnect())
{
;
}
IdleTimer->start( 5000, TRUE );
}
bool ConnectOracle::EstablishOracleConnection()
{
siteName = getenv("OMS_DB");
userName = getenv("OMS_USER");
passWord = getenv("OMS_PWD");
hostname = getenv("OMS_HOST");
oracledb->setDatabaseName( siteName );
oracledb->setUserName( userName );
oracledb->setPassword( passWord );
oracledb->setHostName( hostname );
if ( ! oracledb->open() )
{
qWarning( "Failed to open database: " + oracledb->lastError().text() );
return FALSE;
}
else
{
qDebug("Oracle connection successful");
//setup queries
//PrepareSql();
}
return(true);
}
bool ConnectOracle::DBReconnect()
{
tabname = "Notes_Messages";
//temp = omsdb->recordInfo ( "Notes_Messages" );
qWarning( "DBReconnect: " + omsdb->lastError().text() );
if (omsdb->isOpenError())
qWarning( "Database connection failed: " + omsdb->lastError().text() );
if ( !omsdb->isOpen() )
{
qDebug("Error: Database connection has been lost. Attempting reconnect.");
if (!omsdb->open())
{
qWarning( "Failed to open database: " + omsdb->lastError().text() );
return FALSE;
}
else
{
qWarning("Database reconnect successful.");
//PrepareSql();
}
}
return(TRUE);
}
#ifndef CONNECTORACLE_H
#define CONNECTORACLE_H
#include <qtimer.h>
#include <qsqldatabase.h>
/**
@author Rick Burge
*/
class ConnectOracle
: public QObject{
Q_OBJECT
public:
ConnectOracle();
~ConnectOracle();
private:
bool DBReconnect();
bool EstablishOracleConnection();
private slots:
virtual void IdleTimerTimeout();
};
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include "connectoracle.h"
#include <stdlib.h>
int main(int argc, char *argv[])
{
qWarning("Executing ConnectionTester");
QApplication a( argc, argv );
ConnectOracle nmb;
//a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
#include "connectoracle.h"
#include <qsqlrecord.h>
ConnectOracle::ConnectOracle()
{
int ProcessingFreq;
EstablishOracleConnection();
IdleTimer = new QTimer( this);
ProcessingFreq = 5000; //Default is 3 seconds
connect( IdleTimer, SIGNAL(timeout()), this, SLOT(IdleTimerTimeout()) );
IdleTimer->start( ProcessingFreq, TRUE );
qWarning("Timer initialization complete.");
}
ConnectOracle::~ConnectOracle()
{
}
void ConnectOracle::IdleTimerTimeout()
{
//Check if there are any messages on either the Notes or TCA table
if (DBReconnect())
{
;
}
IdleTimer->start( 5000, TRUE );
}
bool ConnectOracle::EstablishOracleConnection()
{
QString siteName;
QString userName;
QString passWord;
QString hostname;
siteName = getenv("OMS_DB");
userName = getenv("OMS_USER");
passWord = getenv("OMS_PWD");
hostname = getenv("OMS_HOST");
oracledb = QSqlDatabase::addDatabase( "QOCI8", "OMSDB" );
oracledb->setDatabaseName( siteName );
oracledb->setUserName( userName );
oracledb->setPassword( passWord );
oracledb->setHostName( hostname );
if ( ! oracledb->open() )
{
qWarning( "Failed to open database: " + oracledb->lastError().text() );
omsdb = QSqlDatabase::database("OMSDB" );
return FALSE;
}
else
{
qDebug("Oracle connection successful");
omsdb = QSqlDatabase::database("OMSDB" );
//setup queries
//PrepareSql();
}
return(true);
}
bool ConnectOracle::DBReconnect()
{
QString tabname;
tabname = "Notes_Messages";
QSqlRecord temp = omsdb->record( tabname );
//temp = omsdb->recordInfo ( "Notes_Messages" );
qWarning( "DBReconnect: " + omsdb->lastError().text() );
if (omsdb->isOpenError())
qWarning( "Database connection failed: " + omsdb->lastError().text() );
if ( !omsdb->isOpen() )
{
qDebug("Error: Database connection has been lost. Attempting reconnect.");
if (!omsdb->open())
{
qWarning( "Failed to open database: " + omsdb->lastError().text() );
return FALSE;
}
else
{
qWarning("Database reconnect successful.");
//PrepareSql();
}
}
return(TRUE);
}
#ifndef CONNECTORACLE_H
#define CONNECTORACLE_H
#include <qtimer.h>
#include <qsqldatabase.h>
/**
@author Rick Burge
*/
class ConnectOracle: public QObject
{
Q_OBJECT
public:
ConnectOracle();
~ConnectOracle();
private:
bool DBReconnect();
bool EstablishOracleConnection();
QTimer *IdleTimer;
QSqlDatabase *omsdb;
QSqlDatabase *oracledb;
private slots:
virtual void IdleTimerTimeout();
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks