MXS-2441: Extend maxsql extraction functions

Having helper methods that combine the index position search and value
extraction make it easier to deal with results that have a lot of fields
e.g. the output of SHOW SLAVE STATUS.
This commit is contained in:
Markus Mäkelä
2019-04-17 15:48:32 +03:00
parent 24fc82e160
commit dda813f3aa
2 changed files with 39 additions and 0 deletions

View File

@ -155,11 +155,35 @@ string QueryResult::get_string(int64_t column_ind) const
return data ? data : "";
}
string QueryResult::get_string(const std::string& name) const
{
auto idx = get_col_index(name);
if (idx != -1)
{
return get_string(idx);
}
return "";
}
int64_t QueryResult::get_int(int64_t column_ind) const
{
return parse_integer(column_ind, "integer");
}
int64_t QueryResult::get_int(const std::string& name) const
{
auto idx = get_col_index(name);
if (idx != -1)
{
return get_int(idx);
}
return 0;
}
/**
* Parse a 64bit integer. On parse error an error flag is set.
*
@ -212,6 +236,18 @@ bool QueryResult::get_bool(int64_t column_ind) const
return rval;
}
bool QueryResult::get_bool(const std::string& name) const
{
auto idx = get_col_index(name);
if (idx != -1)
{
return get_bool(idx);
}
return 0;
}
bool QueryResult::field_is_null(int64_t column_ind) const
{
mxb_assert(column_ind < get_col_count() && column_ind >= 0 && m_rowdata);