📄 arsdb.h
字号:
//---------------------------------------------------------------------
// arsdb.h - Copyright (C) 1998 by AIRES Group
// Definitions of AIRES Database Services
//---------------------------------------------------------------------
#if !defined(ARSDB_DEFINED)
#define ARSDB_DEFINED
#ifdef ARSDB_EXPORTS
#define ARSDB_API __declspec(dllexport)
#else
#define ARSDB_API __declspec(dllimport)
#endif
// Right now implementation is based on ADO 2.0, but may change in the future
#include <objbase.h>
#include <afxdisp.h>
#ifdef ARSDB_DATABLOCK
#include <initguid.h>
#endif
#include <tchar.h> // Unicode
#include <adoid.h>
#include <adoint.h>
#include <comdef.h>
#include "arsmsg.h"
#define ARSDB_GETFIELD(fd) (fd##_isNULL = !(*this)("" #fd "", fd))
#define ARSDB_SETFIELD(fd) ((*this)("" #fd "", fd, TRUE, fd##_isNULL))
#define ARSDB_CHKSTRFIELD(fd) if (!fd.IsEmpty()) fd##_isNULL = FALSE;
#define ARSDB_CHKDATEFIELD(fd) if (fd.GetYear() != 1900) fd##_isNULL = FALSE;
#define ARSDB_CHKNUMFIELD(fd) if (fd > 0) fd##_isNULL = FALSE;
#define ARSDB_GETCYFIELD(fd) \
{ \
CY fd; \
fd.int64 = 0; \
fd##_isNULL = !(*this)("" #fd "", fd); \
this->fd = (float )(((double )fd.int64) / ((double )10000)); \
}
#define ARSDB_SETCYFIELD(fd) \
{ \
CY fd; \
if (!fd##_isNULL) \
fd.int64 = (__int64 )(this->fd * 10000.0); \
else \
fd.int64 = 0; \
(*this)("" #fd "", fd, TRUE, fd##_isNULL); \
}
#define ARSDB_CHKCYFIELD(fd) \
{ \
if ((fd >= 0.01) || (fd <= -0.01)) \
fd##_isNULL = FALSE; \
}
#define ARSDB_FIXDATEFIELD(fd) \
{ \
if (fd.GetStatus() == COleDateTime::invalid) \
fd.SetDate(1900,1,1); \
}
// CARSObject - base class of all of the AIRES Classes
class ARSDB_API CARSObject : public CObject {
// Must for every CARSObject derived class
DECLARE_DYNAMIC(CARSObject);
};
// Forward declarations to resolve circular refferences
class ARSDB_API CARSConnection;
// Wrapper around get_Message() in order to return CString object for easier management
CString ARSDB_API arsmsg_GetMessage(UINT nID, BOOL *res = NULL);
// Throws ARS Exception
void ARSDB_API AfxThrowARSException(UINT cause, UINT m_detailed = 0, ADOConnection *pConn = NULL, UINT helpID = 0);
// ARS Execption type, reads messages from the Resource DLL
class ARSDB_API CARSException : public CException {
// Must to give us IsKindOf ability
DECLARE_DYNAMIC(CARSException);
UINT m_cause; // Cause of exception (ID of the message in arsmsg.dll)
UINT m_detailed; // Additional explanation (ID of the message in arsmsg.dll)
UINT m_helpID; // Help ID of the exception
CString m_ErrorStr; // Error String from ADO Connection
public:
CARSException(UINT _m_cause, UINT _m_detailed = 0, ADOConnection *pConn = NULL, UINT _m_helpID = 0);
UINT GetCause();
UINT GetDetailed();
UINT GetHelpID();
virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL );
virtual int ReportError( UINT nType = MB_OK, UINT nMessageID = 0 );
private:
void ExtractConnError(ADOConnection *pConn);
};
// CARSRecordSet - encapsulate RecordSet functionality
class ARSDB_API CARSRecordset : public CARSObject {
// Give access to CARSConnection(ADOReocrdset) member to CARSConnection
friend class CARSConnection;
// Must to give us IsKindOf ability
DECLARE_DYNAMIC(CARSRecordset);
ADORecordset *pSet;
ADOConnection *pConnection;
CARSRecordset(ADORecordset *_pSet);
public:
// Open/Close/Create/Delete record set
CARSRecordset();
CARSRecordset(LPCSTR pcsSource, CARSConnection *pConn, CursorTypeEnum cType = adOpenDynamic, LockTypeEnum lType = adLockOptimistic, long lOptions = adCmdUnknown);
~CARSRecordset();
void Open(LPCSTR pcsSource, CARSConnection *pConn, CursorTypeEnum cType = adOpenDynamic, LockTypeEnum lType = adLockOptimistic, long lOptions = adCmdUnknown);
void Close();
// Queries
BOOL IsOpen();
BOOL IsInitialized(); // If all of the underlying Data Access Components are loaded
BOOL IsBOF();
BOOL IsEOF();
// Move operations
void MoveFirst();
void MoveNext();
void MoveLast();
void MovePrevious();
virtual BOOL PositionToPK(long _pk_id);
// Filter
void SetFilter(LPCSTR filter);
CString GetFilter();
// Edit Mode
EditModeEnum GetEditMode();
// Updates / Deletes
void Delete(AffectEnum affectRecords = adAffectCurrent);
void Update();
void CancelUpdate();
// Read/Write Access to data members
void GetFieldValue(LPCSTR fieldName, VARIANT *value);
void SetFieldValue(LPCSTR fieldName, VARIANT *value);
CString ConvertVariantToString(VARIANT *value);
BOOL operator()(LPCSTR fieldName, CString &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, long &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, short &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, BOOL &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, double &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, float &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, COleDateTime &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
BOOL operator()(LPCSTR fieldName, CY &fd, BOOL doWrite = FALSE, BOOL isNULL = FALSE);
void AddNew();
protected:
// Overwritables in order to support easy Subclassing
CARSRecordset(CARSConnection *pConn, CursorTypeEnum cType = adOpenDynamic, LockTypeEnum lType = adLockOptimistic, long lOptions = adCmdUnknown);
void Open(CARSConnection *pConn, CursorTypeEnum cType = adOpenDynamic, LockTypeEnum lType = adLockOptimistic, long lOptions = adCmdUnknown);
// Called upon Open(pConn, CursorType, LockMode, Options)
// must return source (either table name or query for extracting data)
virtual LPCSTR GetSource();
// Called from MoveFirst, Next() and so on to copy data from Database to internal variables
virtual void CopyDataFromDatabase();
// Called from Update(), AddNew() to copy data from internal variables to Database
virtual void CopyDataToDatabase();
};
// CARSConnection - class which encapsulates database connection functionality
class ARSDB_API CARSConnection : public CARSObject {
friend class CARSRecordset;
// Must to give us IsKindOf ability
DECLARE_DYNAMIC(CARSConnection);
ADOConnection *pConn;
static DWORD dwNumConnections;
public:
// Open /close Create/Destroy Connection
CARSConnection();
CARSConnection(LPCSTR pcsConnectString, LPCSTR pcsUID, LPCSTR pcsPWD, long lFlags = adOpenUnspecified);
~CARSConnection();
void Open(LPCSTR pcsConnectString, LPCSTR pcsUID, LPCSTR pcsPWD, long lFlags = adOpenUnspecified);
void Close();
// Queries
BOOL IsOpen();
BOOL IsInitialized(); // If all of the underlying Data Access Components are loaded
// Transaction Management
void BeginTrans(long *plNestingLevel);
void CommitTrans();
void RollbackTrans();
// Schema Definitions
CARSRecordset *OpenSchema(SchemaEnum Schema, VARIANT *Criteria, VARIANT *SchemaID);
// Database access
CARSRecordset *Execute(LPCSTR pcsCommand, VARIANT *RecordsAffected = NULL, long lOptions = adCmdUnknown);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -