Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC

The CODBCDynamic class

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
14 Mar 2000 189.2K   3.1K   40  
A class to dynamically read data from any ODBC data source
#pragma once

typedef CTypedPtrMap<CMapStringToPtr, CString /* column name */, CDBVariantEx* /* value */> CODBCRecord;
typedef CTypedPtrArray<CObArray, CODBCRecord*> CODBCRecordArray;

class AFX_EXT_CLASS CODBCDynamic
{                           
public:
	CODBCDynamic(LPCSTR lpszDSN, 
		LPCSTR lpszUser = NULL, LPCSTR lpszPassword = NULL, 
		SQLHENV henv = NULL, SQLHDBC hdbc = NULL);
	// throws CUserException

	~CODBCDynamic();

public:
	enum
	{
		errorSqlAllocHandleHenv = 50000,
		errorSqlSetEnvAttr = 50001,
		errorSqlAllocHandleHdbc = 50002,
		errorSqlConnect = 50003,
		errorUnknownCause = 5004
	};

protected:
	void CleanOutRecordArray();
	
protected:
	SQLHENV m_henv;
	SQLHDBC m_hdbc;
	BOOL m_bIsConnected;

public:
	SQLHDBC GetHDBC ()
	{
		return m_hdbc;
	}
		
public:
	CODBCRecordArray m_ODBCRecordArray;

protected:
	short GetFieldTypeFromSQLType(short nSQLType);
	void* GetDataBuffer(CDBVariantEx* pvarValue, short nFieldType, int* pnLen, short nSQLType, UDWORD nPrecision);
	long GetData(SQLHSTMT hstmt, short nFieldIndex, short nFieldType, LPVOID pvData, int nLen, short nSQLType);

public:
	long ExecuteSQL(LPCTSTR lpszSQL);
	long FetchData(HSTMT hstmt);
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Microsoft
United States United States
I manage the strategy for the Azure Management Experience documentation at Microsoft. Those technologies include Open-Source DevOps (Terraform, Ansible, Jenkins), Azure PowerShell, and Azure CLI.

Comments and Discussions