DALMyBools.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:4k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // DALMyBools.cpp : Implementation of CDALMyBools
- #include "stdafx.h"
- #include "BooksDAL.h"
- #include "DALMyBools.h"
- /////////////////////////////////////////////////////////////////////////////
- // CDALMyBools
- STDMETHODIMP CDALMyBools::InterfaceSupportsErrorInfo(REFIID riid)
- {
- static const IID* arr[] =
- {
- &IID_IDALMyBools
- };
- for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
- {
- if (InlineIsEqualGUID(*arr[i],riid))
- return S_OK;
- }
- return S_FALSE;
- }
- STDMETHODIMP CDALMyBools::GetBookByIsbn(UINT bookisbn, DTOBook **mybook)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- _ConnectionPtr conn=this->GetMyConn();//自定义的连接函数
- *mybook=(DTOBook*)::CoTaskMemAlloc(sizeof(DTOBook));//开辟空间
- _CommandPtr sqlobj;
- sqlobj.CreateInstance(__uuidof(Command));//生成实例
- sqlobj->CommandText=(_bstr_t)this->m_sqlQueryById;//在构造函数那初始化了
- sqlobj->CommandType=adCmdText;
- sqlobj->ActiveConnection=conn;
- _ParameterPtr para1=sqlobj->CreateParameter("id",adInteger,adParamInput,4);
- para1->Value=_variant_t((long)bookisbn);
- sqlobj->Parameters->Append(para1);
- _RecordsetPtr data=sqlobj->Execute(NULL,NULL,adCmdText);
- if(!data->adEOF)
- {
- (*mybook)->BookIsnb=(UINT)(long)(data->GetCollect("bookisnb"));
- _variant_t vtname=data->GetCollect("bookname");
- (*mybook)->BookName=::SysAllocString(vtname.bstrVal);
- _variant_t vtauthor=data->GetCollect("bookauthor");
- (*mybook)->BookName=::SysAllocString(vtauthor.bstrVal);
- }
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::QueryAllBook(DTOBook **allBook)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::SaveBook(DTOBook *bookdata, UINT *pResult)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::DeleteBookById(UINT id, UINT *iResult)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::Update(DTOBook *Book, UINT *iResult)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::get_UID(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::put_UID(BSTR newVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- this->m_UID=CString(newVal);
- ::SysFreeString(newVal);
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::get_PWD(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::put_PWD(BSTR newVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- this->m_PWD=CString(newVal);
- ::SysFreeString(newVal);
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::get_DataSource(BSTR *pVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- return S_OK;
- }
- STDMETHODIMP CDALMyBools::put_DataSource(BSTR newVal)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState())
- // TODO: Add your implementation code here
- this->m_DataSource=CString(newVal);
- ::SysFreeString(newVal);
- return S_OK;
- }
- _ConnectionPtr CDALMyBools::GetMyConn()
- {
- CString strFormat="Provider=OraOLEDB.Oracle.1;User Id=%s;Data Source=%s";
- CString str;
- str.Format(strFormat,this->m_UID,this->m_DataSource);
- _ConnectionPtr mytools;
- mytools.CreateInstance(__uuidof(Connection));
- mytools->Open(_bstr_t(str),"",_bstr_t(this->m_PWD),-1);
- return mytools;
- }