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

ODBCStatement Class Reference

#include <odbcStatement.hpp>

Inheritance diagram for ODBCStatement:

Inheritance graph
[legend]

Public Member Functions

 ODBCStatement (SQLHDBC connection, const std::string &query) throw (Error)
virtual ~ODBCStatement (void)
 Destructor frees the statement handle.
virtual int getNumCols (void) throw (Error)
virtual std::string getColAttr (int col) throw (Error)
virtual ResultRowPtrfetchRow (void) throw (Error)
 Fetch row of resulting row.

Protected Attributes

SQLHSTMT statement
ResultRowPtr resultRow

Detailed Description

Class for executing SQL query and querying results.
Deprecated:
{The ODBC classes are not in use at the moment} Call ODBCDatabase::execQuery to acquire an instance of this class.
Date:
Thu Mar 03 2005
Author:
Jan Wedekind (wedesoft@users.sourceforge.net)

Definition at line 28 of file odbcStatement.hpp.


Constructor & Destructor Documentation

ODBCStatement::ODBCStatement ( SQLHDBC  connection,
const std::string &  query 
) throw (Error)

Constructor requiring SQLHDBC handle. Call ODBCDatabase::execQuery to acquire an instance of this class.

See also:
ODBCDatabase::execQuery

Definition at line 23 of file odbcStatement.cpp.

References ERRORMACRO, odbcWrap(), and Error::what().

00024                :
00025   statement( NULL )
00026 {
00027   try {
00028     if ( !query.empty() ) {
00029       odbcWrap( SQLAllocHandle( SQL_HANDLE_STMT, connection, &statement ),
00030                 SQL_HANDLE_STMT, statement );
00031 
00032       assert( statement );
00033       assert( sizeof( char ) == sizeof( SQLCHAR ) );
00034 #ifndef NDEBUG
00035       cerr << query << endl;
00036 #endif
00037       odbcWrap( SQLExecDirect( statement, (SQLCHAR *)query.c_str(), SQL_NTS ),
00038                 SQL_HANDLE_STMT, statement );
00039     };
00040   } catch ( Error &e ) {
00041     if ( statement )
00042       SQLFreeHandle( SQL_HANDLE_STMT, statement );
00043     ERRORMACRO( false, Error, ,
00044                 "Error in query \"" << query << "\": " << e.what() );
00045   }
00046 }

ODBCStatement::~ODBCStatement ( void   )  [virtual]

Destructor frees the statement handle.

Definition at line 48 of file odbcStatement.cpp.

References resultRow, and statement.

00049 {
00050   if ( resultRow )
00051     resultRow->invalidate();
00052   if( statement )
00053     SQLFreeHandle( SQL_HANDLE_STMT, statement );
00054 }


Member Function Documentation

int ODBCStatement::getNumCols ( void   )  throw (Error) [virtual]

Get number of result columns.

Returns:
Number of resulting columns of a SELECT query. 0 if there is none.

Implements Statement.

Definition at line 56 of file odbcStatement.cpp.

References odbcWrap(), and statement.

Referenced by getColAttr().

00057 {
00058   SQLSMALLINT retVal;
00059   if ( statement )
00060     odbcWrap( SQLNumResultCols( statement, &retVal ),
00061               SQL_HANDLE_STMT, statement );
00062   else
00063     retVal = 0;
00064   return retVal;
00065 }

std::string ODBCStatement::getColAttr ( int  col  )  throw (Error) [virtual]

Meta information about column.

Parameters:
col Number of column (between 0 and getNumCols()-1).

Implements Statement.

Definition at line 67 of file odbcStatement.cpp.

References ERRORMACRO, getNumCols(), and statement.

00068 {
00069   SQLCHAR retVal[4096];
00070   ERRORMACRO( col >= 0 && col < getNumCols(), Error, ,
00071               "Column number of meta-column must be between 0 and "
00072               << ( getNumCols() - 1 ) << " but was " << col << "." );
00073   SQLColAttribute( statement, col + 1, SQL_DESC_LABEL, retVal,
00074                    sizeof(retVal), NULL, NULL );
00075   assert( sizeof( SQLCHAR ) == sizeof( char ) );
00076   return (char *)retVal;
00077 }

ResultRowPtr & ODBCStatement::fetchRow ( void   )  throw (Error) [virtual]

Fetch row of resulting row.

Implements Statement.

Definition at line 79 of file odbcStatement.cpp.

References ERRORMACRO, resultRow, and statement.

00080 {
00081   if ( resultRow ) {
00082     ERRORMACRO( resultRow.use_count() <= 1, Error, ,
00083                 "Can not fetch new row, "
00084                 "because previous row was not released yet." );
00085     assert( resultRow.use_count() == 1 );
00086   };
00087   if ( SQL_SUCCEEDED( SQLFetch( statement ) ) )
00088     resultRow = ResultRowPtr( new ODBCResultRow( statement ) );
00089   else
00090     resultRow.reset();
00091   return resultRow;
00092 }


Field Documentation

SQLHSTMT ODBCStatement::statement [protected]

Definition at line 45 of file odbcStatement.hpp.

Referenced by fetchRow(), getColAttr(), getNumCols(), and ~ODBCStatement().

ResultRowPtr ODBCStatement::resultRow [protected]

Definition at line 47 of file odbcStatement.hpp.

Referenced by fetchRow(), and ~ODBCStatement().


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