WxAdoImpl.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #include "StdAfx.h"
  2. #include "WxAdoImpl.h"
  3. #include "WxAdoPool.h"
  4. #include "table.pb.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #endif
  8. #define GETDBPTR(dwTimeOut) \
  9. pAdoObj pObj = NULL;\
  10. CAdoConnGuard tagConnGuard(pObj, dwTimeOut);\
  11. if ( pObj == NULL)\
  12. return FALSE\
  13. enum UserLogInStatus
  14. {
  15. USER_LOGIN = 1, // 登录成功;
  16. USER_PW_MISTAKE = 2, // 密码错误;
  17. USER_NULL = 0 // 没有用户;
  18. };
  19. CWxAdoImpl* CWxAdoImpl::m_pInstance = NULL;
  20. CWxAdoImpl::CWxAdoImpl(void):m_nRef(0),m_nObjRef(0)
  21. {
  22. // 全局uid,64位整型,转字符长度17位;
  23. m_uniqueid.setWorkerId(10);
  24. m_uniqueid.setDatacenterId(20);
  25. }
  26. CWxAdoImpl::~CWxAdoImpl(void)
  27. {
  28. }
  29. ULONG CWxAdoImpl::AddRef()
  30. {
  31. InterlockedIncrement( &m_nRef ); //增加引用计数;
  32. return m_nRef;
  33. }
  34. ULONG CWxAdoImpl::Release()
  35. {
  36. InterlockedDecrement( &m_nRef ); //减少引用计数;
  37. //如果为0,删除对象
  38. if( m_nRef == 0 )
  39. {
  40. delete this;
  41. }
  42. return m_nRef;
  43. }
  44. HRESULT CWxAdoImpl::QueryInterface(REFIID refiid, void **ppvObject)
  45. {
  46. if (IID_IUnknown == refiid)
  47. {
  48. *ppvObject = this;
  49. }
  50. else if (IID_IWxAdoInterface == refiid)
  51. {
  52. *ppvObject = (IWxAdoInterface*)this;
  53. }
  54. else
  55. {
  56. *ppvObject = NULL;
  57. return E_NOINTERFACE;
  58. }
  59. ((IUnknown*)(*ppvObject))->AddRef();
  60. return NOERROR;
  61. }
  62. /************************************************************************/
  63. /* 函数:[9/25/2016 IT];
  64. /* 描述:;
  65. /* 参数:;
  66. /* [IN] :;
  67. /* [OUT] :;
  68. /* [IN/OUT] :;
  69. /* 返回:void;
  70. /* 注意:;
  71. /* 示例:;
  72. /*
  73. /* 修改:;
  74. /* 日期:;
  75. /* 内容:;
  76. /************************************************************************/
  77. void CWxAdoImpl::SolveDBError( IN CONST DWORD &dwError, IN LPVOID pDBConn)
  78. {
  79. switch(dwError)
  80. {
  81. //case SQL_ERROR://这个错误比较难精确判断问题;
  82. case ERROR_PIPE_NOT_CONNECTED:
  83. case WSAECONNRESET:
  84. case WSAECONNABORTED:
  85. {
  86. pAdoObj pObj = (pAdoObj)pDBConn;
  87. CWxAdoPool::GetInstance()->CloseBusyConnection(pObj);
  88. #if _DEBUG
  89. OutputDebugString(_T("关闭数据库连接\n"));
  90. #endif
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. //template<typename T>
  98. //BOOL CWxAdoImpl::GetFiedValue(IN _RecordsetPtr rst, IN LPCTSTR lpFiedName, T &value)
  99. //{
  100. // typeid(value);
  101. // _variant_t var = rst->GetCollect(lpFiedName);
  102. //switch(var.vt)
  103. //{
  104. //case VT_EMPTY:
  105. // break;
  106. //case VT_NULL:
  107. // break;
  108. //case VT_I2://2 byte signed int
  109. // value = var.iVal;
  110. // break;
  111. //case VT_I4://4 byte signed int
  112. // value = var.iVal;
  113. // break;
  114. //case VT_R4://4 byte real
  115. // value = var.fltVal;
  116. // break;
  117. //case VT_R8://8 byte real
  118. // value = var.dblVal;
  119. // break;
  120. //case VT_CY://currency
  121. // break;
  122. //case VT_DATE:
  123. // {
  124. // COleDateTime dt(var);
  125. // value = dt.Format(_T("%Y-%m-%d %H:%M:%S"));
  126. // }
  127. // break;
  128. //case VT_BSTR://OLE Automation string
  129. // value = _bstr_t(var.bstrVal);
  130. // break;
  131. //case VT_DISPATCH://IDispatch *
  132. // break;
  133. //case VT_ERROR://SCODE
  134. // break;
  135. //case VT_BOOL://True=-1, False=0
  136. // value = var.boolVal;
  137. // break;
  138. //case VT_VARIANT://VARIANT *
  139. // break;
  140. //case VT_UNKNOWN://IUnknown *
  141. // break;
  142. //case VT_DECIMAL://16 byte fixed point
  143. // break;
  144. //case VT_RECORD://user defined type
  145. // break;
  146. //case VT_I1: // signed char
  147. // value = var.pcVal;
  148. // break;
  149. //case VT_UI1://unsigned char
  150. // value = var.bVal;
  151. // break;
  152. //case VT_UI2://unsigned short
  153. // value = var.uiVal;
  154. // break;
  155. //case VT_UI4://unsigned long
  156. // value = var.uiVal;
  157. // break;
  158. //case VT_I8://signed 64-bit int
  159. // value = var.lVal;
  160. // break;
  161. //case VT_UI8://unsigned 64-bit int
  162. // value = var.ulVal;
  163. // break;
  164. //case VT_INT://signed machine int
  165. // value = var.intVal;
  166. // break;
  167. //case VT_UINT://unsigned machine int
  168. // value = var.uintVal;
  169. // break;
  170. //case VT_INT_PTR://signed machine register size width
  171. // break;
  172. //case VT_UINT_PTR://unsigned machine register size width
  173. // break;
  174. //case VT_VOID://C style void
  175. // break;
  176. //case VT_HRESULT://Standard return type
  177. // break;
  178. //case VT_PTR://pointer type
  179. // break;
  180. //case VT_SAFEARRAY://(use VT_ARRAY in VARIANT)
  181. // break;
  182. //case VT_CARRAY://C style array
  183. // break;
  184. //case VT_USERDEFINED://user defined type
  185. // break;
  186. //case VT_LPSTR://null terminated string
  187. // break;
  188. //case VT_LPWSTR://wide null terminated string
  189. // break;
  190. //case VT_FILETIME://FILETIME
  191. // break;
  192. //case VT_BLOB://Length prefixed bytes
  193. // break;
  194. //case VT_STREAM://Name of the stream follows
  195. // break;
  196. //case VT_STORAGE://Name of the storage follows
  197. // break;
  198. //case VT_STREAMED_OBJECT://Stream contains an object
  199. // break;
  200. //case VT_STORED_OBJECT://Storage contains an object
  201. // break;
  202. //case VT_VERSIONED_STREAM://Stream with a GUID version
  203. // break;
  204. //case VT_BLOB_OBJECT://Blob contains an object
  205. // break;
  206. //case VT_CF://Clipboard format
  207. // break;
  208. //case VT_CLSID://A Class ID
  209. // break;
  210. //case VT_VECTOR://simple counted array
  211. // break;
  212. //case VT_ARRAY://SAFEARRAY*
  213. // break;
  214. //case VT_BYREF://void* for local use
  215. // break;
  216. //case VT_BSTR_BLOB://Reserved for system use
  217. // break;
  218. //default:
  219. // value = var.iVal;
  220. //}
  221. // return TRUE;
  222. //}
  223. /************************************************************************/
  224. /* 函数:[9/25/2016 IT];
  225. /* 描述:;
  226. /* 参数:;
  227. /* [IN] :;
  228. /* [OUT] :;
  229. /* [IN/OUT] :;
  230. /* 返回:void;
  231. /* 注意:;
  232. /* 示例:;
  233. /*
  234. /* 修改:;
  235. /* 日期:;
  236. /* 内容:;
  237. /************************************************************************/
  238. DWORD CWxAdoImpl::InitializePool( IN LPCTSTR lpDBType, IN LPCTSTR lpDBSource, IN CONST DWORD &dwDBPort, IN LPCTSTR lpDBAccount, IN LPCTSTR lpPassWord, IN LPCTSTR lpDBName, IN CONST INT &nMinConn /* = 1 */, IN CONST INT &nMaxConn /* = 5 */ )
  239. {
  240. return CWxAdoPool::GetInstance()->InitializePool(lpDBType, lpDBSource, dwDBPort, lpDBAccount, lpPassWord, lpDBName, nMinConn, nMaxConn);
  241. }
  242. /************************************************************************/
  243. /* 函数:[9/25/2016 IT];
  244. /* 描述:;
  245. /* 参数:;
  246. /* [IN] :;
  247. /* [OUT] :;
  248. /* [IN/OUT] :;
  249. /* 返回:void;
  250. /* 注意:;
  251. /* 示例:;
  252. /*
  253. /* 修改:;
  254. /* 日期:;
  255. /* 内容:;
  256. /************************************************************************/
  257. void CWxAdoImpl::ReleasePool()
  258. {
  259. CWxAdoPool *pObj = CWxAdoPool::GetInstance();
  260. if ( pObj )
  261. {
  262. pObj->ReleasePool();
  263. delete pObj;
  264. pObj = NULL;
  265. }
  266. }
  267. /************************************************************************/
  268. /* 函数:[9/25/2016 IT];
  269. /* 描述:;
  270. /* 参数:;
  271. /* [IN] :;
  272. /* [OUT] :;
  273. /* [IN/OUT] :;
  274. /* 返回:void;
  275. /* 注意:;
  276. /* 示例:;
  277. /*
  278. /* 修改:;
  279. /* 日期:;
  280. /* 内容:;
  281. /************************************************************************/
  282. BOOL CWxAdoImpl::ExecuteSQL( IN LPCTSTR lpExcuteSQL, IN CONST DWORD &dwTimeOut /* = 30000 */ )
  283. {
  284. GETDBPTR(dwTimeOut);
  285. try
  286. {
  287. if ( lpExcuteSQL == NULL || pObj == NULL )
  288. return FALSE;
  289. pObj->pCommand->CommandText = _bstr_t(lpExcuteSQL);
  290. // 执行SQL语句,返回记录集
  291. pObj->pCommand->Execute(NULL, NULL, adCmdText);
  292. }
  293. catch (_com_error &e)
  294. {
  295. _bstr_t bstrSource(e.Source());
  296. _bstr_t bstrDescription(e.Description());
  297. SolveDBError(e.Error(), pObj);
  298. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  299. return FALSE;
  300. }
  301. return TRUE;
  302. }
  303. /************************************************************************/
  304. /* 函数:[9/25/2016 IT];
  305. /* 描述:;
  306. /* 参数:;
  307. /* [IN] :;
  308. /* [OUT] :;
  309. /* [IN/OUT] :;
  310. /* 返回:void;
  311. /* 注意:;
  312. /* 示例:;
  313. /*
  314. /* 修改:;
  315. /* 日期:;
  316. /* 内容:;
  317. /************************************************************************/
  318. BOOL CWxAdoImpl::IsUserExist( IN LPCTSTR lpPhone, IN LPCTSTR lpPassword, OUT LPVOID lpOutValue,IN CONST DWORD &dwTimeOut /* = 3000 */ )
  319. {
  320. GETDBPTR(dwTimeOut);
  321. #if 0
  322. try
  323. {
  324. if ( lpPhone == NULL || lpPassword == NULL || pObj == NULL)
  325. return FALSE;
  326. CString strSql = _T("");
  327. strSql.Format(_T("select csr_id,csr_name,csr_phone,csr_gender,csr_password,csr_old_phone,csr_vcode,vcode_expiry_time,enable from customer where csr_phone = %s"), lpPhone);//用于是否转相片;
  328. pObj->pCommand->CommandText = _bstr_t(strSql);
  329. // 执行SQL语句,返回记录集
  330. _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText);
  331. tb_customer &customer = *(tb_customer*)lpOutValue;
  332. if(!rst->adoEOF)
  333. {
  334. customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal));
  335. customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal));
  336. customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  337. customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal));
  338. customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal));
  339. customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal));
  340. customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal));
  341. _variant_t var = rst->GetCollect(_T("vcode_expiry_time"));
  342. if (var.vt == VT_EMPTY || var.vt == VT_NULL)
  343. customer.set_customer_vcode_expiry_time(_T(""));
  344. else
  345. {
  346. COleDateTime dt(var);
  347. customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S")));
  348. }
  349. customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  350. }
  351. rst->Close();
  352. }
  353. catch (_com_error &e)
  354. {
  355. _bstr_t bstrSource(e.Source());
  356. _bstr_t bstrDescription(e.Description());
  357. SolveDBError(e.Error(), pObj);
  358. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  359. return FALSE;
  360. }
  361. #else // 参数化查询;
  362. try
  363. {
  364. if (lpPhone == NULL || lpPassword == NULL || pObj == NULL)
  365. return FALSE;
  366. _ParameterPtr QueryParam;
  367. QueryParam.CreateInstance(__uuidof(Parameter));
  368. QueryParam = pObj->pCommand->CreateParameter(_bstr_t(_T("csr_phone")), adBSTR, adParamInput, _tclen(lpPhone), lpPhone);
  369. pObj->pCommand->Parameters->Append(QueryParam);
  370. pObj->pCommand->CommandText = _bstr_t(_T("select csr_id,csr_name,csr_phone,csr_gender,csr_password,csr_old_phone,csr_vcode,vcode_expiry_time,enable from customer where csr_phone = ?"));
  371. // 执行SQL语句,返回记录集
  372. _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText);
  373. tb_customer &customer = *(tb_customer*)lpOutValue;
  374. if (!rst->adoEOF)
  375. {
  376. customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal));
  377. customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal));
  378. customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  379. customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal));
  380. customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal));
  381. customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal));
  382. customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal));
  383. _variant_t var = rst->GetCollect(_T("vcode_expiry_time"));
  384. if (var.vt == VT_EMPTY || var.vt == VT_NULL)
  385. customer.set_customer_vcode_expiry_time(_T(""));
  386. else
  387. {
  388. COleDateTime dt(var);
  389. customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S")));
  390. }
  391. customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  392. }
  393. rst->Close();
  394. pObj->pCommand->Parameters->Release();
  395. }
  396. catch (_com_error &e)
  397. {
  398. _bstr_t bstrSource(e.Source());
  399. _bstr_t bstrDescription(e.Description());
  400. SolveDBError(e.Error(), pObj);
  401. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  402. return FALSE;
  403. }
  404. #endif
  405. return TRUE;
  406. }
  407. INT CWxAdoImpl::QueryUserDetail(IN LPCTSTR lpPhone, IN LPVOID lpOutValue, IN const DWORD & dwTimeOut)
  408. {
  409. GETDBPTR(dwTimeOut);
  410. #if 0
  411. try
  412. {
  413. if (lpPhone == NULL || pObj == NULL)
  414. return FALSE;
  415. CString strSql = _T("");
  416. strSql.Format(_T("select csr_id,csr_name,csr_phone,csr_gender,csr_password,csr_old_phone,csr_vcode,vcode_expiry_time,enable from customer where csr_phone = %s"), lpPhone);//用于是否转相片;
  417. pObj->pCommand->CommandText = _bstr_t(strSql);
  418. // 执行SQL语句,返回记录集
  419. _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText);
  420. tb_customer &customer = *(tb_customer*)lpOutValue;
  421. if (!rst->adoEOF)
  422. {
  423. customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal));
  424. customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal));
  425. customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  426. customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal));
  427. customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal));
  428. customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal));
  429. customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal));
  430. _variant_t var = rst->GetCollect(_T("vcode_expiry_time"));
  431. if (var.vt == VT_EMPTY || var.vt == VT_NULL)
  432. customer.set_customer_vcode_expiry_time(_T(""));
  433. else
  434. {
  435. COleDateTime dt(var);
  436. customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S")));
  437. }
  438. customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  439. }
  440. rst->Close();
  441. }
  442. catch (_com_error &e)
  443. {
  444. _bstr_t bstrSource(e.Source());
  445. _bstr_t bstrDescription(e.Description());
  446. SolveDBError(e.Error(), pObj);
  447. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  448. return FALSE;
  449. }
  450. #else // 参数化查询;
  451. try
  452. {
  453. if (lpPhone == NULL || pObj == NULL)
  454. return FALSE;
  455. _ParameterPtr QueryParam;
  456. QueryParam.CreateInstance(__uuidof(Parameter));
  457. QueryParam = pObj->pCommand->CreateParameter(_bstr_t(_T("csr_phone")), adBSTR, adParamInput, _tclen(lpPhone), lpPhone);
  458. pObj->pCommand->Parameters->Append(QueryParam);
  459. pObj->pCommand->CommandText = _bstr_t(_T("select csr_id,csr_name,csr_phone,csr_gender,csr_password,csr_old_phone,csr_vcode,vcode_expiry_time,enable from customer where csr_phone = ?"));
  460. // 执行SQL语句,返回记录集
  461. _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText);
  462. tb_customer &customer = *(tb_customer*)lpOutValue;
  463. if (!rst->adoEOF)
  464. {
  465. customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal));
  466. customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal));
  467. customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  468. customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal));
  469. customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal));
  470. customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal));
  471. customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal));
  472. _variant_t var = rst->GetCollect(_T("vcode_expiry_time"));
  473. if (var.vt == VT_EMPTY || var.vt == VT_NULL)
  474. customer.set_customer_vcode_expiry_time(_T(""));
  475. else
  476. {
  477. COleDateTime dt(var);
  478. customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S")));
  479. }
  480. customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE);
  481. }
  482. rst->Close();
  483. pObj->pCommand->Parameters->Release();
  484. }
  485. catch (_com_error &e)
  486. {
  487. _bstr_t bstrSource(e.Source());
  488. _bstr_t bstrDescription(e.Description());
  489. SolveDBError(e.Error(), pObj);
  490. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  491. return FALSE;
  492. }
  493. #endif
  494. return TRUE;
  495. }
  496. BOOL CWxAdoImpl::AddCustomer(IN LPVOID lpCustomerInfo, IN const DWORD & dwTimeOut)
  497. {
  498. if (lpCustomerInfo == NULL)
  499. return FALSE;
  500. GETDBPTR(dwTimeOut);
  501. tb_customer &customer = *(tb_customer*)lpCustomerInfo;
  502. try
  503. {
  504. #if 1
  505. CString strSql = _T("");
  506. strSql.Format(_T("INSERT INTO customer(csr_id,csr_name,csr_phone,csr_gender,csr_password,csr_old_phone,csr_vcode,vcode_expiry_time,enable) "
  507. "VALUES('%s','%s','%s',%d,'%s','%s','%s','%s',%d) "),
  508. //customer.customer_id().c_str(),
  509. //[&]()->TCHAR* {
  510. // // 如果存在, 或者异常,新建spid;
  511. // TCHAR szUid[50] = { 0 };
  512. // _ui64tot_s(m_uniqueid.get_unique_id(), szUid, 50, 10);
  513. // return szUid;
  514. //}(),
  515. [&]()->TString {
  516. // 如果存在, 或者异常,新建spid;
  517. TCHAR szUid[50] = { 0 };
  518. _ui64tot_s(m_uniqueid.get_unique_id(), szUid, 50, 10);
  519. return TString(szUid);
  520. }().c_str(),
  521. customer.customer_name().c_str(),
  522. customer.customer_phone().c_str(),
  523. customer.customer_gender(),
  524. customer.customer_password().c_str(),
  525. customer.customer_old_phone().c_str(),
  526. customer.customer_vcode().c_str(),
  527. customer.customer_vcode_expiry_time().c_str(),
  528. customer.customer_enable()
  529. );
  530. pObj->pCommand->CommandText = _bstr_t(strSql);
  531. // 执行SQL语句,返回记录集
  532. _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText);
  533. if (!rst->adoEOF)
  534. {
  535. ;
  536. }
  537. rst->Close();
  538. #else
  539. #endif
  540. }
  541. catch (_com_error &e)
  542. {
  543. _bstr_t bstrSource(e.Source());
  544. _bstr_t bstrDescription(e.Description());
  545. SolveDBError(e.Error(), pObj);
  546. WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription);
  547. return FALSE;
  548. }
  549. return TRUE;
  550. }
  551. BOOL CWxAdoImpl::AddType(IN LPVOID lpStudioInfo, IN const DWORD & dwTimeOut)
  552. {
  553. return 0;
  554. }
  555. BOOL CWxAdoImpl::AddReply(IN LPVOID lpStudioInfo, IN const DWORD & dwTimeOut)
  556. {
  557. return 0;
  558. }
  559. BOOL CWxAdoImpl::UpdateCustomer(IN LPVOID lpCustomerInfo, IN const DWORD & dwTimeOut)
  560. {
  561. return 0;
  562. }