123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #include "StdAfx.h"
- #include "ADOCommand.h"
- CADOCommand::CADOCommand(CADODatabase* pAdoDatabase, CString strCommandText, int nCommandType)
- {
- m_pCommand = NULL;
- m_pCommand.CreateInstance(__uuidof(Command));
- m_strCommandText = strCommandText;
- m_pCommand->CommandText = m_strCommandText.AllocSysString();
- m_nCommandType = nCommandType;
- m_pCommand->CommandType = (CommandTypeEnum)m_nCommandType;
- m_pCommand->ActiveConnection = pAdoDatabase->GetActiveConnection();
- }
- BOOL CADOCommand::AddParameter(CADOParameter* pAdoParameter)
- {
- ASSERT(pAdoParameter->GetParameter() != NULL);
- try
- {
- m_pCommand->Parameters->Append(pAdoParameter->GetParameter());
- return TRUE;
- }
- catch(_com_error& e)
- {
- dump_com_error(e);
- return FALSE;
- }
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, int nValue)
- {
- _variant_t vtValue;
- vtValue.vt = VT_I2;
- vtValue.iVal = nValue;
- return AddParameter(strName, nType, nDirection, lSize, vtValue);
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, long lValue)
- {
- _variant_t vtValue;
- vtValue.vt = VT_I4;
- vtValue.lVal = lValue;
- return AddParameter(strName, nType, nDirection, lSize, vtValue);
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, double dblValue)
- {
- _variant_t vtValue;
- vtValue.vt = VT_R8;
- vtValue.dblVal = dblValue;
- return AddParameter(strName, nType, nDirection, lSize, vtValue);
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, CString strValue)
- {
- _variant_t vtValue;
- vtValue.vt = VT_BSTR;
- vtValue.bstrVal = strValue.AllocSysString();
- return AddParameter(strName, nType, nDirection, lSize, vtValue);
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, COleDateTime time)
- {
- _variant_t vtValue;
- vtValue.vt = VT_DATE;
- vtValue.date = time;
- return AddParameter(strName, nType, nDirection, lSize, vtValue);
- }
- BOOL CADOCommand::AddParameter(CString strName, int nType, int nDirection, long lSize, _variant_t vtValue)
- {
- try
- {
- m_pCommand->CreateParameter(strName.AllocSysString(), (DataTypeEnum)nType, (ParameterDirectionEnum)nDirection, lSize, vtValue);
- return TRUE;
- }
- catch(_com_error& e)
- {
- dump_com_error(e);
- return FALSE;
- }
- }
- void CADOCommand::SetText(CString strCommandText)
- {
- ASSERT(!strCommandText.IsEmpty());
- m_strCommandText = strCommandText;
- m_pCommand->CommandText = m_strCommandText.AllocSysString();
- }
- void CADOCommand::SetType(int nCommandType)
- {
- m_nCommandType = nCommandType;
- m_pCommand->CommandType = (CommandTypeEnum)m_nCommandType;
- }
- void CADOCommand::dump_com_error(_com_error &e)
- {
- CString ErrorStr;
- _bstr_t bstrSource(e.Source());
- _bstr_t bstrDescription(e.Description());
- ErrorStr.Format( "CADOCommand Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
- e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
- m_strLastError = ErrorStr;
- m_dwLastError = e.Error();
- #ifdef _DEBUG
- AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
- #endif
- }
|