//-------------------- CSPODBCConnection.h --------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef _CSPODBCCONNECTION
#define _CSPODBCCONNECTION

#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPODBCException.h"
#include <sql.h>
#include <sqlext.h>
#include "CSPTransaction.h"

class CSPODBC_CLASS_EXPORT CSPODBCConnection : public CSPTxObject
{
	friend class CSPODBCRecordset;

	public:
		CSPODBCConnection();
		CSPODBCConnection( const CSPTxObject& TxObj );
		CSPODBCConnection( const CSPTxContext& TxCtx );
		virtual ~CSPODBCConnection();

		bool Connect( const CSPString& strDSN, const CSPString& strUser = CSPString(), const CSPString& strPass = CSPString() );
		bool Disconnect();
		bool AutoCommit( bool bAuto = true );
		bool Rollback();
		bool Commit();
		const CSPString& GetLastErrorStr();
		bool IsConnected() const;
		
	protected:
		SQLHANDLE hEnv;
		SQLHANDLE hConn;
		bool bConnected;
		bool bAutoCommit;
		CSPString strLastError;

		void SetError( SQLSMALLINT shHandleType, SQLHDBC hHandle, int iIndex = 1 );
		void SetError( const CSPString& strErrorMsg );
		void ThrowError() const;

	private:
		CSPODBCConnection( const CSPODBCConnection& );
		CSPODBCConnection& operator =( const CSPODBCConnection& );
};


#endif
