#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 |
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().
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] |
| 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.
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.
| 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 }
SQLHSTMT ODBCStatement::statement [protected] |
Definition at line 45 of file odbcStatement.hpp.
Referenced by fetchRow(), getColAttr(), getNumCols(), and ~ODBCStatement().
ResultRowPtr ODBCStatement::resultRow [protected] |