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
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 39 additions and 0 deletions

View File

@ -115,6 +115,7 @@ public:
* @return Value as string
*/
std::string get_string(int64_t column_ind) const;
std::string get_string(const std::string& name) const;
/**
* Read an integer value from the current row and given column.
@ -123,6 +124,7 @@ public:
* @return Value as integer. If the data could not be parsed an error flag is set.
*/
int64_t get_int(int64_t column_ind) const;
int64_t get_int(const std::string& name) const;
/**
* Check if field is null.
@ -140,6 +142,7 @@ public:
* @return Value as boolean. Returns true if the field contains '1'.
*/
bool get_bool(int64_t column_ind) const;
bool get_bool(const std::string& name) const;
/**
* Has a parsing error occurred during current row?

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