MXS-1703 Use a common header for all mariadbmon files

The mariadb_common.hh file is now a header with only common definitions
such as module name. The QueryResult-class was moved to MariaDBServer.
This commit is contained in:
Esa Korhonen
2018-04-12 12:02:07 +03:00
parent 7f36339f53
commit b6e421e13b
13 changed files with 222 additions and 236 deletions

View File

@ -12,13 +12,10 @@
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include <maxscale/cppdefs.hh>
#include "mariadbmon_common.hh"
#include <string>
#include <memory>
#include <maxscale/monitor.h>
#include "utilities.hh"
#include "gtid.hh"
enum mysql_server_version
@ -34,6 +31,8 @@ enum print_repl_warnings_t
WARNINGS_OFF
};
class QueryResult;
// Contains data returned by one row of SHOW ALL SLAVES STATUS
class SlaveStatusInfo
{
@ -163,3 +162,78 @@ public:
*/
bool wait_until_gtid(const GtidList& target, int timeout, json_t** err_out);
};
/**
* Helper class for simplifying working with resultsets. Used in MariaDBServer.
*/
class QueryResult
{
// These need to be banned to avoid premature destruction.
QueryResult(const QueryResult&) = delete;
QueryResult& operator = (const QueryResult&) = delete;
public:
QueryResult(MYSQL_RES* resultset = NULL);
~QueryResult();
/**
* Advance to next row. Affects all result returning functions.
*
* @return True if the next row has data, false if the current row was the last one.
*/
bool next_row();
/**
* Get the index of the current row.
*
* @return Current row index, or -1 if no data or next_row() has not been called yet.
*/
int64_t get_row_index() const;
/**
* How many columns the result set has.
*
* @return Column count, or -1 if no data.
*/
int64_t get_column_count() const;
/**
* Get a numeric index for a column name. May give wrong results if column names are not unique.
*
* @param col_name Column name
* @return Index or -1 if not found.
*/
int64_t get_col_index(const std::string& col_name) const;
/**
* Read a string value from the current row and given column. Empty string and (null) are both interpreted
* as the empty string.
*
* @param column_ind Column index
* @return Value as string
*/
std::string get_string(int64_t column_ind) const;
/**
* Read a non-negative integer value from the current row and given column.
*
* @param column_ind Column index
* @return Value as integer. 0 or greater indicates success, -1 is returned on error.
*/
int64_t get_uint(int64_t column_ind) const;
/**
* Read a boolean value from the current row and given column.
*
* @param column_ind Column index
* @return Value as boolean. Returns true if the text is either 'Y' or '1'.
*/
bool get_bool(int64_t column_ind) const;
private:
MYSQL_RES* m_resultset; // Underlying result set, freed at dtor.
std::tr1::unordered_map<std::string, int64_t> m_col_indexes; // Map of column name -> index
int64_t m_columns; // How many columns does the data have. Usually equal to column index map size.
MYSQL_ROW m_rowdata; // Data for current row
int64_t m_current_row; // Index of current row
};