/************************************************************* /* Copyright (C), 2014-2020, lyfz. Co., Ltd. /* 文件名: ADODatabase.h /* 作者: Jeff.w /* 创建日期: 2014-08-16 /* 版本号: V1.0 /* 描述: 核心层底,数据库ADO编程 /* 其它: /* 主要类模块: /* 历史修改记录: /* 作者 时间 版本 描述 /* Jeff.w 14/08/18 1.0 创建这个模块 ***************************************************************/ #ifndef __ADO_DATABASE_HEADER__ #define __ADO_DATABASE_HEADER__ #pragma once #include "AdoDef.h" class CADODatabase { public: enum cadoConnectModeEnum { connectModeUnknown = adModeUnknown, connectModeRead = adModeRead, connectModeWrite = adModeWrite, connectModeReadWrite = adModeReadWrite, connectModeShareDenyRead = adModeShareDenyRead, connectModeShareDenyWrite = adModeShareDenyWrite, connectModeShareExclusive = adModeShareExclusive, connectModeShareDenyNone = adModeShareDenyNone }; CADODatabase() { ::CoInitialize(NULL); m_pConnection = NULL; m_strConnection = _T(""); m_strLastError = _T(""); m_dwLastError = 0; m_pConnection.CreateInstance(__uuidof(Connection)); m_nRecordsAffected = 0; m_nConnectionTimeout = 0; } virtual ~CADODatabase() { Close(); m_pConnection.Release(); m_pConnection = NULL; m_strConnection = _T(""); m_strLastError = _T(""); m_dwLastError = 0; ::CoUninitialize(); } BOOL Execute(LPCTSTR lpstrExec); BOOL Open(LPCTSTR lpstrConnection = _T(""), LPCTSTR lpstrUserID = _T(""), LPCTSTR lpstrPassword = _T("")); BOOL IsOpen(); void Close(); // inline func; inline _ConnectionPtr GetActiveConnection() {return m_pConnection;}; inline int GetRecordsAffected(){return m_nRecordsAffected;}; inline DWORD GetRecordCount(_RecordsetPtr m_pRs); inline long BeginTransaction() {return m_pConnection->BeginTrans();}; inline long CommitTransaction() {return m_pConnection->CommitTrans();}; inline long RollbackTransaction() {return m_pConnection->RollbackTrans();}; inline void SetConnectionMode(cadoConnectModeEnum nMode){m_pConnection->PutMode((enum ConnectModeEnum)nMode);}; inline void SetConnectionString(LPCTSTR lpstrConnection){m_strConnection = lpstrConnection;}; inline CString GetConnectionString(){return m_strConnection;}; inline CString GetLastErrorString() {return m_strLastError;}; inline DWORD GetLastError(){return m_dwLastError;}; CString GetErrorDescription() {return m_strErrorDescription;}; void SetConnectionTimeout(long nConnectionTimeout = 30) {m_nConnectionTimeout = nConnectionTimeout;}; protected: void dump_com_error(_com_error &e); public: _ConnectionPtr m_pConnection; protected: CString m_strConnection; CString m_strLastError; CString m_strErrorDescription; DWORD m_dwLastError; int m_nRecordsAffected; long m_nConnectionTimeout; }; #endif