a record to hold return columns for a given statement More...
#include <mysqlpl.h>


Public Member Functions | |
| SqlRecord (SqlStatement &stmt) | |
| int | get_column_count () const |
| const ColumnType & | get_column_type (int idx) const |
| const ColumnType & | get_column_type (const std::string &col_name) const |
| void | print_columns (std::ostream &out) |
| void | print_values (std::ostream &out) |
Protected Types | |
| typedef std::map< std::string, int > | NameMap |
Protected Member Functions | |
| NameMap::const_iterator | find_column (const std::string &col_name) const |
| int | get_column_idx (const std::string &col_name) const |
Protected Attributes | |
| SqlStatement & | _stmt |
| ColumnVector | _columns |
| NameMap | _name_map |
a record to hold return columns for a given statement
Definition at line 1047 of file mysqlpl.h.
typedef std::map<std::string, int> MySqlPL::SqlRecord::NameMap [protected] |
| MySqlPL::SqlRecord::SqlRecord | ( | SqlStatement & | stmt ) |
Definition at line 859 of file mysqlpl.cpp.
References _columns, MySqlPL::SqlStatement::get_column_count(), and MySqlPL::SqlStatement::get_meta_res().
: _stmt(stmt) { int column_cnt = stmt.get_column_count(); _columns.resize(column_cnt); // unsigned num_fields = mysql_num_fields(stmt.get_meta_res()); MYSQL_FIELD* fields = mysql_fetch_fields(stmt.get_meta_res()); for(ColumnVector::iterator it=_columns.begin(); it!=_columns.end(); ++it) { it->_type.init(fields++); #if MYSQLPL_PREP_STMT it->_column = SqlVariant(it->_type._data_type); #endif } //_name_map.clear(); }

| SqlRecord::NameMap::const_iterator MySqlPL::SqlRecord::find_column | ( | const std::string & | col_name ) | const [protected] |
Definition at line 908 of file mysqlpl.cpp.
References _columns, _name_map, and _strupr_s.
Referenced by get_column_idx(), and get_column_type().
{
std::string upper_name;
// initialize column name map
if (_name_map.empty()) {
int idx = 0;
for(ColumnVector::const_iterator it=_columns.begin(); it!=_columns.end(); ++it,++idx) {
upper_name = it->_type._name.c_str();
_strupr_s((char*)upper_name.data(), upper_name.length()+1);
_name_map[upper_name] = idx;
}
}
upper_name = col_name;
_strupr_s((char*)upper_name.data(), upper_name.length()+1);
return _name_map.find(upper_name);
}

| int MySqlPL::SqlRecord::get_column_count | ( | ) | const [inline] |
| int MySqlPL::SqlRecord::get_column_idx | ( | const std::string & | col_name ) | const [protected] |
Definition at line 930 of file mysqlpl.cpp.
References _name_map, find_column(), and THROW_MYSQLPL_EXCEPTION.
Referenced by MySqlPL::SqlResult::get_double(), MySqlPL::SqlResult::get_int(), MySqlPL::SqlResult::get_string(), MySqlPL::SqlResult::is_not_null(), and MySqlPL::SqlResult::is_null().
{
NameMap::const_iterator found = find_column(col_name);
if (found != _name_map.end())
return found->second;
else {
THROW_MYSQLPL_EXCEPTION("column not found");
return -1;
}
}


| const ColumnType& MySqlPL::SqlRecord::get_column_type | ( | int | idx ) | const [inline] |
| const ColumnType & MySqlPL::SqlRecord::get_column_type | ( | const std::string & | col_name ) | const |
Definition at line 880 of file mysqlpl.cpp.
References _columns, _name_map, find_column(), and THROW_MYSQLPL_EXCEPTION.
{
NameMap::const_iterator found = find_column(col_name);
if (found != _name_map.end()) {
int idx = found->second;
return _columns[idx]._type;
} else {
THROW_MYSQLPL_EXCEPTION("column not found");
return *(ColumnType*)NULL;
}
}

| void MySqlPL::SqlRecord::print_columns | ( | std::ostream & | out ) |
Definition at line 943 of file mysqlpl.cpp.
References MySqlPL::ColumnType::_name, MySqlPL::ColumnType::_table_name, and MySqlPL::ColumnType::get_type_str().
Referenced by MySqlPL::SqlStatement::print_results().
{
for(ColumnVector::const_iterator it=_columns.begin(); it!=_columns.end(); ++it) {
const ColumnType& type = it->_type;
if (!type._table_name.empty())
out << type._table_name << ".";
out << type._name << ": " << type.get_type_str() << std::endl;
}
out << std::endl;
}


| void MySqlPL::SqlRecord::print_values | ( | std::ostream & | out ) |
Definition at line 957 of file mysqlpl.cpp.
References MySqlPL::ColumnType::_name.
Referenced by MySqlPL::SqlStatement::print_results().
{
#if MYSQLPL_PREP_STMT
for(ColumnVector::const_iterator it=_columns.begin(); it!=_columns.end(); ++it) {
const ColumnType& type = it->_type;
// if (!type._table_name.empty())
// out << type._table_name << ".";
out << type._name << "=" << it->_column.str() << std::endl;
}
#else
for(size_t i=0; i<_columns.size(); ++i) {
const ColumnType& type = _columns[i]._type;
// if (!type._table_name.empty())
// out << type._table_name << ".";
out << type._name << "=" << _stmt->get_string(i) << std::endl;
}
#endif
}

ColumnVector MySqlPL::SqlRecord::_columns [protected] |
Definition at line 1075 of file mysqlpl.h.
Referenced by find_column(), get_column_count(), get_column_type(), and SqlRecord().
NameMap MySqlPL::SqlRecord::_name_map [mutable, protected] |
Definition at line 1078 of file mysqlpl.h.
Referenced by find_column(), get_column_idx(), and get_column_type().
SqlStatement& MySqlPL::SqlRecord::_stmt [protected] |
1.7.2