多数据源中间件标准版1.0

OtlRecordset.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #include "stdafx.h"
  2. #include "OtlDB.h"
  3. #include "OtlConnHost.h"
  4. COtlRecordset::COtlRecordset( COtlConnHost* pConnHost )
  5. : m_pOtlConnHost( pConnHost )
  6. {
  7. m_pStream = NULL;
  8. }
  9. COtlRecordset::~COtlRecordset()throw()
  10. {
  11. if( m_pStream != NULL )
  12. {
  13. m_Iterator.detach(); //释放迭代器
  14. delete m_pStream;
  15. m_pStream = NULL;
  16. }
  17. }
  18. /*****************************************************************
  19. **【函数名称】 InitData
  20. **【函数功能】 初始化记录集初始数据
  21. **【参数】 lpszSQL SQL查询语句
  22. **【返回值】
  23. *****************************************************************/
  24. BOOL COtlRecordset::__InitData( LPCTSTR lpszSQL )
  25. {
  26. BOOL bResult = m_pOtlConnHost->InitOtlStream( lpszSQL, &m_pStream, &m_Iterator );
  27. return bResult;
  28. }
  29. /*****************************************************************
  30. **【函数名称】 DestroyInstance
  31. **【函数功能】 释放一个记录集实例(接口静态函数实现)
  32. **【参数】 pRecord 要释放的记录集实例
  33. **【返回值】
  34. *****************************************************************/
  35. void OTL_RECORD_SET::DestroyInstance( OTL_RECORD_SET* pRecord )
  36. {
  37. if( pRecord )
  38. {
  39. delete pRecord;
  40. pRecord = NULL;
  41. }
  42. }
  43. /*****************************************************************
  44. **【函数名称】 IsEOF
  45. **【函数功能】 是否已遍历到记录保结尾
  46. **【参数】
  47. **【返回值】
  48. *****************************************************************/
  49. BOOL COtlRecordset::IsEOF( void )
  50. {
  51. return m_pOtlConnHost->IsEOF( m_pStream );
  52. }
  53. /*****************************************************************
  54. **【函数名称】 GetLastError
  55. **【函数功能】 获取最近一次错误信息
  56. **【参数】
  57. **【返回值】
  58. *****************************************************************/
  59. LPCTSTR COtlRecordset::GetLastError( void )
  60. {
  61. return m_pOtlConnHost->GetLastError();
  62. }
  63. /*****************************************************************
  64. **【函数名称】 MoveNextRow
  65. **【函数功能】 移动记录集到下一行
  66. **【参数】
  67. **【返回值】
  68. *****************************************************************/
  69. BOOL COtlRecordset::MoveNextRow( void )
  70. {
  71. return m_pOtlConnHost->MoveNextRow( &m_Iterator );
  72. }
  73. /*****************************************************************
  74. **【函数名称】 GetValueInt
  75. **【函数功能】 获取指定字段值 整形
  76. **【参数】
  77. **【返回值】
  78. *****************************************************************/
  79. BOOL COtlRecordset::GetValueInt( char *pColName, int &nValue )
  80. {
  81. return m_pOtlConnHost->GetValueInt( &m_Iterator, pColName, nValue );
  82. }
  83. /*****************************************************************
  84. **【函数名称】 GetValueStr
  85. **【函数功能】 获取指定字段值 字符串
  86. **【参数】
  87. **【返回值】
  88. *****************************************************************/
  89. BOOL COtlRecordset::GetValueStr( char *pColName, char *pValue )
  90. {
  91. return m_pOtlConnHost->GetValueString( &m_Iterator, pColName, pValue );
  92. }
  93. /*****************************************************************
  94. **【函数名称】 GetValueText
  95. **【函数功能】 获取指定字段值 较大文本值
  96. **【参数】
  97. **【返回值】
  98. *****************************************************************/
  99. BOOL COtlRecordset::GetValueText( char *pColName, char *pValue )
  100. {
  101. return m_pOtlConnHost->GetValueText( &m_Iterator, pColName, pValue );
  102. }
  103. /*****************************************************************
  104. **【函数名称】 GetValueFloat
  105. **【函数功能】 获取指定字段值 浮点
  106. **【参数】
  107. **【返回值】
  108. *****************************************************************/
  109. BOOL COtlRecordset::GetValueFloat( char *pColName, float &Value )
  110. {
  111. return m_pOtlConnHost->GetValueFloat( &m_Iterator, pColName, Value );
  112. }
  113. /*****************************************************************
  114. **【函数名称】 GetValueIntByIndex
  115. **【函数功能】 通过字段ID获取整型记录
  116. **【参数】
  117. **【返回值】
  118. *****************************************************************/
  119. int COtlRecordset::GetValueIntByIndex( int index )
  120. {
  121. int nValue;
  122. BOOL bResult = m_pOtlConnHost->GetValueIntByIndex( &m_Iterator, index, nValue );
  123. if( bResult )
  124. {
  125. return nValue;
  126. }
  127. return -1;
  128. }
  129. /*****************************************************************
  130. **【函数名称】 GetValueInt
  131. **【函数功能】 通过字段名称获取整型记录
  132. **【参数】
  133. **【返回值】
  134. *****************************************************************/
  135. int COtlRecordset::GetValueInt( CString FieldName )
  136. {
  137. int nValue;
  138. BOOL bResult = m_pOtlConnHost->GetValueInt( &m_Iterator, FieldName.GetBuffer( 0 ), nValue );
  139. if( bResult )
  140. {
  141. return nValue;
  142. }
  143. return -1;
  144. }
  145. /*****************************************************************
  146. **【函数名称】 GetValueStrByIndex
  147. **【函数功能】 通过字段ID获取字符串记录
  148. **【参数】 字段索引
  149. **【返回值】 字段对应的字符串
  150. *****************************************************************/
  151. CString COtlRecordset::GetValueStrByIndex( int index ) // 通过字段ID获取字符串记录
  152. {
  153. CHAR buff[MAX_DB_DATA_BUFFER_LEN] = { 0 };
  154. CString strValue = "";
  155. BOOL bResult = m_pOtlConnHost->GetValueStrByIndex( &m_Iterator, index, buff );
  156. if( bResult )
  157. {
  158. strValue.Format( "%s", buff );
  159. return strValue;
  160. }
  161. return "";
  162. }
  163. /*****************************************************************
  164. **【函数名称】 GetValueFloatByIndex
  165. **【函数功能】 通过字段ID获取浮点记录
  166. **【参数】
  167. **【返回值】
  168. *****************************************************************/
  169. BOOL COtlRecordset::GetValueFloatByIndex( int index, float &Value )
  170. {
  171. return m_pOtlConnHost->GetValueFloatByIndex( &m_Iterator, index, Value );
  172. }
  173. /*****************************************************************
  174. **【函数名称】 GetValueStr
  175. **【函数功能】 通过字段ID获取字符串记录
  176. **【参数】 字段名称
  177. **【返回值】
  178. *****************************************************************/
  179. CString COtlRecordset::GetValueStr( CString FieldName )
  180. {
  181. CHAR buff[MAX_DB_DATA_BUFFER_LEN] = { 0 };
  182. CString strValue = "";
  183. BOOL bResult = m_pOtlConnHost->GetValueString( &m_Iterator, FieldName.GetBuffer( 0 ), buff );
  184. if( bResult )
  185. {
  186. strValue.Format( "%s", buff );
  187. return strValue;
  188. }
  189. return "";
  190. }