// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#ifdef AFX_DB_SEG
#pragma code_seg(AFX_DB_SEG)
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma comment(lib, "ole32.lib")
#define new DEBUG_NEW
/////////////////////////////////////////////////////////////////////////////
// Maintain DAODBEngine object
_AFX_DAO_STATE::_AFX_DAO_STATE()
{
m_pDAODBEngine = NULL;
m_bOleInitialized = FALSE;
}
_AFX_DAO_STATE::~_AFX_DAO_STATE()
{
// these ASSERTs can trip when:
// ... there any outstanding workspsace objects
ASSERT(m_mapWorkspaces.IsEmpty());
// ... you've not shut down with a call AfxDaoTerm()
ASSERT(m_pDAODBEngine == NULL);
// ... OLE wasn't correctly shut down
ASSERT(!m_bOleInitialized);
}
//////////////////////////////////////////////////////////////////////////
// Helpers
// Index function return value
#define AFX_DAO_DATA_NOT_FOUND (-1L)
#define AFX_DAO_FETCH_PRIMARY_PROPERTIES \
(AFX_DAO_PRIMARY_INFO | AFX_DAO_SECONDARY_INFO | AFX_DAO_ALL_INFO)
#define AFX_DAO_FETCH_SECONDARY_PROPERTIES \
(AFX_DAO_SECONDARY_INFO | AFX_DAO_ALL_INFO)
#define AFX_DAO_FETCH_ALL_PROPERTIES \
AFX_DAO_ALL_INFO
// Info helpers
void AFX_CDECL AfxGetFieldInfo(DAOField* pDAOField, CDaoFieldInfo& fieldinfo,
DWORD dwInfoOptions = AFX_DAO_PRIMARY_INFO);
void AFX_CDECL AfxSetFieldInfo(DAOField* pDAOField, CDaoFieldInfo& fieldinfo);
void AFX_CDECL AfxGetIndexInfo(DAOIndex* pDAOIndex, CDaoIndexInfo& indexinfo,
DWORD dwInfoOptions = AFX_DAO_PRIMARY_INFO);
void AFX_CDECL AfxSetIndexInfo(DAOIndex* pDAOIndex, CDaoIndexInfo& indexinfo);
void AFX_CDECL AfxGetIndexFields(DAOIndex* pDAOIndex,
DAOIndexFields** ppDAOIndexFields);
void AFX_CDECL AfxGetIndexFieldInfo(DAOIndex* pDAOIndex, CDaoIndexInfo& indexinfo);
void AFX_CDECL AfxSetIndexFieldInfo(DAOIndex* pDAOIndex, CDaoIndexInfo& indexinfo);
void AFX_CDECL AfxGetDefaultValue(DAOField* pDAOField, CString& strDefaultValue);
void AFX_CDECL AfxSetDefaultValue(DAOField* pDAOField, CString& strDefaultValue);
// GetRows helper
void AFX_CDECL ThrowGetRowsDaoException(SCODE scode);
// _AFX_DAO_STATE helper
_AFX_DAO_STATE* AFX_CDECL AfxGetDaoState();
//////////////////////////////////////////////////////////////////////////
// Global data
AFX_STATIC_DATA const TCHAR _afxParameters2[] = _T("PARAMETERS ");
AFX_STATIC_DATA const TCHAR _afxSelect2[] = _T("SELECT ");
AFX_STATIC_DATA const TCHAR _afxFrom2[] = _T(" FROM ");
AFX_STATIC_DATA const TCHAR _afxWhere2[] = _T(" WHERE ");
AFX_STATIC_DATA const TCHAR _afxOrderBy2[] = _T(" ORDER BY ");
AFX_STATIC_DATA const TCHAR _afxTransform2[] = _T("TRANSFORM ");
AFX_STATIC_DATA const TCHAR _afxTable2[] = _T("TABLE ");
// Need a static VARIANT for optional DAO parameters
AFX_STATIC_DATA VARIANT _afxOptionalVariant = { VT_ERROR, 0, 0, 0, DISP_E_PARAMNOTFOUND };
// Need a static VARIANT for NULL DAO parameters
AFX_STATIC_DATA VARIANT _afxNullVariant = { VT_NULL, 0, 0, 0, 0 };
//////////////////////////////////////////////////////////////////////////
// Logging helpers
void AFXAPI AfxDaoCheck(SCODE scode, LPCSTR lpszDaoCall,
LPCSTR lpszFile, int nLine, int nError, BOOL bMemOnly)
{
UNUSED(lpszDaoCall);
UNUSED(lpszFile);
UNUSED(nLine);
if (FAILED(scode))
{
#ifdef _DEBUG
if (afxTraceFlags & traceDatabase)
{
TRACE0("\nDAO Call Failed.");
TRACE1("\n\t%hs", lpszDaoCall);
TRACE2("\n\tIn file %hs on line %d", lpszFile, nLine);
TRACE1("\n\tscode = %X\n", scode);
}
#endif
if (scode == E_OUTOFMEMORY)
AfxThrowMemoryException();
else if (!bMemOnly)
AfxThrowDaoException(nError, scode);
}
}
#ifdef _DEBUG
void AFXAPI AfxDaoTrace(SCODE scode, LPCSTR lpszDaoCall,
LPCSTR lpszFile, int nLine)
{
if (FAILED(scode))
{
if (afxTraceFlags & traceDatabase)
{
TRACE0("\nDAO Call Failed.\n\t");
TRACE1("\n%hs", lpszDaoCall);
TRACE2("\nIn file %hs on line %d\n", lpszFile, nLine);
TRACE1("scode = %X\n", scode);
}
}
}
#endif // _DEBUG
//////////////////////////////////////////////////////////////////////////
// Info structure diagnostics
#ifdef _DEBUG
void CDaoErrorInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoErrorInfo at " << (void*)this;
dc << "\nm_lErrorCode = " << m_lErrorCode;
dc << "\nm_strSource = " << m_strSource;
dc << "\nm_strDescription = " << m_strDescription;
dc << "\nm_strHelpFile = " << m_strHelpFile;
dc << "\nm_lHelpContext = " << m_lHelpContext;
dc << "\n";
}
#endif // _DEBUG
#ifdef _DEBUG
void CDaoWorkspaceInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoWorkspaceInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_strUserName = " << m_strUserName;
dc << "\nb = m_bIsolateODBCTrans" << m_bIsolateODBCTrans;
dc << "\n";
}
#endif // _DEBUG
#ifdef _DEBUG
void CDaoDatabaseInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoDatabaseInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_bUpdatable = " << m_bUpdatable;
dc << "\nm_bTransactions = " << m_bTransactions;
dc << "\nm_strVersion = " << m_strVersion;
dc << "\nm_lCollatingOrder = " << m_lCollatingOrder;
dc << "\nm_nQueryTimeout = " << m_nQueryTimeout;
dc << "\nm_strConnect = " << m_strConnect;
dc << "\n";
}
#endif // _DEBUG
#ifdef _DEBUG
void CDaoTableDefInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoTableDefInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_bUpdatable = " << m_bUpdatable;
dc << "\nm_lAttributes = " << m_lAttributes;
dc << "\nm_dateDateCreated = " << m_dateCreated;
dc << "\nm_dateLastUpdated = " << m_dateLastUpdated;
dc << "\nm_strSrcTableName = " << m_strSrcTableName;
dc << "\nm_strConnect = " << m_strConnect;
dc << "\nm_strValidationRule = " << m_strValidationRule;
dc << "\nm_strValidationText = " << m_strValidationText;
dc << "\nm_lRecordCount = " << m_lRecordCount;
dc << "\n";
}
#endif // _DEBUG
#ifdef _DEBUG
void CDaoFieldInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoFieldInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_nType = " << m_nType;
dc << "\nm_lSize = " << m_lSize;
dc << "\nm_lAttributes = " << m_lAttributes;
dc << "\nm_nOrdinalPosition = " << m_nOrdinalPosition;
dc << "\nm_bRequired = " << m_bRequired;
dc << "\nm_bAllowZeroLength = " << m_bAllowZeroLength;
dc << "\nm_lCollatingOrder = " << m_lCollatingOrder;
dc << "\nm_strForeignName = " << m_strForeignName;
dc << "\nm_strSourceField = " << m_strSourceField;
dc << "\nm_strSourceTable = " << m_strSourceTable;
dc << "\nm_strValidationRule = " << m_strValidationRule;
dc << "\nm_strValidationText = " << m_strValidationText;
dc << "\nm_strDefaultValue = " << m_strDefaultValue;
dc << "\n";
}
#endif // _DEBUG
#ifdef _DEBUG
void CDaoIndexFieldInfo::Dump(CDumpContext& dc) const
{
dc << " a CDaoIndexFieldInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_bDescending = " << m_bDescending;
}
#endif
CDaoIndexInfo::CDaoIndexInfo()
{
m_pFieldInfos = NULL;
m_nFields = 0;
m_bCleanupFieldInfo = FALSE;
}
CDaoIndexInfo::~CDaoIndexInfo()
{
if (m_bCleanupFieldInfo && m_pFieldInfos != NULL)
{
delete[] m_pFieldInfos;
m_pFieldInfos = NULL;
}
}
#ifdef _DEBUG
void CDaoIndexInfo::Dump(CDumpContext& dc) const
{
dc << "a CDaoIndexInfo at " << (void*)this;
dc << "\nm_strName = " << m_strName;
dc << "\nm_nFields = " << m_nFields;
for (int