#include <mysqlpl.h>
Public Member Functions | |
SqlResult (SqlStatement &stmt) | |
bool | is_null (int idx) const |
int | is_null (const std::string &col_name) const |
bool | is_not_null (int idx) const |
int | is_not_null (const std::string &col_name) const |
int | get_int (int idx) const |
int | get_int (const std::string &col_name) const |
double | get_double (int idx) const |
double | get_double (const std::string &col_name) const |
std::string | get_string (int idx) const |
std::string | get_string (const std::string &col_name) const |
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) |
Public Attributes | |
MYSQL_ROW | _row |
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 |
Definition at line 1087 of file mysqlpl.h.
typedef std::map<std::string, int> MySqlPL::SqlRecord::NameMap [protected, inherited] |
MySqlPL::SqlResult::SqlResult | ( | SqlStatement & | stmt ) | [inline] |
SqlRecord::NameMap::const_iterator MySqlPL::SqlRecord::find_column | ( | const std::string & | col_name ) | const [protected, inherited] |
Definition at line 908 of file mysqlpl.cpp.
References MySqlPL::SqlRecord::_columns, MySqlPL::SqlRecord::_name_map, and _strupr_s.
Referenced by MySqlPL::SqlRecord::get_column_idx(), and MySqlPL::SqlRecord::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, inherited] |
Definition at line 1051 of file mysqlpl.h.
References MySqlPL::SqlRecord::_columns.
{return _columns.size();}
int MySqlPL::SqlRecord::get_column_idx | ( | const std::string & | col_name ) | const [protected, inherited] |
Definition at line 930 of file mysqlpl.cpp.
References MySqlPL::SqlRecord::_name_map, MySqlPL::SqlRecord::find_column(), and THROW_MYSQLPL_EXCEPTION.
Referenced by get_double(), get_int(), get_string(), is_not_null(), and 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, inherited] |
Definition at line 1061 of file mysqlpl.h.
References MySqlPL::SqlRecord::_columns.
{return _columns[idx]._type;}
const ColumnType & MySqlPL::SqlRecord::get_column_type | ( | const std::string & | col_name ) | const [inherited] |
Definition at line 880 of file mysqlpl.cpp.
References MySqlPL::SqlRecord::_columns, MySqlPL::SqlRecord::_name_map, MySqlPL::SqlRecord::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; } }
double MySqlPL::SqlResult::get_double | ( | int | idx ) | const [inline] |
Definition at line 1135 of file mysqlpl.h.
References _row.
Referenced by get_double().
{ return atof(_row[idx]); }
double MySqlPL::SqlResult::get_double | ( | const std::string & | col_name ) | const [inline] |
Definition at line 1139 of file mysqlpl.h.
References MySqlPL::SqlRecord::get_column_idx(), and get_double().
{ return get_double(get_column_idx(col_name)); }
int MySqlPL::SqlResult::get_int | ( | int | idx ) | const [inline] |
int MySqlPL::SqlResult::get_int | ( | const std::string & | col_name ) | const [inline] |
Definition at line 1119 of file mysqlpl.h.
References MySqlPL::SqlRecord::get_column_idx(), and get_int().
{ return get_int(get_column_idx(col_name)); }
std::string MySqlPL::SqlResult::get_string | ( | int | idx ) | const [inline] |
Definition at line 1144 of file mysqlpl.h.
References _row.
Referenced by get_string().
{ const char* str = _row[idx]; return str? str: std::string(); }
std::string MySqlPL::SqlResult::get_string | ( | const std::string & | col_name ) | const [inline] |
Definition at line 1149 of file mysqlpl.h.
References MySqlPL::SqlRecord::get_column_idx(), and get_string().
{ return get_string(get_column_idx(col_name)); }
bool MySqlPL::SqlResult::is_not_null | ( | int | idx ) | const [inline] |
Definition at line 1106 of file mysqlpl.h.
References _row.
Referenced by is_not_null().
{ return _row[idx] != NULL; }
int MySqlPL::SqlResult::is_not_null | ( | const std::string & | col_name ) | const [inline] |
Definition at line 1110 of file mysqlpl.h.
References MySqlPL::SqlRecord::get_column_idx(), and is_not_null().
{ return is_not_null(get_column_idx(col_name)); }
int MySqlPL::SqlResult::is_null | ( | const std::string & | col_name ) | const [inline] |
Definition at line 1101 of file mysqlpl.h.
References MySqlPL::SqlRecord::get_column_idx(), and is_null().
{ return is_null(get_column_idx(col_name)); }
bool MySqlPL::SqlResult::is_null | ( | int | idx ) | const [inline] |
void MySqlPL::SqlRecord::print_columns | ( | std::ostream & | out ) | [inherited] |
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 ) | [inherited] |
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, inherited] |
Definition at line 1075 of file mysqlpl.h.
Referenced by MySqlPL::SqlRecord::find_column(), MySqlPL::SqlRecord::get_column_count(), MySqlPL::SqlRecord::get_column_type(), and MySqlPL::SqlRecord::SqlRecord().
NameMap MySqlPL::SqlRecord::_name_map [mutable, protected, inherited] |
Definition at line 1078 of file mysqlpl.h.
Referenced by MySqlPL::SqlRecord::find_column(), MySqlPL::SqlRecord::get_column_idx(), and MySqlPL::SqlRecord::get_column_type().
MYSQL_ROW MySqlPL::SqlResult::_row |
Definition at line 1089 of file mysqlpl.h.
Referenced by MySqlPL::SqlStatement::fetch(), get_double(), get_int(), get_string(), is_not_null(), and is_null().
SqlStatement& MySqlPL::SqlRecord::_stmt [protected, inherited] |