Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes

OCIPL::SqlRecord Struct Reference

a record to hold return columns for a given statement More...

#include <ocipl.h>

Inheritance diagram for OCIPL::SqlRecord:
Inheritance graph
[legend]
Collaboration diagram for OCIPL::SqlRecord:
Collaboration graph
[legend]

List of all members.

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
SqlVariantArrayget_column (int idx)
ColumnTypeget_column_type (int idx)
const SqlVariantArrayget_column (int idx) const
const ColumnTypeget_column_type (int idx) const
const ColumnTypeget_column_type (const tstring &col_name) const
const SqlVariantArrayget_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< DataColumnVector
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

Detailed Description

a record to hold return columns for a given statement

Definition at line 3532 of file ocipl.h.


Member Typedef Documentation

typedef std::vector<Data> OCIPL::SqlRecord::ColumnVector [protected]

Definition at line 3578 of file ocipl.h.

typedef std::map<tstring, int> OCIPL::SqlRecord::NameMap [protected]

Definition at line 3582 of file ocipl.h.


Constructor & Destructor Documentation

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();
}

Here is the call graph for this function:

OCIPL::SqlRecord::SqlRecord ( OciEnv env,
size_t  column_cnt 
) [inline]

Definition at line 3535 of file ocipl.h.

: _env(_env) {_values.resize(column_cnt);}
OCIPL::SqlRecord::~SqlRecord (  )

Definition at line 1362 of file ocipl.cpp.

References _values, and iterator.

{
    for(ColumnVector::iterator it=_values.begin(); it!=_values.end(); ++it)
        delete it->_pvar;
}

Member Function Documentation

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);
}

Here is the caller graph for this function:

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);
}

Here is the caller graph for this function:

SqlVariantArray& OCIPL::SqlRecord::get_column ( int  idx ) [inline]

Definition at line 3542 of file ocipl.h.

        {return *_values[idx]._pvar;}
const SqlVariantArray& OCIPL::SqlRecord::get_column ( int  idx ) const [inline]

Definition at line 3547 of file ocipl.h.

        {return *_values[idx]._pvar;}
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;
    }
}

Here is the call graph for this function:

size_t OCIPL::SqlRecord::get_column_count (  ) const [inline]

Definition at line 3539 of file ocipl.h.

        {return _values.size();}
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;
    }
}

Here is the call graph for this function:

const ColumnType& OCIPL::SqlRecord::get_column_type ( int  idx ) const [inline]

Definition at line 3549 of file ocipl.h.

        {return _values[idx]._type;}
ColumnType& OCIPL::SqlRecord::get_column_type ( int  idx ) [inline]

Definition at line 3544 of file ocipl.h.

        {return _values[idx]._type;}
void OCIPL::SqlRecord::print_columns ( tostream out )

Definition at line 1444 of file ocipl.cpp.

References _values, and TEXT.

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");
}

Here is the caller graph for this function:

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");
}

Here is the caller graph for this function:


Member Data Documentation

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


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