Click here to Skip to main content
12,694,542 members (33,712 online)
Click here to Skip to main content
Articles » Database » Database » ODBC » Downloads

Stats

154.6K views
2.8K downloads
37 bookmarked
Posted

The CODBCDynamic class

, 14 Mar 2000
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

Share

About the Author

Tom Archer
Software Developer (Senior) Microsoft
United States United States
I'm a Senior Programming Writer in the Microsoft Windows Server organization where my focus is WMI, BITS, WinRM, and SMI-S.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 15 Mar 2000
Article Copyright 2000 by Tom Archer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid