#include "stdafx.h" #include "OtlDB.h" #include "OtlConnHost.h" COtlRecordset::COtlRecordset( COtlConnHost* pConnHost ) : m_pOtlConnHost( pConnHost ) { m_pStream = NULL; } COtlRecordset::~COtlRecordset()throw() { if( m_pStream != NULL ) { m_Iterator.detach(); //释放迭代器 delete m_pStream; m_pStream = NULL; } } /***************************************************************** **【函数名称】 InitData **【函数功能】 初始化记录集初始数据 **【参数】 lpszSQL SQL查询语句 **【返回值】 *****************************************************************/ BOOL COtlRecordset::__InitData( LPCTSTR lpszSQL ) { BOOL bResult = m_pOtlConnHost->InitOtlStream( lpszSQL, &m_pStream, &m_Iterator ); return bResult; } /***************************************************************** **【函数名称】 DestroyInstance **【函数功能】 释放一个记录集实例(接口静态函数实现) **【参数】 pRecord 要释放的记录集实例 **【返回值】 *****************************************************************/ void OTL_RECORD_SET::DestroyInstance( OTL_RECORD_SET* pRecord ) { if( pRecord ) { delete pRecord; pRecord = NULL; } } /***************************************************************** **【函数名称】 IsEOF **【函数功能】 是否已遍历到记录保结尾 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::IsEOF( void ) { return m_pOtlConnHost->IsEOF( m_pStream ); } /***************************************************************** **【函数名称】 GetLastError **【函数功能】 获取最近一次错误信息 **【参数】 **【返回值】 *****************************************************************/ LPCTSTR COtlRecordset::GetLastError( void ) { return m_pOtlConnHost->GetLastError(); } /***************************************************************** **【函数名称】 MoveNextRow **【函数功能】 移动记录集到下一行 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::MoveNextRow( void ) { return m_pOtlConnHost->MoveNextRow( &m_Iterator ); } /***************************************************************** **【函数名称】 GetValueInt **【函数功能】 获取指定字段值 整形 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::GetValueInt( char *pColName, int &nValue ) { return m_pOtlConnHost->GetValueInt( &m_Iterator, pColName, nValue ); } /***************************************************************** **【函数名称】 GetValueStr **【函数功能】 获取指定字段值 字符串 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::GetValueStr( char *pColName, char *pValue ) { return m_pOtlConnHost->GetValueString( &m_Iterator, pColName, pValue ); } /***************************************************************** **【函数名称】 GetValueText **【函数功能】 获取指定字段值 较大文本值 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::GetValueText( char *pColName, char *pValue ) { return m_pOtlConnHost->GetValueText( &m_Iterator, pColName, pValue ); } /***************************************************************** **【函数名称】 GetValueFloat **【函数功能】 获取指定字段值 浮点 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::GetValueFloat( char *pColName, float &Value ) { return m_pOtlConnHost->GetValueFloat( &m_Iterator, pColName, Value ); } /***************************************************************** **【函数名称】 GetValueIntByIndex **【函数功能】 通过字段ID获取整型记录 **【参数】 **【返回值】 *****************************************************************/ int COtlRecordset::GetValueIntByIndex( int index ) { int nValue; BOOL bResult = m_pOtlConnHost->GetValueIntByIndex( &m_Iterator, index, nValue ); if( bResult ) { return nValue; } return -1; } /***************************************************************** **【函数名称】 GetValueInt **【函数功能】 通过字段名称获取整型记录 **【参数】 **【返回值】 *****************************************************************/ int COtlRecordset::GetValueInt( CString FieldName ) { int nValue; BOOL bResult = m_pOtlConnHost->GetValueInt( &m_Iterator, FieldName.GetBuffer( 0 ), nValue ); if( bResult ) { return nValue; } return -1; } /***************************************************************** **【函数名称】 GetValueStrByIndex **【函数功能】 通过字段ID获取字符串记录 **【参数】 字段索引 **【返回值】 字段对应的字符串 *****************************************************************/ CString COtlRecordset::GetValueStrByIndex( int index ) // 通过字段ID获取字符串记录 { CHAR buff[MAX_DB_DATA_BUFFER_LEN] = { 0 }; CString strValue = ""; BOOL bResult = m_pOtlConnHost->GetValueStrByIndex( &m_Iterator, index, buff ); if( bResult ) { strValue.Format( "%s", buff ); return strValue; } return ""; } /***************************************************************** **【函数名称】 GetValueFloatByIndex **【函数功能】 通过字段ID获取浮点记录 **【参数】 **【返回值】 *****************************************************************/ BOOL COtlRecordset::GetValueFloatByIndex( int index, float &Value ) { return m_pOtlConnHost->GetValueFloatByIndex( &m_Iterator, index, Value ); } /***************************************************************** **【函数名称】 GetValueStr **【函数功能】 通过字段ID获取字符串记录 **【参数】 字段名称 **【返回值】 *****************************************************************/ CString COtlRecordset::GetValueStr( CString FieldName ) { CHAR buff[MAX_DB_DATA_BUFFER_LEN] = { 0 }; CString strValue = ""; BOOL bResult = m_pOtlConnHost->GetValueString( &m_Iterator, FieldName.GetBuffer( 0 ), buff ); if( bResult ) { strValue.Format( "%s", buff ); return strValue; } return ""; }