/*
*	©Copyright 2002, Microsoft Corporation
*	Written by Sergey Vasilevskiy, 2002-2005.
*/

//	Binding type of the program TIdent variables (corresponding to all integer ids)
//
#define SQL_C_IDENT		SQL_C_SBIGINT
//	Database type for IDENT_T metatype (all integer ids)
//
#define SQL_IDENT		SQL_BIGINT

// Exception class for all transaction logical errors.
//
#define ERR_TYPE_TPCE_TXN	100

class CTpceTxnErr : public TPCE::CBaseErr
{
public:
	enum Action
	{
		eNone = 0,
		eTradeIdRangeExhausted,
		Last
	};

	CTpceTxnErr(Action eAction, char const * szLocation)
	: TPCE::CBaseErr(eAction, szLocation)
	{
	}
	
	int ErrorType() {return ERR_TYPE_TPCE_TXN;}
	const char* ErrorText() const
	{
		static	char	*szMsgs[CTpceTxnErr::Last+1] = {
			(char*)"Success",
			(char*)"Range of available trade ids is exhausted.",
			(char*)"Error code above the range"
		};

		if (m_idMsg > CTpceTxnErr::Last)
			return szMsgs[CTpceTxnErr::Last];
		else
			return szMsgs[m_idMsg];
	}
};

/*
*	Superclass for all transaction database classes.
*/

class CTxnHarnessDBBase
{
protected:
	CDBConnection*	m_pDBConnection;	// reference to an external DB connection
	SQLHENV			m_henv;				// ODBC environment handle
	SQLHDBC			m_hdbc;
	//SQLHSTMT		m_hstmt;			// the current hstmt
	//int				m_tt_id[iTotalTradeTypeRows];	

public:	

	CTxnHarnessDBBase(CDBConnection *pDBConn);
	~CTxnHarnessDBBase();

	void ThrowError( TPCE::CODBCERR::ACTION eAction, SQLSMALLINT HandleType = 0, 
					SQLHANDLE Handle = SQL_NULL_HANDLE, const char* szLoc = NULL);	

	void StartTransaction(char *szIsoLevel="REPEATABLE READ");
	void StartTransactionReadCommitted();
	void Rollback();
	void CommitTransaction();	
};
