ODBCWrappers v1.04
Welcome to ODBCWrappers, a set of C++ classes to provide a complete encapsulation
of ODBC for Windows.
The classes provided are: CODBC::CHandle, CODBC::CEnvironment,
CODBC::CConnection, CODBC::CStatement & CODBC::CDescriptor.
CHandle provides a class based encapsulation of a SQLHANDLE
handle and the various ODBC v3 APIs which work on any SQLHANDLE type handle.
CEnvironment derives from CHandle and provides encapsulation
of a ODBC environment handle. This class allows configuration of ODBC for initial
usage and creation of connections to a database
CConnection derives from CHandle and provides encapsulation
of a logical connection to a database.
CStatement derives from CHandle and provides encapsulation of
an ODBC "statement" which allows execution of commands against a ODBC connection.
CDescriptor derives from CHandle and provides encapsulation
of an ODBC "descriptor".
Finally ODBCWrappers provides a framework which provides accessor maps similar
to the macros provided by the built in Visual C++ ATL OLE DB Consumer templates.
These provide a simple mapping from code using OLE DB and these templates to equivalent
ODBC functionality. This should provide a easy migration path if you want to move
your OLE DB code to ODBC now that Microsoft have recommended that all new native
mode development should use ODBC going forward instead of OLE DB at least when talking
to SQL Server (http://blogs.msdn.com/b/sqlnativeclient/archive/2011/08/29/microsoft-is-aligning-with-odbc-for-native-relational-data-access.aspx).
Similar to the OLE DB classes, both static accessors (CODBC::CAccessor)
and dynamic accessors (CODBC::CDynamicColumnAccessor) are supported.
This decision by Microsoft was one of the driving reasons to implement ODBCWrappers
in the first place as the only ODBC classes available in Visual C++ are MFC specific
(CDatabase/CRecordSet etc) and in-line with Microsoft's strategy it really does
not make sense to restrict our usage of ODBC to MFC specific use cases going forward.
The development of ODBCWrappers took a number of months of hard work researching,
developing and testing and hopefully you should find them useful in your C++ database
programming efforts.
Features
- Provides a simple C++ Header only module to easily encapsulate ODBC.
- Supports both ASCII and UNICODE API's of ODBC on Windows.
- Provides a complete wrapping for all the ODBC v3 functionality.
- Integrates with STL's string classes and the native Windows TCHAR string
data types for easier client coding.
- Should make it easier to use ODBC from non Windows platforms going forward.
Usage
- To use the various ODBCWrappers classes in your project simply #include
ODBCWrappers.h from the test application in your application.
- The classes are only supported on VC 2008 or later.
- Included in the download is a VC 2008 console based application which demonstrates
most of the classes functionality. To run correctly, this sample requires that
a PJ_Test stored procedure is created from the included "Create PJ_Test SP.sql"
script against a local installed instance of the sample AdventureWorks 2008 sample
database from Microsoft. You will also need to create a DSN called "AdventureWorks"
so that the sample app can connect to the database.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
History
V1.0 (13 November 2011)
V1.01 (16 November 2011)
- Updated code to use std::vector instead of std::auto_ptr for allocating
SQLTCHAR temp heap arrays. Thanks to Andrey Karpov for reporting this issue.
- BrowseConnect method which returns a string& parameter now uses a TCHAR*
parameter instead of a SQLTCHAR* parameter for the first parameter
V1.02 (20 November 2011)
- Removed final occurrence of std::auto_ptr usage in CStatement::GetCursorName.
V1.03 (19 February 2013)
- Updated copyright details.
- Updated code to provide default sensible values for the StrLen_or_IndPtr
parameter if it is not explicitly provided by client code.
- Updated the sample app to shown examples of inserting into a table,
iterating across the rows in a table, updating a row in a table and deleting
a row from a table.
- Removed some accidental usage of MFC TRACE and ASSERT functions and
replaced with ATL equivalents.
- Pulling in MS SQL Server extensions header file sqlext.h and associated
functionality is now optional via a new CODBCWRAPPERS_MSSQL_EXTENSIONS
preprocessor value
- Sample app now does not link against MFC for demonstration purposes
V1.04 (21 February 2013)
- Addition of a new CODBCWRAPPERS_MFC_EXTENSIONS preprocessor value which changes the
wrapper classes to more tightly integrate with MFC. Internally the classes will then use
the MFC collection classes and expose a CString interface
- Following a customer request the code should now be compilable in VC 6 for those
diehards still stuck on this compiler.
Contacting the Author
PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
21
February 2013