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:
@ -115,6 +115,7 @@ public:
|
|||||||
* @return Value as string
|
* @return Value as string
|
||||||
*/
|
*/
|
||||||
std::string get_string(int64_t column_ind) const;
|
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.
|
* 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.
|
* @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(int64_t column_ind) const;
|
||||||
|
int64_t get_int(const std::string& name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if field is null.
|
* Check if field is null.
|
||||||
@ -140,6 +142,7 @@ public:
|
|||||||
* @return Value as boolean. Returns true if the field contains '1'.
|
* @return Value as boolean. Returns true if the field contains '1'.
|
||||||
*/
|
*/
|
||||||
bool get_bool(int64_t column_ind) const;
|
bool get_bool(int64_t column_ind) const;
|
||||||
|
bool get_bool(const std::string& name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has a parsing error occurred during current row?
|
* Has a parsing error occurred during current row?
|
||||||
|
@ -155,11 +155,35 @@ string QueryResult::get_string(int64_t column_ind) const
|
|||||||
return data ? data : "";
|
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
|
int64_t QueryResult::get_int(int64_t column_ind) const
|
||||||
{
|
{
|
||||||
return parse_integer(column_ind, "integer");
|
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.
|
* 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;
|
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
|
bool QueryResult::field_is_null(int64_t column_ind) const
|
||||||
{
|
{
|
||||||
mxb_assert(column_ind < get_col_count() && column_ind >= 0 && m_rowdata);
|
mxb_assert(column_ind < get_col_count() && column_ind >= 0 && m_rowdata);
|
||||||
|
Reference in New Issue
Block a user