ADO方法访问数据库的封装接口(03)

5.DBRecordSetImpl.h
#pragmaonce

typedef_RecordsetPtrCADORecordSetPtr;

classCDBRecordSetImpl
{
 //构造函数和析构函数
public:
 CDBRecordSetImpl(void);
 virtual~CDBRecordSetImpl(void);

//copyconstructor
 CDBRecordSetImpl(constCDBRecordSetImpl&rRecordSetImpl);

//operator=,如果复制成功,则GetErrorMessage()返回空串
 CDBRecordSetImpl&operator=(constCDBRecordSetImpl&rRecordSetImpl);

//接口函数
public:
 //返回记录集
 CADORecordSetPtr&GetRecordSet(void);

/*
 * 判断当前记录集是否已经创建对象
 */
 BOOLisValid(void);

voidSetErrorMessage(LPCTSTRszErrMsg,constchar*szSourceFile=NULL,intnLine=0);

constCString&GetErrorMessage(void);

protected:

//记录集
 CADORecordSetPtrm_pRecordSetPtr;

//errormessage
 CStringm_strErrMsg;
};

inlineCADORecordSetPtr&CDBRecordSetImpl::GetRecordSet(void)
{
 returnm_pRecordSetPtr;
}

inlineBOOLCDBRecordSetImpl::isValid(void)
{
 return(m_pRecordSetPtr!=NULL);
};

inlineconstCString&CDBRecordSetImpl::GetErrorMessage(void)
{
 returnm_strErrMsg;
}
6.DBRecordSetImpl.cpp
#include"StdAfx.h"
#include"dbrecordsetimpl.h"
#include"DBErrorMsgDefs.h"

CDBRecordSetImpl::CDBRecordSetImpl(void)
{
 try
 {
  m_pRecordSetPtr.CreateInstance(__uuidof(Recordset));
 }
 catch(_com_error&e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__);
 }
 catch(...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__);
 }
}

CDBRecordSetImpl::~CDBRecordSetImpl(void)
{
 try
 {
  //关闭连接,并释放对象
  if(m_pRecordSetPtr!=NULL)
  {
   if(m_pRecordSetPtr->GetState()!=adStateClosed)
   {
    m_pRecordSetPtr->Close();
   }
   m_pRecordSetPtr=NULL;
  }
 }
 catch(_com_error&e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__);
 }
 catch(...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__);
 }
}

//copyconstructor
CDBRecordSetImpl::CDBRecordSetImpl(constCDBRecordSetImpl&rRecordSetImpl):
 m_pRecordSetPtr(NULL)
{
 *this=rRecordSetImpl;
}

//operator=
CDBRecordSetImpl&CDBRecordSetImpl::operator=(constCDBRecordSetImpl&rRecordSetImpl)
{
 if(this==&rRecordSetImpl)
 {
  return*this;
 }

//错误信息不复制,如果复制成功,则m_strErrMsg为空 
 try
 {
  m_strErrMsg=_T("");
  //cloneitfromdestination
  if(rRecordSetImpl.m_pRecordSetPtr!=NULL)
  {
   if(rRecordSetImpl.m_pRecordSetPtr->GetState()==adStateOpen)
   {
    //关闭连接,并释放对象
    if(m_pRecordSetPtr!=NULL)
    {
     if(m_pRecordSetPtr->GetState()!=adStateClosed)
     {
      m_pRecordSetPtr->Close();
     }
     m_pRecordSetPtr=NULL;
    }
    m_pRecordSetPtr=rRecordSetImpl.m_pRecordSetPtr->Clone(adLockUnspecified);
   }
  } 
 }
 catch(_com_error&e)
 {
  SetErrorMessage((LPCTSTR)e.Description(),__FILE__,__LINE__);
 }
 catch(...)
 {
  SetErrorMessage(EXCEPTION_UNKNOWN,__FILE__,__LINE__);
 }
 return*this;
}

voidCDBRecordSetImpl::SetErrorMessage(LPCTSTRszErrMsg,constchar*szSourceFile,intnLine)
{
 m_strErrMsg=szErrMsg;
}

转载于:https://www.cnblogs.com/IT-lover/archive/2005/11/28/285769.html

ADO方法访问数据库的封装接口相关推荐

  1. python数据库实体_python---使用get方法访问‘数据库’实体

    使用get方法访问'数据库'实体 #simple database #people people = { 'Alice':{ 'phone':'2341', 'addr':'Foo drive 23' ...

  2. 使用ADO.NET访问数据库

    一.ADO.NET:数据库访问的方法和技术. 二.ADO.NEt的重要组件: 1.DataSet:独立于数据源的数据访问 2-Net framework数据提供程序:用于连接到数据库执行命令和检索结果 ...

  3. 【参考】微信 - 数据库 -官方封装接口说明:

    前言:微信对SQL的数据库进行了标准封装PDO:本节把接口源码Copy出来简单分析,作为,以后开发的参考. <?php namespace QCloud_WeApp_SDK\Mysql; use ...

  4. 应用程序利用ADO对象访问数据库

    1.已创建MySQL数据库employeedb,数据库中有如下所示的employeetb表. 2.在使用ADO对象之前,必须在工程的Stdafx.h文件里用直接引入符号#import引入 ADO库文件 ...

  5. tfs 方法访问数据库 源代码_TFS源代码管理

    一.服务器配置 1.创建一个Visual Studio Online账户 打开VS,选择团队资源管理器(视图菜单下),然后在团队资源管理器中选择注册Team Foundation Service,打开 ...

  6. 第13章 使用ADO.NET访问数据库

    Program using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  7. VC用ADO访问数据库全攻略  作者 相生昌

    VC用ADO访问数据库全攻略 作者 相生昌 <script language=VBScript> document.title="VC用ADO访问数据库全攻略 "&am ...

  8. 使用ADO或ADO控件访问数据库

    目录: 1.数据库的基础知识以及创建Access数据库 2.数据库的接口 3.使用ADO或ADO控件访问数据库 上篇文章,为大家讲解了数据库的接口,大家对ADO也有了较为基础的了解,这篇文章主要解决大 ...

  9. VC访问数据库学习总结

    VC连接数据库方式 目前Windows系统上常见的数据库接口包括: ODBC(开放数据库互连):访问数据库得先配置数据源 MFC(Microsoft基础类)ODBC类 DAO(数据访问对象) RDO( ...

  10. VC++使用ADO开发ACCESS数据库

    VC++使用ADO开发ACCESS数据库 ADO和ADOX到底是什么,二者的作用和区别 ADO是Microsoft 最新推出的数据库访问的高层软件接口.它和Microsoft以前的数据库访问接口DAO ...

最新文章

  1. SAP PM单一和复合角色
  2. win10 rabbitMQ的安装与测试
  3. 启明云端分享|ESP32-C3模块入门应用
  4. VTK:图片之InteractWithImage
  5. springboot 系列教程十:springboot单元测试
  6. 性能提升一倍,云原生网关支持 TLS 硬件加速
  7. englishpod主持人对话文本_Englishpod 23 | 主持人文本讲解
  8. WebLogic12.1.1中跨域问题的探讨以及几种常见中间件中跨域问题的解决方法
  9. 2018.7.11 昨天晚上的列表(字典)嵌套题
  10. windows server 2008 各版本下载
  11. power iso linux启动盘,怎么用poweriso制作u盘启动盘win10_poweriso制作u盘启动盘win10详细步骤...
  12. TexturePacker破解版教程及下载
  13. python 多行注释 快捷键
  14. 基于IDS模型设计的ICS
  15. 工作流:如何将Word尾注转换为普通文本格式
  16. 【腾讯Bugly干货分享】美团大众点评 Hybrid 化建设
  17. windows10系统盘瘦身
  18. android otg读写文件,Android USB Host在USB设备OTG中读/写文件
  19. Alibaba Java 2021 技术图谱——学习永无止境
  20. oracle数据库导入dmp文件

热门文章

  1. KORG Software TRITON for mac(虚拟合成器软件)
  2. 详细教程Desktop Goose又在整什么幺鹅子呢?
  3. DDD~领域事件应用篇(订单处理变得更清晰)
  4. pxe结合kickstart文件实现全自动化安装
  5. CentOS 7下网络设备命名
  6. QQ截图自动保存工具分享
  7. Ajax局部刷新例子
  8. 二叉树:听说递归能做的,栈也能做!
  9. 在 Mac 上的“照片”中如何更改文件的储存位置?
  10. Slideshow Maker for mac(幻灯片制作软件)