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

//	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

/* 
*	Types of driver to connect to the database.
*/
enum eClientDriverType
{
	eMDAC,
	eSNAC
};
/*
*	String representation of driver types.
*/
const char szClientDriverTypeStr[2][5] = {"MDAC", "SNAC"};

/*
*	Class representing a database connection for all transaction database classes.
*/

class CDBConnection
{
protected:
	
	SQLHSTMT		m_hstmt;			// the current hstmt

	//Prepares statement handle for executing another SQL statement
	void CleanupStmt()
	{
		SQLCloseCursor(m_hstmt);
		SQLFreeStmt(m_hstmt, SQL_RESET_PARAMS);
		SQLFreeStmt(m_hstmt, SQL_UNBIND);
	}

public:
	SQLHENV			m_henv;				// ODBC environment handle
	SQLHDBC			m_hdbc;

	CDBConnection(const char *szServer, const char *szDatabase, eClientDriverType eClientType);
	~CDBConnection();

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

	// Set connection options
	void InitConnection();

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