📄 afxdb.h
字号:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif //_DEBUG
virtual BOOL Check(RETCODE nRetCode) const; // general error check
void InitRecord();
void ResetCursor();
void CheckRowsetCurrencyStatus(UWORD wFetchType, long nRows);
RETCODE FetchData(UWORD wFetchType, SDWORD nRow,
DWORD* pdwRowsFetched);
void SkipDeletedRecords(UWORD wFetchType, long nRows,
DWORD* pdwRowsFetched, RETCODE* pnRetCode);
virtual void SetRowsetCurrencyStatus(RETCODE nRetCode,
UWORD wFetchType, long nRows, DWORD dwRowsFetched);
virtual void PreBindFields(); // called before data fields are bound
UINT m_nFields; // number of RFX fields
UINT m_nParams; // number of RFX params
BOOL m_bCheckCacheForDirtyFields; // switch for dirty field checking
BOOL m_bRebindParams; // date or UNICODE text parameter existence flag
BOOL m_bLongBinaryColumns; // long binary column existence flag
BOOL m_bUseUpdateSQL; // uses SQL-based updates
DWORD m_dwOptions; // archive dwOptions on Open
SWORD m_nResultCols; // number of columns in result set
BOOL m_bUseODBCCursorLib; // uses ODBC cursor lib if m_pDatabase not Open
CODBCFieldInfo* m_rgODBCFieldInfos; // Array of field info structs with ODBC meta-data
CFieldInfo* m_rgFieldInfos; // Array of field info structs with MFC specific field data
CMapPtrToPtr m_mapFieldIndex; // Map of member address to field index
CMapPtrToPtr m_mapParamIndex; // Map of member address to field index
BOOL IsSQLUpdatable(LPCTSTR lpszSQL);
BOOL IsSelectQueryUpdatable(LPCTSTR lpszSQL);
static BOOL PASCAL IsJoin(LPCTSTR lpszJoinClause);
static LPCTSTR PASCAL FindSQLToken(LPCTSTR lpszSQL, LPCTSTR lpszSQLToken);
// RFX Operations on fields of CRecordset
UINT BindParams(HSTMT hstmt);
void RebindParams(HSTMT hstmt);
UINT BindFieldsToColumns();
void BindFieldsForUpdate();
void UnbindFieldsForUpdate();
void Fixups();
UINT AppendNames(CString* pstr, LPCTSTR szSeparator);
UINT AppendValues(HSTMT hstmt, CString* pstr, LPCTSTR szSeparator);
UINT AppendNamesValues(HSTMT hstmt, CString* pstr, LPCTSTR szSeparator);
void StoreFields();
void LoadFields();
void MarkForAddNew();
void MarkForUpdate();
void AllocDataCache();
void FreeDataCache();
#ifdef _DEBUG
void DumpFields(CDumpContext& dc) const;
#endif //_DEBUG
// RFX operation helper functions
virtual void ThrowDBException(RETCODE nRetCode, HSTMT hstmt = SQL_NULL_HSTMT);
int GetBoundFieldIndex(void* pv);
int GetBoundParamIndex(void* pv);
short GetFieldIndexByName(LPCTSTR lpszFieldName);
void AllocStatusArrays();
long* GetFieldLengthBuffer(DWORD nField, int nFieldType); // for fields & params
BYTE GetFieldStatus(DWORD nField);
void SetFieldStatus(DWORD nField, BYTE bFlags);
void ClearFieldStatus();
BOOL IsFieldStatusDirty(DWORD nField) const;
void SetDirtyFieldStatus(DWORD nField);
void ClearDirtyFieldStatus(DWORD nField);
BOOL IsFieldStatusNull(DWORD nField) const;
void SetNullFieldStatus(DWORD nField);
void ClearNullFieldStatus(DWORD nField);
BOOL IsParamStatusNull(DWORD nField) const;
void SetNullParamStatus(DWORD nField);
void ClearNullParamStatus(DWORD nField);
BOOL IsFieldNullable(DWORD nField) const;
void** m_pvFieldProxy;
void** m_pvParamProxy;
UINT m_nProxyFields;
UINT m_nProxyParams;
// GetFieldValue helpers
static short PASCAL GetDefaultFieldType(short nSQLType);
static void* PASCAL GetDataBuffer(CDBVariant& varValue, short nFieldType,
int* pnLen, short nSQLType, UDWORD nPrecision);
static int PASCAL GetTextLen(short nSQLType, UDWORD nPrecision);
static long PASCAL GetData(CDatabase* pdb, HSTMT hstmt, short nFieldIndex,
short nFieldType, LPVOID pvData, int nLen, short nSQLType);
static void PASCAL GetLongBinaryDataAndCleanup(CDatabase* pdb, HSTMT hstmt,
short nFieldIndex, long nActualSize, LPVOID* ppvData, int nLen,
CDBVariant& varValue, short nSQLType);
static void PASCAL GetLongCharDataAndCleanup(CDatabase* pdb, HSTMT hstmt,
short nFieldIndex, long nActualSize, LPVOID* ppvData, int nLen,
CString& strValue, short nSQLType);
protected:
UINT m_nOpenType;
UINT m_nDefaultType;
enum EditMode
{
noMode,
edit,
addnew
};
long m_lOpen;
UINT m_nEditMode;
BOOL m_bEOFSeen;
long m_lRecordCount;
long m_lCurrentRecord;
CString m_strCursorName;
// Perform operation based on m_nEditMode
BOOL UpdateInsertDelete();
BOOL m_nLockMode; // Control concurrency for Edit()
UDWORD m_dwDriverConcurrency; // driver supported concurrency types
UDWORD m_dwConcurrency; // requested concurrency type
UWORD* m_rgRowStatus; // row status used by SQLExtendedFetch and SQLSetPos
DWORD m_dwRowsFetched; // number of rows fetched by SQLExtendedFetch
HSTMT m_hstmtUpdate;
BOOL m_bRecordsetDb;
BOOL m_bBOF;
BOOL m_bEOF;
BOOL m_bUpdatable; // Is recordset updatable?
BOOL m_bAppendable;
CString m_strSQL; // SQL statement for recordset
CString m_strUpdateSQL; // SQL statement for updates
CString m_strTableName; // source table of recordset
BOOL m_bScrollable; // supports MovePrev
BOOL m_bDeleted;
int m_nFieldsBound;
BYTE* m_pbFieldFlags;
BYTE* m_pbParamFlags;
LONG* m_plParamLength;
DWORD m_dwInitialGetDataLen; // Initial GetFieldValue alloc size for long data
DWORD m_dwRowsetSize;
DWORD m_dwAllocatedRowsetSize;
protected:
CString m_strRequerySQL; // archive SQL string for use in Requery()
CString m_strRequeryFilter; // archive filter string for use in Requery()
CString m_strRequerySort; // archive sort string for use in Requery()
void SetState(int nOpenType, LPCTSTR lpszSQL, DWORD dwOptions);
BOOL AllocHstmt();
void BuildSQL(LPCTSTR lpszSQL);
void PrepareAndExecute();
void BuildSelectSQL();
void AppendFilterAndSortSQL();
BOOL IsRecordsetUpdatable();
void VerifyDriverBehavior();
DWORD VerifyCursorSupport();
void EnableBookmarks();
void SetUpdateMethod();
void SetConcurrencyAndCursorType(HSTMT hstmt, DWORD dwScrollOptions);
void AllocAndCacheFieldInfo();
void AllocRowset();
void FreeRowset();
void ExecuteSetPosUpdate();
void PrepareUpdateHstmt();
void BuildUpdateSQL();
void ExecuteUpdateSQL();
void SendLongBinaryData(HSTMT hstmt);
virtual long GetLBFetchSize(long lOldSize); // CLongBinary fetch chunking
virtual long GetLBReallocSize(long lOldSize); // CLongBinary realloc chunking
friend class CFieldExchange;
friend class CRecordView;
};
/////////////////////////////////////////////////////////////////////////////
// Info helper definitions
#define AFX_CURRENT_RECORD_UNDEFINED (-2)
#define AFX_CURRENT_RECORD_BOF (-1)
// For returning status for a recordset
struct CRecordsetStatus
{
long m_lCurrentRecord; // -2=Unknown,-1=BOF,0=1st record. . .
BOOL m_bRecordCountFinal;// Have we counted all records?
};
// Must maintian data binding info
struct CFieldInfo
{
// MFC specific info
void* m_pvDataCache;
long m_nLength;
int m_nDataType;
BYTE m_bStatus;
#ifdef _DEBUG
void* m_pvBindAddress;
#endif
};
struct CODBCFieldInfo
{
// meta data from ODBC
CString m_strName;
SWORD m_nSQLType;
UDWORD m_nPrecision;
SWORD m_nScale;
SWORD m_nNullability;
};
struct CODBCParamInfo
{
// meta data from ODBC
SWORD m_nSQLType;
UDWORD m_nPrecision;
SWORD m_nScale;
SWORD m_nNullability;
};
/////////////////////////////////////////////////////////////////////////////
// CDBVariant
#define DBVT_NULL 0
#define DBVT_BOOL 1
#define DBVT_UCHAR 2
#define DBVT_SHORT 3
#define DBVT_LONG 4
#define DBVT_SINGLE 5
#define DBVT_DOUBLE 6
#define DBVT_DATE 7
#define DBVT_STRING 8
#define DBVT_BINARY 9
class CDBVariant
{
// Constructor
public:
CDBVariant();
// Attributes
public:
DWORD m_dwType;
union
{
BOOL m_boolVal;
unsigned char m_chVal;
short m_iVal;
long m_lVal;
float m_fltVal;
double m_dblVal;
TIMESTAMP_STRUCT* m_pdate;
CString* m_pstring;
CLongBinary* m_pbinary;
};
// Operations
void Clear();
// Implementation
public:
virtual ~CDBVariant();
};
/////////////////////////////////////////////////////////////////////////////
// CRecordView - form for viewing data records
#ifdef _AFXDLL
class CRecordView : public CFormView
#else
class AFX_NOVTABLE CRecordView : public CFormView
#endif
{
DECLARE_DYNAMIC(CRecordView)
// Construction
protected: // must derive your own class
CRecordView(LPCTSTR lpszTemplateName);
CRecordView(UINT nIDTemplate);
// Attributes
public:
virtual CRecordset* OnGetRecordset() = 0;
BOOL IsOnLastRecord();
BOOL IsOnFirstRecord();
// Operations
public:
virtual BOOL OnMove(UINT nIDMoveCommand);
// Implementation
public:
virtual ~CRecordView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
virtual void OnInitialUpdate();
protected:
BOOL m_bOnFirstRecord;
BOOL m_bOnLastRecord;
//{{AFX_MSG(CRecordView)
afx_msg void OnUpdateRecordFirst(CCmdUI* pCmdUI);
afx_msg void OnUpdateRecordPrev(CCmdUI* pCmdUI);
afx_msg void OnUpdateRecordNext(CCmdUI* pCmdUI);
afx_msg void OnUpdateRecordLast(CCmdUI* pCmdUI);
//}}AFX_MSG
afx_msg void OnMove(int cx, int cy);
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// Inline function declarations
#ifdef _AFX_PACKING
#pragma pack(pop)
#endif
#ifdef _AFX_ENABLE_INLINES
#define _AFXDBCORE_INLINE AFX_INLINE
#define _AFXDBRFX_INLINE AFX_INLINE
#define _AFXDBVIEW_INLINE AFX_INLINE
#include <afxdb.inl>
#undef _AFXDBVIEW_INLINE
#undef _AFXDBCORE_INLINE
#undef _AFXDBRFX_INLINE
#endif
#undef AFX_DATA
#define AFX_DATA
#ifdef _AFX_MINREBUILD
#pragma component(minrebuild, on)
#endif
#ifndef _AFX_FULLTYPEINFO
#pragma component(mintypeinfo, off)
#endif
#endif //__AFXDB_H__
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -