📄 _dbdao.h
字号:
public: \
\
objSingle Item (LONG i); \
objSingle Item (LPCTSTR pstr); \
objSingle operator[] (LONG i); \
objSingle operator[] (LPCTSTR pstr); \
}
#define DAOMFC_DYNAMIC_COLLECTION_DECL(objColl, objSingle, intSingle) \
class DLLEXPORT objColl : public CdbDynamicCollection \
{ \
public: \
\
objSingle Item (LONG i); \
objSingle Item (LPCTSTR pstr); \
VOID Append (objSingle &o); \
objSingle operator[] (LONG i); \
objSingle operator[] (LPCTSTR pstr); \
}
DAOMFC_STATIC_COLLECTION_DECL(CdbErrors, CdbError, DAOError);
DAOMFC_STATIC_COLLECTION_DECL(CdbDatabases, CdbDatabase, DAODatabase);
//Connections are special cased so we can trap the copy constructor
DAOMFC_STATIC_COLLECTION_DECL(CdbRecordsets, CdbRecordset, DAORecordset);
DAOMFC_STATIC_COLLECTION_DECL(CdbParameters, CdbParameter, DAOParameter);
DAOMFC_STATIC_COLLECTION_DECL(CdbDocuments, CdbDocument, DAODocument);
DAOMFC_STATIC_COLLECTION_DECL(CdbContainers, CdbContainer, DAOContainer);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbProperties, CdbProperty, DAOProperty);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbFields, CdbField, DAOField);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbQueryDefs, CdbQueryDef, DAOQueryDef);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbTableDefs, CdbTableDef, DAOTableDef);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbIndexes, CdbIndex, DAOIndex);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbRelations, CdbRelation, DAORelation);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbUsers, CdbUser, DAOUser);
DAOMFC_DYNAMIC_COLLECTION_DECL(CdbGroups, CdbGroup, DAOGroup);
//Need some extra functions in CdbWorkspaces to support the delay in creating the
//default workspace needed to support the JET/ODBC option.
class DLLEXPORT CdbWorkspaces : public CdbDynamicCollection
{
friend CdbDBEngine;
private:
DAODBEngine * pDBEng;
BOOL m_bDontStart;
public:
CONSTRUCTOR CdbWorkspaces (VOID){pDBEng = NULL;}
CdbWorkspace Item (LONG i);
CdbWorkspace Item (LPCTSTR pstr);
VOID Append (CdbWorkspace &o);
CdbWorkspace operator[] (LONG i);
CdbWorkspace operator[] (LPCTSTR pstr);
VOID SetDBEngine (DAODBEngine *peng){pDBEng = peng;}
VOID GetDelayedInterface ();
};
//Need to trap Connections in the copy constructor so the user can't
//get a "sorta-kinda" working Connections collection on a Jet workspace
class DLLEXPORT CdbConnections : public CdbStaticCollection
{
public:
CONSTRUCTOR CdbConnections (CdbConnections &Connections);
CONSTRUCTOR CdbConnections (){pwrk = NULL;}
CdbConnection Item (LONG i);
CdbConnection Item (LPCTSTR pstr);
CdbConnection operator[] (LONG i);
CdbConnection operator[] (LPCTSTR pstr);
CdbConnections & operator = (CdbConnections &o);
LONG GetCount (VOID);
VOID Refresh (VOID) ;
VOID SetWorkspace (DAOWorkspace * pParent){pwrk = pParent;}
private:
VOID CheckInterface();
DAOWorkspace * pwrk;
};
/*****************************************************************************
* CdbObject
*/
class DLLEXPORT CdbObject : public CdbOleObject
{
public:
CONSTRUCTOR CdbObject (VOID);
CONSTRUCTOR CdbObject (LPUNKNOWN punk, BOOL bAddRef=FALSE);
virtual CString GetName (VOID);
virtual VOID SetName (LPCTSTR pstr);
CdbProperties Properties;
};
/*****************************************************************************
* CdbGetRowsEx (holds GetRowsEx for Recordset)
*/
class DLLEXPORT CdbGetRowsEx : public CdbObject
{
public:
// Administration
CONSTRUCTOR CdbGetRowsEx (VOID);
CONSTRUCTOR CdbGetRowsEx (ICDAORecordset *pGetRows, BOOL bAddRef=FALSE);
CONSTRUCTOR CdbGetRowsEx (const CdbGetRowsEx &);
CdbGetRowsEx & operator = (const CdbGetRowsEx &);
VOID OnInterfaceChange (VOID);
};
/*****************************************************************************
* Helper macros
*/
//Initialize a variant
#define DAOVINIT(var) \
do \
{ \
(var).vt = VT_ERROR; \
(var).scode = DISP_E_PARAMNOTFOUND; \
} \
while (0)
// LPTSTR to VARIANT
#define STV(pstr) CdbVariant(pstr)
// LPTSTR to BSTR
#define STB(pstr) V_BSTR(((LPVARIANT)STV(pstr)))
// LONG to VARIANT
#define LTV(l) CdbVariant(l)
// Optional LONG to VARIANT
#define OLTV(l) CdbVariant((l))
// C/C++ bool to DAO bool
#define BTB(b) ((VARIANT_BOOL)(b?-1:0))
// C/C++ bool to VARIANT
#define BTV(b) CdbVariant(BTB(b), TRUE)
// C/C++ short to VARIANT
#define SHTV(s) CdbVariant((SHORT)s)
// OLE variant to VARIANT
#define VTV(pv) CdbVariant(pv)
// SAFEARRAY to VARIANT
#define ATV(psa, var) \
do \
{ \
if (!psa) \
{ \
var.vt = VT_ERROR; \
var.scode = DISP_E_PARAMNOTFOUND; \
} \
else \
{ \
var.vt = VT_ARRAY|VT_UI1; \
SafeArrayCopy(psa, &var.parray); \
} \
} \
while (0)
#define DAOMFC_CALL(hr) \
do \
{ \
HRESULT hresult = (hr); \
if(FAILED(hresult)) \
{ \
TRACE0("\nDBDAO Call Failed.\n\t"); \
TRACE2("\nIn file %s on line %d\n", _T("DBDAO.CPP"), __LINE__); \
TRACE1("hResult = %X\n", hresult); \
if (GetScode(hresult) == E_OUTOFMEMORY) \
AfxThrowMemoryException(); \
else \
throw CdbException(hresult); \
} \
} while (0)
/*****************************************************************************
* Property Set/Get helper macros
*/
// Get a LONG property
#define LPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
LONG l = 0; \
\
DAOMFC_CALL(p->meth(&l)); \
\
return l; \
} \
while (0)
// Set a LONG property
#define LPROPSET(intDAO, meth, l) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(l)); \
} \
while(0)
// Get a SHORT property
#define WPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
SHORT s = 0; \
\
DAOMFC_CALL(p->meth(&s)); \
\
return s; \
} \
while (0)
// Set a SHORT property
#define WPROPSET(intDAO, meth, s) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(s)); \
} \
while(0)
// Get a STRING property
#define SPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
CdbBSTR bstr; \
\
DAOMFC_CALL(p->meth(bstr)); \
\
return bstr; \
} \
while (0)
// Set a STRING property
#define SPROPSET(intDAO, meth, s) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(STB(s))); \
} \
while(0)
// Get a DATETIME property
#define DPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
VARIANT Var; \
\
VariantInit(&Var); \
DAOMFC_CALL(p->meth(&Var)); \
return Var; \
} \
while (0)
// Set a DATETIME property
#define DPROPSET(intDAO, meth, pv) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(*pv)); \
} \
while(0)
// Get a BOOLEAN property
#define BPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
VARIANT_BOOL vb = 0; \
\
DAOMFC_CALL(p->meth(&vb)); \
\
return (BOOL)vb; \
} \
while (0)
// Set a BOOLEAN property
#define BPROPSET(intDAO, meth, b) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(BTB(b))); \
} \
while(0)
// Get a VARIANT property
#define VPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
COleVariant v; \
\
VariantInit(&v); \
DAOMFC_CALL(p->meth(&v)); \
\
return &v; \
} \
while (0)
// Set a VARIANT property
#define VPROPSET(intDAO, meth, pv) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
\
DAOMFC_CALL(p->meth(*pv)); \
} \
while(0)
// Get a DWORD property
#define DWPROPGET(intDAO, meth) \
do \
{ \
intDAO * p = (intDAO *)GetInterface(); \
DWORD dw = 0; \
\
DAOMFC_CALL(p->meth(&dw)); \
\
return dw; \
} \
while (0)
#define DAOMFC_STATIC_COLLECTION_IMPL(objColl, objSingle, intColl, intSingle) \
objSingle objColl::Item (LONG i) { return (intSingle *)(ObItem(i).GetInterface(TRUE)); } \
objSingle objColl::Item (LPCTSTR pstr) { return (intSingle *)(ObItem(pstr).GetInterface(TRUE)); } \
objSingle objColl::operator[] (LONG i) { return (intSingle *)(Item(i).GetInterface(TRUE)); } \
objSingle objColl::operator[] (LPCTSTR pstr) { return (intSingle *)(Item(pstr).GetInterface(TRUE)); }
#define DAOMFC_DYNAMIC_COLLECTION_IMPL(objColl, objSingle, intColl, intSingle) \
objSingle objColl::Item (LONG i) { return (intSingle *)(ObItem(i).GetInterface(TRUE)); } \
objSingle objColl::Item (LPCTSTR pstr) { return (intSingle *)(ObItem(pstr).GetInterface(TRUE)); } \
VOID objColl::Append (objSingle &o) { ObAppend(o); } \
objSingle objColl::operator[] (LONG i) { return (intSingle *)(Item(i).GetInterface(TRUE)); } \
objSingle objColl::operator[] (LPCTSTR pstr) { return (intSingle *)(Item(pstr).GetInterface(TRUE)); }
DECLARE_INTERFACE_(DAOMFCSCollection, _DAOCollection)
{
STDMETHOD(get_Item) (VARIANT index, LPUNKNOWN *ppunk);
};
DECLARE_INTERFACE_(DAOMFCDCollection, _DAODynaCollection)
{
STDMETHOD(get_Item) (VARIANT index, LPUNKNOWN *ppunk);
};
#endif // __DBDAO_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -