Main | License | Installation | FAQ | Screenshots | Contact | Links | Sf.net | Freshmeat.net | KDE-Apps.org
Requirements | Design | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

ODBCDatabase Class Reference

#include <odbcDatabase.hpp>

Inheritance diagram for ODBCDatabase:

Inheritance graph
[legend]

Public Member Functions

 ODBCDatabase (const std::string &databaseName, const std::string &userName, const std::string &passWord) throw (Error)
virtual ~ODBCDatabase (void)
 Destructor.
virtual StatementPtr execQuery (const std::string &query) throw (Error)

Protected Attributes

SQLHENV odbcEnvironment
 ODBC environment handle.
SQLHDBC connection
 Connection handle.

Detailed Description

Class for connecting to ODBC-database.
Deprecated:
{The ODBC classes are not in use at the moment}
Date:
Thu Mar 03 2005
Author:
Jan Wedekind (wedesoft@users.sourceforge.net)

Definition at line 27 of file odbcDatabase.hpp.


Constructor & Destructor Documentation

ODBCDatabase::ODBCDatabase ( const std::string &  databaseName,
const std::string &  userName,
const std::string &  passWord 
) throw (Error)

Constructor establishing connection to the data source.

Parameters:
databaseName Name of unixODBC's data source.
userName Name of database user.
passWord Password of user. The password will be passed to the SQLConnect command.

Definition at line 24 of file odbcDatabase.cpp.

References odbcWrap().

00026                                                                      :
00027   Database( userName ), odbcEnvironment( NULL ), connection( NULL )
00028 {
00029   
00030   bool connected = false;
00031 
00032   try {
00033     // 1. allocate Environment handle and register version 
00034     odbcWrap( SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE,
00035                               &odbcEnvironment ), SQL_NULL_HANDLE, NULL );
00036     
00037     odbcWrap( SQLSetEnvAttr( odbcEnvironment, SQL_ATTR_ODBC_VERSION,
00038                              (void*)SQL_OV_ODBC3, 0 ),
00039               SQL_HANDLE_ENV, odbcEnvironment );
00040 
00041     odbcWrap( SQLAllocHandle( SQL_HANDLE_DBC, odbcEnvironment, &connection ),
00042               SQL_HANDLE_ENV, odbcEnvironment );
00043 
00044     // 2. allocate connection handle, set timeout
00045     odbcWrap( SQLSetConnectAttr( connection, SQL_LOGIN_TIMEOUT,
00046                                  (SQLPOINTER *)5, 0 ),
00047               SQL_HANDLE_DBC, connection );
00048 
00049     // 3. Connect to the datasource "web" 
00050     odbcWrap( SQLConnect( connection, (SQLCHAR*)databaseName.c_str(), SQL_NTS,
00051                           (SQLCHAR*)userName.c_str(), SQL_NTS,
00052                           (SQLCHAR*)passWord.c_str(), SQL_NTS ),
00053               SQL_HANDLE_DBC, connection );
00054 
00055     connected = true;
00056 
00057   } catch ( Error &e ) {
00058 
00059     if ( connected ) {
00060       assert( connection );
00061       SQLDisconnect( connection );
00062     };
00063     if ( connection )
00064       SQLFreeHandle( SQL_HANDLE_DBC, connection );
00065     if ( odbcEnvironment )
00066       SQLFreeHandle( SQL_HANDLE_ENV, odbcEnvironment );
00067     throw e;
00068 
00069   };
00070 
00071 };

ODBCDatabase::~ODBCDatabase ( void   )  [virtual]

Destructor.

Definition at line 73 of file odbcDatabase.cpp.

References connection, and odbcEnvironment.

00074 {
00075   assert( connection );
00076   SQLDisconnect( connection );
00077   SQLFreeHandle( SQL_HANDLE_DBC, connection );
00078   assert( odbcEnvironment );
00079   SQLFreeHandle( SQL_HANDLE_ENV, odbcEnvironment );
00080 }


Member Function Documentation

StatementPtr ODBCDatabase::execQuery ( const std::string &  query  )  throw (Error) [virtual]

Execute single query. The returned Statement object allows requesting the results of the query.

Implements Database.

Definition at line 82 of file odbcDatabase.cpp.

References connection.

00083 {
00084   StatementPtr retVal( new ODBCStatement( connection, query ) );
00085   return retVal;
00086 }


Field Documentation

SQLHENV ODBCDatabase::odbcEnvironment [protected]

ODBC environment handle.

Definition at line 44 of file odbcDatabase.hpp.

Referenced by ~ODBCDatabase().

SQLHDBC ODBCDatabase::connection [protected]

Connection handle.

Definition at line 46 of file odbcDatabase.hpp.

Referenced by execQuery(), and ~ODBCDatabase().


The documentation for this class was generated from the following files:

anymeal 0.30 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Sep 14 16:01:29 2008 - GNU Free Documentation License