| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- #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 "";
- }
|