#include <odbcStatement.hpp>

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 ResultRowPtr & | fetchRow (void) throw (Error) |
| Fetch row of resulting row. | |
Protected Attributes | |
| SQLHSTMT | statement |
| ResultRowPtr | resultRow |
Class for executing SQL query and querying results.
ODBCDatabase::execQuery to acquire an instance of this class. Definition at line 28 of file odbcStatement.hpp.
| ODBCStatement::ODBCStatement | ( | SQLHDBC | connection, | |
| const std::string & | query | |||
| ) | throw (Error) |
Constructor requiring SQLHDBC handle. Call ODBCDatabase::execQuery to acquire an instance of this class.
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] |
| 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.
| 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.
0 if there is none. Implements Statement.
Definition at line 56 of file odbcStatement.cpp.
References odbcWrap(), and statement.
ResultRowPtr ODBCStatement::resultRow [protected] |
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().