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().

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

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 }

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.

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 }

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.

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 }


Field Documentation

Definition at line 47 of file odbcStatement.hpp.

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

SQLHSTMT ODBCStatement::statement [protected]

Definition at line 45 of file odbcStatement.hpp.

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


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


anymeal 0.31 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Dec 19 19:36:05 2010 - GNU Free Documentation License