中间件底层,websocket

OtlConn.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #include "stdafx.h"
  2. #include "OtlConn.h"
  3. COtlConn::COtlConn() :m_pStream(nullptr), m_nField(0)
  4. {
  5. otl_connect::otl_initialize(1);
  6. }
  7. COtlConn::~COtlConn()
  8. {
  9. try
  10. {
  11. if (this->m_pStream) {
  12. delete this->m_pStream;
  13. this->m_pStream = nullptr;
  14. }
  15. if (this->m_OtlConn.connected) {
  16. this->m_OtlConn.logoff();
  17. }
  18. }
  19. catch (const otl_exception&)
  20. {
  21. }
  22. }
  23. bool COtlConn::ConnectDataBase(const CString & connStr, CString & ErrMessage)
  24. {
  25. try
  26. {
  27. m_OtlConn.rlogon(connStr, 1);
  28. return true;
  29. }
  30. catch (const otl_exception& e)
  31. {
  32. ErrMessage = e.msg;
  33. }
  34. return false;
  35. }
  36. //bool COtlConn::GetRecordSet(const CString & SQL, CString & ErrMessage)
  37. //{
  38. // try
  39. // {
  40. // if (this->m_pStream) {
  41. // delete this->m_pStream;
  42. // this->m_pStream = nullptr;
  43. // }
  44. // this->m_pStream = new otl_stream(1, SQL, m_OtlConn, otl_implicit_select);
  45. // if (!this->m_pStream->eof())
  46. // rs.attach(*this->m_pStream);
  47. // return true;
  48. // }
  49. // catch (const otl_exception& e)
  50. // {
  51. // ErrMessage = e.msg;
  52. // try
  53. // {
  54. // if (ErrMessage.Find("ÎÞЧµÄÓαê״̬") >= 0) {
  55. // if (this->m_pStream) {
  56. // delete this->m_pStream;
  57. // this->m_pStream = nullptr;
  58. // }
  59. // this->m_pStream = new otl_stream(1, SQL, m_OtlConn);
  60. // if (!this->m_pStream->eof())
  61. // rs.attach(*this->m_pStream);
  62. // return true;
  63. // }
  64. // }
  65. // catch (const otl_exception& e)
  66. // {
  67. // ErrMessage = e.msg;
  68. // }
  69. // }
  70. //
  71. // return false;
  72. //}
  73. bool COtlConn::GetRecordSet(const CString & SQL, CString & ErrMessage, const bool & IsSaveRs)
  74. {
  75. try
  76. {
  77. if (this->m_pStream) {
  78. delete this->m_pStream;
  79. this->m_pStream = nullptr;
  80. }
  81. if (!IsSaveRs) {
  82. this->m_pStream = new otl_stream(1, SQL, m_OtlConn);
  83. }
  84. else {
  85. this->m_pStream = new otl_stream(1, SQL, m_OtlConn, otl_implicit_select);
  86. }
  87. return true;
  88. }
  89. catch (const otl_exception& e)
  90. {
  91. ErrMessage = e.msg;
  92. }
  93. return false;
  94. }
  95. int COtlConn::GetFields()
  96. {
  97. try {
  98. //int nField = 1;
  99. //rs.describe(nField);
  100. return this->m_nField;
  101. }
  102. catch (const otl_exception&) {
  103. return 0;
  104. }
  105. }
  106. std::pair<std::list<std::vector<CString>>, bool> COtlConn::GetAllValues(CString & ErrMessage)
  107. {
  108. std::list<std::vector<CString>> lisRows;
  109. try {
  110. std::vector<CString> vecRow;
  111. int nField = 1;
  112. this->m_pStream->describe_select(nField);
  113. this->m_nField = nField;
  114. std::string strTemp = "";
  115. CString strTmp;
  116. while (!m_pStream->eof()) {
  117. vecRow.clear();
  118. for (int i = 0; i < nField; ++i) {
  119. otl_var_desc* desck = m_pStream->describe_next_out_var();
  120. switch (desck->ftype)
  121. {
  122. case otl_var_char:
  123. {
  124. *m_pStream >> strTemp;
  125. }
  126. break;
  127. case otl_var_double:
  128. case otl_var_float:
  129. {
  130. double dVal;
  131. *m_pStream >> dVal;
  132. strTemp = std::to_string(dVal);
  133. }
  134. break;
  135. case otl_var_int:
  136. case otl_var_unsigned_int:
  137. case otl_var_short:
  138. case otl_var_long_int:
  139. {
  140. std::int32_t nVal;
  141. *m_pStream >> nVal;
  142. strTemp = std::to_string(nVal);
  143. }
  144. break;
  145. case otl_var_timestamp:
  146. {
  147. otl_datetime dtTime;
  148. *m_pStream >> dtTime;
  149. char szTime[128];
  150. snprintf(szTime, 128, "%d-%02d-%02d %02d:%02d:%02d", dtTime.year, dtTime.month, dtTime.day, dtTime.hour, dtTime.minute, dtTime.second);
  151. strTemp = (szTime);
  152. }
  153. break;
  154. default:
  155. *m_pStream >> strTemp;
  156. break;
  157. }
  158. strTmp = strTemp.data();
  159. vecRow.emplace_back(strTmp);
  160. }
  161. lisRows.emplace_back(vecRow);
  162. }
  163. return std::make_pair(lisRows, true);
  164. }
  165. catch (const otl_exception& e) {
  166. ErrMessage = (char*)e.msg;
  167. return std::make_pair(lisRows, false);
  168. }
  169. }
  170. //std::pair<std::list<std::vector<CString>>, bool> COtlConn::GetAllValuesProc(CString & ErrMessage)
  171. //{
  172. // return std::pair<std::list<std::vector<CString>>, bool>();
  173. //}
  174. //
  175. //void COtlConn::close()
  176. //{
  177. // try
  178. // {
  179. // m_OtlConn.logoff();
  180. // }
  181. // catch (const otl_exception&)
  182. // {
  183. //
  184. // }
  185. //}
  186. //
  187. //bool COtlConn::GetValueStr(const int & nPos, CString & strValue, CString & ErrMessage)
  188. //{
  189. // try
  190. // {
  191. // int pos = nPos;
  192. // std::string strVal;
  193. // rs.get(nPos, strVal);
  194. // strValue = strVal.data();
  195. // return true;
  196. // }
  197. // catch (const otl_exception& e)
  198. // {
  199. // ErrMessage = e.msg;
  200. // }
  201. // return false;
  202. //}