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

/*
*	Checkpoint database class that uses stored procedures for individual frames.
*/

#include "stdafx.h"

using namespace TPCE;

CCheckpointDB::CCheckpointDB(CDBConnection *pDBConn)
: CTxnHarnessDBBase(pDBConn)
{	
	//Allocate one handle per stored procedure (frame)
	if (SQLAllocHandle(SQL_HANDLE_STMT, m_hdbc, &m_hstmtFrame1) != SQL_SUCCESS)
		ThrowError(CODBCERR::eAllocHandle, SQL_HANDLE_STMT, m_hdbc);	
};

CCheckpointDB::~CCheckpointDB()
{
	SQLFreeHandle(SQL_HANDLE_STMT, m_hstmtFrame1);
}

void CCheckpointDB::DoCheckpointFrame1(const TCheckpointInput *pInput)
{
	int			rc;	
	char		szCmd[256];

	// Form the command.
	//
	if (pInput->lDuration > 0)
	{
		_snprintf(&szCmd[0], sizeof(szCmd), "CHECKPOINT %d", pInput->lDuration);		
	}
	else
	{
		_snprintf(&szCmd[0], sizeof(szCmd), "CHECKPOINT");
	}

	rc = SQLExecDirect(m_hstmtFrame1, 
						(SQLCHAR*)szCmd, SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
		ThrowError(CODBCERR::eExecDirect, SQL_HANDLE_STMT, m_hstmtFrame1, "DoCheckpointFrame1");	
};