a record to hold return columns for a given statement More...
#include <ocipl.h>
Classes | |
struct | Data |
data structure for the content of single column More... | |
Public Member Functions | |
SqlRecord (SqlStatement &stmt, int rows) | |
SqlRecord (OciEnv &env, size_t column_cnt) | |
~SqlRecord () | |
size_t | get_column_count () const |
SqlVariantArray & | get_column (int idx) |
ColumnType & | get_column_type (int idx) |
const SqlVariantArray & | get_column (int idx) const |
const ColumnType & | get_column_type (int idx) const |
const ColumnType & | get_column_type (const tstring &col_name) const |
const SqlVariantArray & | get_column (const tstring &col_name) const |
void | bind_result (SqlStatement &stmt) |
void | alloc_column (size_t col_idx, const ColumnTypeInfo &type, int rows) |
void | print_columns (tostream &out) |
void | print_values (tostream &out, int row) |
Public Attributes | |
OciEnv & | _env |
Protected Types | |
typedef std::vector< Data > | ColumnVector |
typedef std::map< tstring, int > | NameMap |
Protected Member Functions | |
NameMap::const_iterator | find_column (const tstring &col_name) const |
Protected Attributes | |
ColumnVector | _values |
NameMap | _name_map |
a record to hold return columns for a given statement
Definition at line 3532 of file ocipl.h.
typedef std::vector<Data> OCIPL::SqlRecord::ColumnVector [protected] |
typedef std::map<tstring, int> OCIPL::SqlRecord::NameMap [protected] |
OCIPL::SqlRecord::SqlRecord | ( | SqlStatement & | stmt, |
int | rows | ||
) |
Definition at line 1343 of file ocipl.cpp.
References _values, OCIPL::SqlStatement::ensure_execute(), OCIPL::SqlStatement::get_column_count(), OCIPL::SqlStatement::get_column_type(), and iterator.
: _env(stmt._env) { stmt.ensure_execute(); int column_cnt = stmt.get_column_count(); _values.resize(column_cnt); ColumnVector::iterator it = _values.begin(); for(int idx=0; idx<column_cnt; ++idx,++it) { stmt.get_column_type(idx, it->_type); it->_pvar = new SqlVariantArray(it->_type, rows); } //_name_map.clear(); }
OCIPL::SqlRecord::SqlRecord | ( | OciEnv & | env, |
size_t | column_cnt | ||
) | [inline] |
OCIPL::SqlRecord::~SqlRecord | ( | ) |
void OCIPL::SqlRecord::alloc_column | ( | size_t | col_idx, |
const ColumnTypeInfo & | type, | ||
int | rows | ||
) |
Definition at line 1368 of file ocipl.cpp.
References OCIPL::SqlRecord::Data::_pvar, and _values.
{ Data& data = _values[col_idx]; // (re)allocate variant data buffers delete data._pvar; data._pvar = new SqlVariantArray(type, rows); }
void OCIPL::SqlRecord::bind_result | ( | SqlStatement & | stmt ) |
Definition at line 1436 of file ocipl.cpp.
References _values, and iterator.
Referenced by OCIPL::SqlStatement::bind_result().
{ int idx = 0; for(ColumnVector::iterator it=_values.begin(); it!=_values.end(); ++it,++idx) it->_pvar->bind_result(stmt, idx); }
SqlRecord::NameMap::const_iterator OCIPL::SqlRecord::find_column | ( | const tstring & | col_name ) | const [protected] |
Definition at line 1413 of file ocipl.cpp.
References _name_map, _tcsupr_s, _values, and TCHAR.
Referenced by get_column(), and get_column_type().
{ tstring upper_name; // initialize column name map if (_name_map.empty()) { int idx = 0; for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it,++idx) { upper_name = it->_type._name.c_str(); _tcsupr_s((TCHAR*)upper_name.data(), upper_name.length()+1); _name_map[upper_name] = idx; } } upper_name = col_name; _tcsupr_s((TCHAR*)upper_name.data(), upper_name.length()+1); return _name_map.find(upper_name); }
SqlVariantArray& OCIPL::SqlRecord::get_column | ( | int | idx ) | [inline] |
const SqlVariantArray& OCIPL::SqlRecord::get_column | ( | int | idx ) | const [inline] |
const SqlVariantArray & OCIPL::SqlRecord::get_column | ( | const tstring & | col_name ) | const |
Definition at line 1395 of file ocipl.cpp.
References _name_map, _values, find_column(), and THROW_OCI_EXCEPTION.
{ /* for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it) if (!stricmp(it->_type._name.c_str(), col_name.c_str())) return *it->_pvar; */ NameMap::const_iterator found = find_column(col_name); if (found != _name_map.end()) { int idx = found->second; return *_values[idx]._pvar; } else { THROW_OCI_EXCEPTION("column not found"); // return SqlVariantArray::s_empty; } }
size_t OCIPL::SqlRecord::get_column_count | ( | ) | const [inline] |
const ColumnType & OCIPL::SqlRecord::get_column_type | ( | const tstring & | col_name ) | const |
Definition at line 1377 of file ocipl.cpp.
References _name_map, _values, find_column(), and THROW_OCI_EXCEPTION.
{ /* for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it) if (!stricmp(it->_type._name.c_str(), col_name.c_str())) return it->_type; */ NameMap::const_iterator found = find_column(col_name); if (found != _name_map.end()) { int idx = found->second; return _values[idx]._type; } else { THROW_OCI_EXCEPTION("column not found"); // return ColumnType::s_empty; } }
const ColumnType& OCIPL::SqlRecord::get_column_type | ( | int | idx ) | const [inline] |
ColumnType& OCIPL::SqlRecord::get_column_type | ( | int | idx ) | [inline] |
void OCIPL::SqlRecord::print_columns | ( | tostream & | out ) |
Definition at line 1444 of file ocipl.cpp.
Referenced by OCIPL::SqlStatement::print_results().
{ for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it) out << it->_type._name << TEXT(": ") << it->_type.get_type_str() << TEXT("\n"); out << TEXT("\n"); }
void OCIPL::SqlRecord::print_values | ( | tostream & | out, |
int | row | ||
) |
Definition at line 1452 of file ocipl.cpp.
References _env, OCIPL::OciEnv::_errh, _values, and TEXT.
Referenced by OCIPL::SqlStatement::print_results().
{ ColumnVector::const_iterator it_type = _values.begin(); for(ColumnVector::const_iterator it=_values.begin(); it!=_values.end(); ++it,++it_type) out << it->_type._name << TEXT("=") << it->_pvar->str(row, _env._errh) << TEXT("\n"); }
Definition at line 3588 of file ocipl.h.
Referenced by print_values().
NameMap OCIPL::SqlRecord::_name_map [mutable, protected] |
Definition at line 3583 of file ocipl.h.
Referenced by find_column(), get_column(), and get_column_type().
ColumnVector OCIPL::SqlRecord::_values [protected] |
Definition at line 3580 of file ocipl.h.
Referenced by alloc_column(), bind_result(), find_column(), get_column(), get_column_type(), print_columns(), print_values(), SqlRecord(), and ~SqlRecord().