#include "StdAfx.h" #include "WxAdoImpl.h" #include "WxAdoPool.h" #include "table.pb.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #define GETDBPTR(dwTimeOut) \ pAdoObj pObj = NULL;\ CAdoConnGuard tagConnGuard(pObj, dwTimeOut);\ if ( pObj == NULL)\ return FALSE\ // 添加参数; auto AddSTRParameters = [](_CommandPtr cmd, LPCTSTR lpszFieldName, LPCTSTR lpszFieldValue)->BOOL { if (lpszFieldName == NULL || lpszFieldValue == NULL) return FALSE; _ParameterPtr param; param.CreateInstance(__uuidof(Parameter)); param = cmd->CreateParameter(_bstr_t(lpszFieldName), adBSTR, adParamInput, _tclen(lpszFieldValue), lpszFieldValue); cmd->Parameters->Append(param); return TRUE; }; auto AddIntParameters = [](_CommandPtr cmd, LPCTSTR lpszFieldName, int nFieldValue)->BOOL { if (lpszFieldName == NULL ) return FALSE; _ParameterPtr param; param.CreateInstance(__uuidof(Parameter)); param = cmd->CreateParameter(_bstr_t(lpszFieldName), adInteger, adParamInput, sizeof(nFieldValue), nFieldValue); cmd->Parameters->Append(param); return TRUE; }; auto AddBoolParameters = [](_CommandPtr cmd, LPCTSTR lpszFieldName, BOOL bFieldValue)->BOOL { if (lpszFieldName == NULL) return FALSE; _ParameterPtr param; param.CreateInstance(__uuidof(Parameter)); param = cmd->CreateParameter(_bstr_t(lpszFieldName), adBoolean, adParamInput, sizeof(bFieldValue), bFieldValue); cmd->Parameters->Append(param); return TRUE; }; enum UserLogInStatus { USER_LOGIN = 1, // 登录成功; USER_PW_MISTAKE = 2, // 密码错误; USER_NULL = 0 // 没有用户; }; CWxAdoImpl* CWxAdoImpl::m_pInstance = NULL; CWxAdoImpl::CWxAdoImpl(void):m_nRef(0),m_nObjRef(0) { // 全局uid,64位整型,转字符长度17位; m_uniqueid.setWorkerId(10); m_uniqueid.setDatacenterId(20); } CWxAdoImpl::~CWxAdoImpl(void) { } ULONG CWxAdoImpl::AddRef() { InterlockedIncrement( &m_nRef ); //增加引用计数; return m_nRef; } ULONG CWxAdoImpl::Release() { InterlockedDecrement( &m_nRef ); //减少引用计数; //如果为0,删除对象 if( m_nRef == 0 ) { delete this; } return m_nRef; } HRESULT CWxAdoImpl::QueryInterface(REFIID refiid, void **ppvObject) { if (IID_IUnknown == refiid) { *ppvObject = this; } else if (IID_IWxAdoInterface == refiid) { *ppvObject = (IWxAdoInterface*)this; } else { *ppvObject = NULL; return E_NOINTERFACE; } ((IUnknown*)(*ppvObject))->AddRef(); return NOERROR; } /************************************************************************/ /* 函数:[9/25/2016 IT]; /* 描述:; /* 参数:; /* [IN] :; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ void CWxAdoImpl::SolveDBError( IN CONST DWORD &dwError, IN LPVOID pDBConn) { switch(dwError) { //case SQL_ERROR://这个错误比较难精确判断问题; case ERROR_PIPE_NOT_CONNECTED: case WSAECONNRESET: case WSAECONNABORTED: { pAdoObj pObj = (pAdoObj)pDBConn; CWxAdoPool::GetInstance()->CloseBusyConnection(pObj); #if _DEBUG OutputDebugString(_T("关闭数据库连接\n")); #endif } break; default: break; } } //template //BOOL CWxAdoImpl::GetFiedValue(IN _RecordsetPtr rst, IN LPCTSTR lpFiedName, T &value) //{ // typeid(value); // _variant_t var = rst->GetCollect(lpFiedName); //switch(var.vt) //{ //case VT_EMPTY: // break; //case VT_NULL: // break; //case VT_I2://2 byte signed int // value = var.iVal; // break; //case VT_I4://4 byte signed int // value = var.iVal; // break; //case VT_R4://4 byte real // value = var.fltVal; // break; //case VT_R8://8 byte real // value = var.dblVal; // break; //case VT_CY://currency // break; //case VT_DATE: // { // COleDateTime dt(var); // value = dt.Format(_T("%Y-%m-%d %H:%M:%S")); // } // break; //case VT_BSTR://OLE Automation string // value = _bstr_t(var.bstrVal); // break; //case VT_DISPATCH://IDispatch * // break; //case VT_ERROR://SCODE // break; //case VT_BOOL://True=-1, False=0 // value = var.boolVal; // break; //case VT_VARIANT://VARIANT * // break; //case VT_UNKNOWN://IUnknown * // break; //case VT_DECIMAL://16 byte fixed point // break; //case VT_RECORD://user defined type // break; //case VT_I1: // signed char // value = var.pcVal; // break; //case VT_UI1://unsigned char // value = var.bVal; // break; //case VT_UI2://unsigned short // value = var.uiVal; // break; //case VT_UI4://unsigned long // value = var.uiVal; // break; //case VT_I8://signed 64-bit int // value = var.lVal; // break; //case VT_UI8://unsigned 64-bit int // value = var.ulVal; // break; //case VT_INT://signed machine int // value = var.intVal; // break; //case VT_UINT://unsigned machine int // value = var.uintVal; // break; //case VT_INT_PTR://signed machine register size width // break; //case VT_UINT_PTR://unsigned machine register size width // break; //case VT_VOID://C style void // break; //case VT_HRESULT://Standard return type // break; //case VT_PTR://pointer type // break; //case VT_SAFEARRAY://(use VT_ARRAY in VARIANT) // break; //case VT_CARRAY://C style array // break; //case VT_USERDEFINED://user defined type // break; //case VT_LPSTR://null terminated string // break; //case VT_LPWSTR://wide null terminated string // break; //case VT_FILETIME://FILETIME // break; //case VT_BLOB://Length prefixed bytes // break; //case VT_STREAM://Name of the stream follows // break; //case VT_STORAGE://Name of the storage follows // break; //case VT_STREAMED_OBJECT://Stream contains an object // break; //case VT_STORED_OBJECT://Storage contains an object // break; //case VT_VERSIONED_STREAM://Stream with a GUID version // break; //case VT_BLOB_OBJECT://Blob contains an object // break; //case VT_CF://Clipboard format // break; //case VT_CLSID://A Class ID // break; //case VT_VECTOR://simple counted array // break; //case VT_ARRAY://SAFEARRAY* // break; //case VT_BYREF://void* for local use // break; //case VT_BSTR_BLOB://Reserved for system use // break; //default: // value = var.iVal; //} // return TRUE; //} /************************************************************************/ /* 函数:[9/25/2016 IT]; /* 描述:; /* 参数:; /* [IN] :; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ 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 */ ) { return CWxAdoPool::GetInstance()->InitializePool(lpDBType, lpDBSource, dwDBPort, lpDBAccount, lpPassWord, lpDBName, nMinConn, nMaxConn); } /************************************************************************/ /* 函数:[9/25/2016 IT]; /* 描述:; /* 参数:; /* [IN] :; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ void CWxAdoImpl::ReleasePool() { CWxAdoPool *pObj = CWxAdoPool::GetInstance(); if ( pObj ) { pObj->ReleasePool(); delete pObj; pObj = NULL; } } /************************************************************************/ /* 函数:[9/25/2016 IT]; /* 描述:; /* 参数:; /* [IN] :; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ BOOL CWxAdoImpl::ExecuteSQL( IN LPCTSTR lpExcuteSQL, IN CONST DWORD &dwTimeOut /* = 30000 */ ) { GETDBPTR(dwTimeOut); try { if ( lpExcuteSQL == NULL || pObj == NULL ) return FALSE; pObj->pCommand->CommandText = _bstr_t(lpExcuteSQL); // 执行SQL语句,返回记录集 pObj->pCommand->Execute(NULL, NULL, adCmdText); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return TRUE; } /************************************************************************/ /* 函数:[9/25/2016 IT]; /* 描述:; /* 参数:; /* [IN] :; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ BOOL CWxAdoImpl::IsUserExist( IN LPCTSTR lpPhone, IN LPCTSTR lpPassword, OUT LPVOID lpOutValue,IN CONST DWORD &dwTimeOut /* = 3000 */ ) { GETDBPTR(dwTimeOut); #if 0 try { if ( lpPhone == NULL || lpPassword == NULL || pObj == NULL) return FALSE; CString strSql = _T(""); 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);//用于是否转相片; pObj->pCommand->CommandText = _bstr_t(strSql); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); tb_customer &customer = *(tb_customer*)lpOutValue; if(!rst->adoEOF) { customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal)); customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE); customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal)); customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal)); customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal)); customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal)); _variant_t var = rst->GetCollect(_T("vcode_expiry_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) customer.set_customer_vcode_expiry_time(_T("")); else { COleDateTime dt(var); customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE); } rst->Close(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } #else // 参数化查询; try { if (lpPhone == NULL || lpPassword == NULL || pObj == NULL) return FALSE; AddSTRParameters(pObj->pCommand, _T("@csr_phone"), lpPhone); 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 = ?")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); tb_customer &customer = *(tb_customer*)lpOutValue; if (!rst->adoEOF) { customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal)); customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE); customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal)); customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal)); customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal)); customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal)); _variant_t var = rst->GetCollect(_T("vcode_expiry_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) customer.set_customer_vcode_expiry_time(_T("")); else { COleDateTime dt(var); customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE); } rst->Close(); pObj->pCommand->Parameters->Release(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } #endif return TRUE; } INT CWxAdoImpl::QueryUserDetail(IN LPCTSTR lpPhone, IN LPVOID lpOutValue, IN const DWORD & dwTimeOut) { GETDBPTR(dwTimeOut); #if 0 try { if (lpPhone == NULL || pObj == NULL) return FALSE; CString strSql = _T(""); 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);//用于是否转相片; pObj->pCommand->CommandText = _bstr_t(strSql); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); tb_customer &customer = *(tb_customer*)lpOutValue; if (!rst->adoEOF) { customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal)); customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE); customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal)); customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal)); customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal)); customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal)); _variant_t var = rst->GetCollect(_T("vcode_expiry_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) customer.set_customer_vcode_expiry_time(_T("")); else { COleDateTime dt(var); customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE); } rst->Close(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } #else // 参数化查询; try { if (lpPhone == NULL || pObj == NULL) return FALSE; AddSTRParameters(pObj->pCommand, _T("@csr_phone"), lpPhone); 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 = ?")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); tb_customer &customer = *(tb_customer*)lpOutValue; if (!rst->adoEOF) { customer.set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); customer.set_customer_name(_bstr_t(rst->GetCollect(_T("csr_name")).bstrVal)); customer.set_customer_gender(rst->GetCollect(_T("csr_gender")).boolVal == VARIANT_TRUE ? TRUE : FALSE); customer.set_customer_password(_bstr_t(rst->GetCollect(_T("csr_password")).bstrVal)); customer.set_customer_phone(_bstr_t(rst->GetCollect(_T("csr_phone")).bstrVal)); customer.set_customer_old_phone(_bstr_t(rst->GetCollect(_T("csr_old_phone")).bstrVal)); customer.set_customer_vcode(_bstr_t(rst->GetCollect(_T("csr_vcode")).bstrVal)); _variant_t var = rst->GetCollect(_T("vcode_expiry_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) customer.set_customer_vcode_expiry_time(_T("")); else { COleDateTime dt(var); customer.set_customer_vcode_expiry_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } customer.set_customer_enable(rst->GetCollect(_T("enable")).boolVal == VARIANT_TRUE ? TRUE : FALSE); } rst->Close(); pObj->pCommand->Parameters->Release(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } #endif return TRUE; } INT CWxAdoImpl::QueryRecordOfType(IN LPCTSTR lpCustomerId, IN LPVOID lpOutValue, IN const DWORD & dwTimeOut) { GETDBPTR(dwTimeOut); try { if (lpCustomerId == NULL ) return FALSE; AddSTRParameters(pObj->pCommand, _T("@csr_id"), lpCustomerId); pObj->pCommand->CommandText = _bstr_t(_T("select csr_id,type_id,type_name,type_gen_time from reply_type where csr_id = ?")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); rec_type &listType = *(rec_type*)lpOutValue; while (!rst->adoEOF) { tb_type *pTypeObj = listType.add_types(); pTypeObj->set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); pTypeObj->set_type_id(_bstr_t(rst->GetCollect(_T("type_id")).bstrVal)); pTypeObj->set_type_name(_bstr_t(rst->GetCollect(_T("type_name")).bstrVal)); _variant_t var = rst->GetCollect(_T("type_gen_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) pTypeObj->set_type_gen_time(_T("")); else { COleDateTime dt(var); pTypeObj->set_type_gen_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } } rst->Close(); pObj->pCommand->Parameters->Release(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return 0; } INT CWxAdoImpl::QueryRecordOfReply(IN LPCTSTR lpCustomerId, IN LPCTSTR lpTypeId, IN LPVOID lpOutValue, IN const DWORD & dwTimeOut) { GETDBPTR(dwTimeOut); try { if (lpCustomerId == NULL || lpTypeId == NULL) return FALSE; AddSTRParameters(pObj->pCommand, _T("@csr_id"), lpCustomerId); AddSTRParameters(pObj->pCommand, _T("@type_id"), lpTypeId); pObj->pCommand->CommandText = _bstr_t(_T("select csr_id,type_id,reply_id,reply_name,reply_content,reply_gen_time from reply where csr_id = ? and type_id = ?")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); rec_reply &listReply = *(rec_reply*)lpOutValue; while (!rst->adoEOF) { tb_reply *pReplyObj = listReply.add_replys(); pReplyObj->set_customer_id(_bstr_t(rst->GetCollect(_T("csr_id")).bstrVal)); pReplyObj->set_type_id(_bstr_t(rst->GetCollect(_T("type_id")).bstrVal)); pReplyObj->set_reply_id(_bstr_t(rst->GetCollect(_T("reply_id")).bstrVal)); pReplyObj->set_reply_name(_bstr_t(rst->GetCollect(_T("reply_name")).bstrVal)); pReplyObj->set_reply_content(_bstr_t(rst->GetCollect(_T("reply_content")).bstrVal)); _variant_t var = rst->GetCollect(_T("reply_gen_time")); if (var.vt == VT_EMPTY || var.vt == VT_NULL) pReplyObj->set_reply_gen_time(_T("")); else { COleDateTime dt(var); pReplyObj->set_reply_gen_time(dt.Format(_T("%Y-%m-%d %H:%M:%S"))); } } rst->Close(); pObj->pCommand->Parameters->Release(); } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return 0; } BOOL CWxAdoImpl::AddCustomer(IN LPVOID lpCustomerInfo, IN const DWORD & dwTimeOut) { if (lpCustomerInfo == NULL) return FALSE; GETDBPTR(dwTimeOut); tb_customer &customer = *(tb_customer*)lpCustomerInfo; try { #if 1 CString strSql = _T(""); customer.set_customer_id(GetUID().c_str()); if (customer.customer_vcode_expiry_time().size() == 0) customer.set_customer_vcode_expiry_time(_T("0000-00-00 00:00:00")); 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) " "VALUES('%s','%s','%s',%d,'%s','%s','%s','%s',%d) "), customer.customer_id().c_str(), customer.customer_name().c_str(), customer.customer_phone().c_str(), customer.customer_gender(), customer.customer_password().c_str(), customer.customer_old_phone().c_str(), customer.customer_vcode().c_str(), customer.customer_vcode_expiry_time().c_str(), customer.customer_enable() ); pObj->pCommand->CommandText = _bstr_t(strSql); // 执行SQL语句,返回记录集 pObj->pCommand->Execute(NULL, NULL, adCmdText); #else // 出错:对象关闭时,不允许操作; AddSTRParameters(pObj->pCommand, _T("@csr_id"), customer.customer_id().c_str()); AddSTRParameters(pObj->pCommand, _T("@csr_name"), customer.customer_name().c_str()); AddSTRParameters(pObj->pCommand, _T("@csr_phone"), customer.customer_phone().c_str()); AddBoolParameters(pObj->pCommand, _T("@csr_gender"), BOOL(customer.customer_gender())); AddSTRParameters(pObj->pCommand, _T("@csr_password"), customer.customer_password().c_str()); AddSTRParameters(pObj->pCommand, _T("@csr_old_phone"), customer.customer_old_phone().c_str()); AddSTRParameters(pObj->pCommand, _T("@csr_vcode"), customer.customer_vcode().c_str()); AddSTRParameters(pObj->pCommand, _T("@vcode_expiry_time"), customer.customer_vcode_expiry_time().c_str()); AddBoolParameters(pObj->pCommand, _T("@enable"), customer.customer_enable()); pObj->pCommand->CommandText = _bstr_t(_T("INSERT INTO customer(csr_id, csr_name, csr_phone, csr_gender, csr_password, csr_old_phone, csr_vcode, vcode_expiry_time, enable) VALUES(?,?,?,?,?,?,?,?,?)")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); if (!rst->adoEOF) { ; } rst->Close(); pObj->pCommand->Parameters->Release(); #endif } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return TRUE; } BOOL CWxAdoImpl::AddType(IN LPVOID lpTypeInfo, IN const DWORD & dwTimeOut) { if (lpTypeInfo == NULL) return FALSE; GETDBPTR(dwTimeOut); tb_type &type = *(tb_type*)lpTypeInfo; try { #if 1 CString strSql = _T(""); type.set_type_id(GetUID().c_str()); if (type.type_gen_time().size() == 0) type.set_type_gen_time(GetCurrentLocalTime().c_str()); strSql.Format(_T("INSERT INTO reply_type(csr_id,type_id,type_name,type_gen_time) " "VALUES('%s','%s','%s','%s') "), type.customer_id().c_str(), type.type_id().c_str(), type.type_name().c_str(), type.type_gen_time().c_str() ); pObj->pCommand->CommandText = _bstr_t(strSql); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); if (!rst->adoEOF) { ; } rst->Close(); #else // 出错:对象关闭时,不允许操作; AddSTRParameters(pObj->pCommand, _T("@csr_id"), type.customer_id().c_str()); AddSTRParameters(pObj->pCommand, _T("@type_id"), GetUID().c_str()); AddSTRParameters(pObj->pCommand, _T("@type_name"), type.type_name().c_str()); AddSTRParameters(pObj->pCommand, _T("@type_gen_time"), type.type_gen_time().c_str()); pObj->pCommand->CommandText = _bstr_t(_T("INSERT INTO reply_type(csr_id,type_id,type_name,type_gen_time) VALUES(?,?,?,?)")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); if (!rst->adoEOF) { ; } rst->Close(); pObj->pCommand->Parameters->Release(); #endif } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return TRUE; } BOOL CWxAdoImpl::AddReply(IN LPVOID lpReplyInfo, IN const DWORD & dwTimeOut) { if (lpReplyInfo == NULL) return FALSE; GETDBPTR(dwTimeOut); tb_reply &reply = *(tb_reply*)lpReplyInfo; try { #if 1 CString strSql = _T(""); reply.set_reply_id(GetUID().c_str()); if (reply.reply_gen_time().size() == 0) reply.set_reply_gen_time(GetCurrentLocalTime().c_str()); strSql.Format(_T("INSERT INTO reply(csr_id,type_id,reply_id,reply_name,reply_content,reply_gen_time) " "VALUES('%s','%s','%s','%s','%s','%s') "), reply.customer_id().c_str(), reply.type_id().c_str(), reply.reply_id().c_str(), reply.reply_name().c_str(), reply.reply_content().c_str(), reply.reply_gen_time().c_str()); pObj->pCommand->CommandText = _bstr_t(strSql); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); if (!rst->adoEOF) { ; } rst->Close(); #else // 出错:对象关闭时,不允许操作; AddSTRParameters(pObj->pCommand, _T("@csr_id"), reply.customer_id().c_str()); AddSTRParameters(pObj->pCommand, _T("@type_id"), reply.type_id().c_str()); AddSTRParameters(pObj->pCommand, _T("@reply_id"), GetUID().c_str()); AddBoolParameters(pObj->pCommand, _T("@reply_name"), reply.reply_name().c_str()); AddSTRParameters(pObj->pCommand, _T("@reply_content"), reply.reply_content().c_str()); AddSTRParameters(pObj->pCommand, _T("@reply_gen_time"), reply.reply_gen_time().c_str()); pObj->pCommand->CommandText = _bstr_t(_T("INSERT INTO reply(csr_id,type_id,reply_id,reply_name,reply_content,reply_gen_time) VALUES(?,?,?,?,?,?)")); // 执行SQL语句,返回记录集 _RecordsetPtr rst = pObj->pCommand->Execute(NULL, NULL, adCmdText); if (!rst->adoEOF) { ; } rst->Close(); pObj->pCommand->Parameters->Release(); #endif } catch (_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); SolveDBError(e.Error(), pObj); WriteTextLog(_T("SQL出错:%08lx,%s,%s,%s"), e.Error(), e.ErrorMessage(), (TCHAR*)bstrSource, (TCHAR*)bstrDescription); return FALSE; } return TRUE; } BOOL CWxAdoImpl::UpdateCustomer(IN LPVOID lpCustomerInfo, IN const DWORD & dwTimeOut) { return 0; }