// dbConnection.h: interface for the dbConnection class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DBCONNECTION_H__0CE8C125_EBDF_43CA_9C52_84266810DAED__INCLUDED_)
#define AFX_DBCONNECTION_H__0CE8C125_EBDF_43CA_9C52_84266810DAED__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <QThread.h>

class QSqlDatabase;

class dbConnection : public QThread  
{
public:
	QString lastError();
	QSqlDatabase* getDbase();
	void run();
	dbConnection(bool _isReserveEnabled = false, const QString dllId = NULL);
	virtual ~dbConnection();
	QString getCurrentDatabase();
	void lock();            // provide synchronization to the class bncs_log_getData
	void unlock();          //
	
	QString sDriver;
	QString sDatabase;
	QString sUser;
	QString sPassword;
	QString sHost;
	QString sDriver_reserve;
	QString sDatabase_reserve;
	QString sUser_reserve;
	QString sPassword_reserve;
	QString sHost_reserve;
	QString sName;
	QString sCurrentDriver;

private:
	QSqlDatabase * dBase;
	bool isReserveEnabled;  // if TRUE, and the connection to the main DB cannot be established, then try to connect to the reserve DB
	bool isReserve;	        // marks the if the current connection is for reserve or main DB
	QSemaphore* semaphore;  // for synchronization
};

#endif // !defined(AFX_DBCONNECTION_H__0CE8C125_EBDF_43CA_9C52_84266810DAED__INCLUDED_)
