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:
@ -1,5 +1,5 @@
|
|||||||
add_library(mariadbmon SHARED mariadbmon.cc mariadbserver.cc cluster_manipulation.cc cluster_discovery.cc
|
add_library(mariadbmon SHARED mariadbmon.cc mariadbserver.cc cluster_manipulation.cc cluster_discovery.cc
|
||||||
utilities.cc gtid.cc)
|
mariadbmon_common.cc gtid.cc)
|
||||||
target_link_libraries(mariadbmon maxscale-common)
|
target_link_libraries(mariadbmon maxscale-common)
|
||||||
add_dependencies(mariadbmon pcre2)
|
add_dependencies(mariadbmon pcre2)
|
||||||
set_target_properties(mariadbmon PROPERTIES VERSION "1.4.0")
|
set_target_properties(mariadbmon PROPERTIES VERSION "1.4.0")
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <maxscale/modutil.h>
|
#include <maxscale/modutil.h>
|
||||||
#include <maxscale/mysql_utils.h>
|
#include <maxscale/mysql_utils.h>
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
static int add_slave_to_master(long *slaves_list, int list_size, long node_id);
|
static int add_slave_to_master(long *slaves_list, int list_size, long node_id);
|
||||||
static bool check_replicate_ignore_table(MXS_MONITORED_SERVER* database);
|
static bool check_replicate_ignore_table(MXS_MONITORED_SERVER* database);
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <maxscale/clock.h>
|
#include <maxscale/clock.h>
|
||||||
#include <maxscale/mysql_utils.h>
|
#include <maxscale/mysql_utils.h>
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "utilities.hh"
|
#include <maxscale/debug.h>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|||||||
@ -12,8 +12,7 @@
|
|||||||
* of this software will be governed by version 2 or later of the General
|
* of this software will be governed by version 2 or later of the General
|
||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
#include "mariadbmon_common.hh"
|
||||||
#include <maxscale/cppdefs.hh>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file A MariaDB replication cluster monitor
|
* @file A MariaDB replication cluster monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MXS_MODULE_NAME "mariadbmon"
|
|
||||||
|
|
||||||
#include "mariadbmon.hh"
|
#include "mariadbmon.hh"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -30,7 +27,6 @@
|
|||||||
#include <maxscale/utils.h>
|
#include <maxscale/utils.h>
|
||||||
// TODO: For monitorAddParameters
|
// TODO: For monitorAddParameters
|
||||||
#include "../../../core/internal/monitor.h"
|
#include "../../../core/internal/monitor.h"
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|||||||
@ -12,18 +12,15 @@
|
|||||||
* of this software will be governed by version 2 or later of the General
|
* of this software will be governed by version 2 or later of the General
|
||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
#include "mariadbmon_common.hh"
|
||||||
#include <maxscale/cppdefs.hh>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tr1/unordered_map>
|
#include <tr1/unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <maxscale/json_api.h>
|
|
||||||
#include <maxscale/monitor.h>
|
#include <maxscale/monitor.h>
|
||||||
#include <maxscale/thread.h>
|
#include <maxscale/thread.h>
|
||||||
|
|
||||||
#include "mariadbserver.hh"
|
#include "mariadbserver.hh"
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
extern const int PORT_UNKNOWN;
|
extern const int PORT_UNKNOWN;
|
||||||
extern const char * const CN_AUTO_FAILOVER;
|
extern const char * const CN_AUTO_FAILOVER;
|
||||||
|
|||||||
17
server/modules/monitor/mariadbmon/mariadbmon_common.cc
Normal file
17
server/modules/monitor/mariadbmon/mariadbmon_common.cc
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mariadbmon_common.hh"
|
||||||
|
|
||||||
|
/** Server id default value */
|
||||||
|
const int64_t SERVER_ID_UNKNOWN = -1;
|
||||||
35
server/modules/monitor/mariadbmon/mariadbmon_common.hh
Normal file
35
server/modules/monitor/mariadbmon/mariadbmon_common.hh
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common definitions for MariaDBMonitor module. Should be included in every header or source file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MXS_MODULE_NAME "mariadbmon"
|
||||||
|
|
||||||
|
#include <maxscale/cppdefs.hh>
|
||||||
|
#include <maxscale/json_api.h>
|
||||||
|
|
||||||
|
/** Utility macro for printing both MXS_ERROR and json error */
|
||||||
|
#define PRINT_MXS_JSON_ERROR(err_out, format, ...)\
|
||||||
|
do {\
|
||||||
|
MXS_ERROR(format, ##__VA_ARGS__);\
|
||||||
|
if (err_out)\
|
||||||
|
{\
|
||||||
|
*err_out = mxs_json_error_append(*err_out, format, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
extern const int64_t SERVER_ID_UNKNOWN;
|
||||||
@ -17,7 +17,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <maxscale/mysql_utils.h>
|
#include <maxscale/mysql_utils.h>
|
||||||
#include <maxscale/thread.h>
|
#include <maxscale/thread.h>
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@ -405,3 +404,91 @@ bool MariaDBServer::wait_until_gtid(const GtidList& target, int timeout, json_t*
|
|||||||
}
|
}
|
||||||
return gtid_reached;
|
return gtid_reached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueryResult::QueryResult(MYSQL_RES* resultset)
|
||||||
|
: m_resultset(resultset)
|
||||||
|
, m_columns(-1)
|
||||||
|
, m_rowdata(NULL)
|
||||||
|
, m_current_row(-1)
|
||||||
|
{
|
||||||
|
if (m_resultset)
|
||||||
|
{
|
||||||
|
m_columns = mysql_num_fields(m_resultset);
|
||||||
|
MYSQL_FIELD* field_info = mysql_fetch_fields(m_resultset);
|
||||||
|
for (int64_t column_index = 0; column_index < m_columns; column_index++)
|
||||||
|
{
|
||||||
|
string key(field_info[column_index].name);
|
||||||
|
// TODO: Think of a way to handle duplicate names nicely. Currently this should only be used
|
||||||
|
// for known queries.
|
||||||
|
ss_dassert(m_col_indexes.count(key) == 0);
|
||||||
|
m_col_indexes[key] = column_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryResult::~QueryResult()
|
||||||
|
{
|
||||||
|
if (m_resultset)
|
||||||
|
{
|
||||||
|
mysql_free_result(m_resultset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QueryResult::next_row()
|
||||||
|
{
|
||||||
|
m_rowdata = mysql_fetch_row(m_resultset);
|
||||||
|
if (m_rowdata != NULL)
|
||||||
|
{
|
||||||
|
m_current_row++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t QueryResult::get_row_index() const
|
||||||
|
{
|
||||||
|
return m_current_row;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t QueryResult::get_column_count() const
|
||||||
|
{
|
||||||
|
return m_columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t QueryResult::get_col_index(const string& col_name) const
|
||||||
|
{
|
||||||
|
auto iter = m_col_indexes.find(col_name);
|
||||||
|
return (iter != m_col_indexes.end()) ? iter->second : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
string QueryResult::get_string(int64_t column_ind) const
|
||||||
|
{
|
||||||
|
ss_dassert(column_ind < m_columns);
|
||||||
|
char* data = m_rowdata[column_ind];
|
||||||
|
return data ? data : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t QueryResult::get_uint(int64_t column_ind) const
|
||||||
|
{
|
||||||
|
ss_dassert(column_ind < m_columns);
|
||||||
|
char* data = m_rowdata[column_ind];
|
||||||
|
int64_t rval = -1;
|
||||||
|
if (data && *data)
|
||||||
|
{
|
||||||
|
errno = 0; // strtoll sets this
|
||||||
|
char* endptr = NULL;
|
||||||
|
auto parsed = strtoll(data, &endptr, 10);
|
||||||
|
if (parsed >= 0 && errno == 0 && *endptr == '\0')
|
||||||
|
{
|
||||||
|
rval = parsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QueryResult::get_bool(int64_t column_ind) const
|
||||||
|
{
|
||||||
|
ss_dassert(column_ind < m_columns);
|
||||||
|
char* data = m_rowdata[column_ind];
|
||||||
|
return data ? (strcmp(data,"Y") == 0 || strcmp(data, "1") == 0) : false;
|
||||||
|
}
|
||||||
|
|||||||
@ -12,13 +12,10 @@
|
|||||||
* of this software will be governed by version 2 or later of the General
|
* of this software will be governed by version 2 or later of the General
|
||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
#include "mariadbmon_common.hh"
|
||||||
#include <maxscale/cppdefs.hh>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <maxscale/monitor.h>
|
#include <maxscale/monitor.h>
|
||||||
#include "utilities.hh"
|
|
||||||
#include "gtid.hh"
|
#include "gtid.hh"
|
||||||
|
|
||||||
enum mysql_server_version
|
enum mysql_server_version
|
||||||
@ -34,6 +31,8 @@ enum print_repl_warnings_t
|
|||||||
WARNINGS_OFF
|
WARNINGS_OFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QueryResult;
|
||||||
|
|
||||||
// Contains data returned by one row of SHOW ALL SLAVES STATUS
|
// Contains data returned by one row of SHOW ALL SLAVES STATUS
|
||||||
class SlaveStatusInfo
|
class SlaveStatusInfo
|
||||||
{
|
{
|
||||||
@ -163,3 +162,78 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool wait_until_gtid(const GtidList& target, int timeout, json_t** err_out);
|
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
|
||||||
|
};
|
||||||
|
|||||||
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 MariaDB Corporation Ab
|
|
||||||
*
|
|
||||||
* Use of this software is governed by the Business Source License included
|
|
||||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
||||||
*
|
|
||||||
* Change Date: 2020-01-01
|
|
||||||
*
|
|
||||||
* On the date above, in accordance with the Business Source License, use
|
|
||||||
* of this software will be governed by version 2 or later of the General
|
|
||||||
* Public License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "utilities.hh"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <maxscale/debug.h>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
/** Server id default value */
|
|
||||||
const int64_t SERVER_ID_UNKNOWN = -1;
|
|
||||||
|
|
||||||
QueryResult::QueryResult(MYSQL_RES* resultset)
|
|
||||||
: m_resultset(resultset)
|
|
||||||
, m_columns(-1)
|
|
||||||
, m_rowdata(NULL)
|
|
||||||
, m_current_row(-1)
|
|
||||||
{
|
|
||||||
if (m_resultset)
|
|
||||||
{
|
|
||||||
m_columns = mysql_num_fields(m_resultset);
|
|
||||||
MYSQL_FIELD* field_info = mysql_fetch_fields(m_resultset);
|
|
||||||
for (int64_t column_index = 0; column_index < m_columns; column_index++)
|
|
||||||
{
|
|
||||||
string key(field_info[column_index].name);
|
|
||||||
// TODO: Think of a way to handle duplicate names nicely. Currently this should only be used
|
|
||||||
// for known queries.
|
|
||||||
ss_dassert(m_col_indexes.count(key) == 0);
|
|
||||||
m_col_indexes[key] = column_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QueryResult::~QueryResult()
|
|
||||||
{
|
|
||||||
if (m_resultset)
|
|
||||||
{
|
|
||||||
mysql_free_result(m_resultset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QueryResult::next_row()
|
|
||||||
{
|
|
||||||
m_rowdata = mysql_fetch_row(m_resultset);
|
|
||||||
if (m_rowdata != NULL)
|
|
||||||
{
|
|
||||||
m_current_row++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t QueryResult::get_row_index() const
|
|
||||||
{
|
|
||||||
return m_current_row;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t QueryResult::get_column_count() const
|
|
||||||
{
|
|
||||||
return m_columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t QueryResult::get_col_index(const string& col_name) const
|
|
||||||
{
|
|
||||||
auto iter = m_col_indexes.find(col_name);
|
|
||||||
return (iter != m_col_indexes.end()) ? iter->second : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
string QueryResult::get_string(int64_t column_ind) const
|
|
||||||
{
|
|
||||||
ss_dassert(column_ind < m_columns);
|
|
||||||
char* data = m_rowdata[column_ind];
|
|
||||||
return data ? data : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t QueryResult::get_uint(int64_t column_ind) const
|
|
||||||
{
|
|
||||||
ss_dassert(column_ind < m_columns);
|
|
||||||
char* data = m_rowdata[column_ind];
|
|
||||||
int64_t rval = -1;
|
|
||||||
if (data && *data)
|
|
||||||
{
|
|
||||||
errno = 0; // strtoll sets this
|
|
||||||
char* endptr = NULL;
|
|
||||||
auto parsed = strtoll(data, &endptr, 10);
|
|
||||||
if (parsed >= 0 && errno == 0 && *endptr == '\0')
|
|
||||||
{
|
|
||||||
rval = parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QueryResult::get_bool(int64_t column_ind) const
|
|
||||||
{
|
|
||||||
ss_dassert(column_ind < m_columns);
|
|
||||||
char* data = m_rowdata[column_ind];
|
|
||||||
return data ? (strcmp(data,"Y") == 0 || strcmp(data, "1") == 0) : false;
|
|
||||||
}
|
|
||||||
@ -1,107 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 MariaDB Corporation Ab
|
|
||||||
*
|
|
||||||
* Use of this software is governed by the Business Source License included
|
|
||||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
||||||
*
|
|
||||||
* Change Date: 2020-01-01
|
|
||||||
*
|
|
||||||
* On the date above, in accordance with the Business Source License, use
|
|
||||||
* of this software will be governed by version 2 or later of the General
|
|
||||||
* Public License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <maxscale/cppdefs.hh>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <maxscale/json_api.h>
|
|
||||||
#include <maxscale/monitor.h>
|
|
||||||
|
|
||||||
/** Utility macro for printing both MXS_ERROR and json error */
|
|
||||||
#define PRINT_MXS_JSON_ERROR(err_out, format, ...)\
|
|
||||||
do {\
|
|
||||||
MXS_ERROR(format, ##__VA_ARGS__);\
|
|
||||||
if (err_out)\
|
|
||||||
{\
|
|
||||||
*err_out = mxs_json_error_append(*err_out, format, ##__VA_ARGS__);\
|
|
||||||
}\
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
extern const int64_t SERVER_ID_UNKNOWN;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user