You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
clang format apply
This commit is contained in:
@ -30,112 +30,107 @@ using namespace std;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
|
||||
LibMySQL::LibMySQL() : fCon(NULL), fRes(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LibMySQL::~LibMySQL()
|
||||
{
|
||||
if (fRes)
|
||||
{
|
||||
mysql_free_result(fRes);
|
||||
}
|
||||
if (fRes)
|
||||
{
|
||||
mysql_free_result(fRes);
|
||||
}
|
||||
|
||||
fRes = NULL;
|
||||
fRes = NULL;
|
||||
|
||||
if (fCon)
|
||||
{
|
||||
mysql_close(fCon);
|
||||
}
|
||||
if (fCon)
|
||||
{
|
||||
mysql_close(fCon);
|
||||
}
|
||||
|
||||
fCon = NULL;
|
||||
fCon = NULL;
|
||||
}
|
||||
|
||||
|
||||
int LibMySQL::init(const char* h, unsigned int p, const char* u, const char* w, const char* d)
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
fCon = mysql_init(NULL);
|
||||
fCon = mysql_init(NULL);
|
||||
|
||||
config::Config* cf = config::Config::makeConfig();
|
||||
const string TLSCA = cf->getConfig("CrossEngineSupport", "TLSCA");
|
||||
const string TLSClientCert = cf->getConfig("CrossEngineSupport", "TLSClientCert");
|
||||
const string TLSClientKey = cf->getConfig("CrossEngineSupport", "TLSClientKey");
|
||||
config::Config* cf = config::Config::makeConfig();
|
||||
const string TLSCA = cf->getConfig("CrossEngineSupport", "TLSCA");
|
||||
const string TLSClientCert = cf->getConfig("CrossEngineSupport", "TLSClientCert");
|
||||
const string TLSClientKey = cf->getConfig("CrossEngineSupport", "TLSClientKey");
|
||||
|
||||
if (!(TLSCA.empty() || TLSClientCert.empty() || TLSClientKey.empty()))
|
||||
if (!(TLSCA.empty() || TLSClientCert.empty() || TLSClientKey.empty()))
|
||||
{
|
||||
mysql_ssl_set(fCon, TLSClientKey.c_str(), TLSClientCert.c_str(), TLSCA.c_str(), NULL, NULL);
|
||||
}
|
||||
|
||||
if (fCon != NULL)
|
||||
{
|
||||
unsigned int tcp_option = MYSQL_PROTOCOL_TCP;
|
||||
mysql_options(fCon, MYSQL_OPT_PROTOCOL, &tcp_option);
|
||||
|
||||
if (mysql_real_connect(fCon, h, u, w, d, p, NULL, 0) == NULL)
|
||||
{
|
||||
mysql_ssl_set(fCon, TLSClientKey.c_str(), TLSClientCert.c_str(),
|
||||
TLSCA.c_str(), NULL, NULL);
|
||||
}
|
||||
|
||||
if (fCon != NULL)
|
||||
{
|
||||
unsigned int tcp_option = MYSQL_PROTOCOL_TCP;
|
||||
mysql_options(fCon, MYSQL_OPT_PROTOCOL, &tcp_option);
|
||||
|
||||
if (mysql_real_connect(fCon, h, u, w, d, p, NULL, 0) == NULL)
|
||||
{
|
||||
fErrStr = "fatal error running mysql_real_connect() in libmysql_client lib";
|
||||
ret = mysql_errno(fCon);
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_set_character_set(fCon, "utf8");
|
||||
}
|
||||
fErrStr = "fatal error running mysql_real_connect() in libmysql_client lib";
|
||||
ret = mysql_errno(fCon);
|
||||
}
|
||||
else
|
||||
{
|
||||
fErrStr = "fatal error running mysql_init() in libmysql_client lib";
|
||||
ret = -1;
|
||||
mysql_set_character_set(fCon, "utf8");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fErrStr = "fatal error running mysql_init() in libmysql_client lib";
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int LibMySQL::run(const char* query, bool resultExpected)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (mysql_real_query(fCon, query, strlen(query)) != 0)
|
||||
{
|
||||
fErrStr = "fatal error runing mysql_real_query() in libmysql_client lib";
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
fRes = mysql_use_result(fCon);
|
||||
|
||||
if (fRes == NULL && resultExpected)
|
||||
{
|
||||
fErrStr = "fatal error running mysql_use_result() or empty result set in libmysql_client lib";
|
||||
ret = -1;
|
||||
}
|
||||
int ret = 0;
|
||||
|
||||
if (mysql_real_query(fCon, query, strlen(query)) != 0)
|
||||
{
|
||||
fErrStr = "fatal error runing mysql_real_query() in libmysql_client lib";
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
fRes = mysql_use_result(fCon);
|
||||
|
||||
if (fRes == NULL && resultExpected)
|
||||
{
|
||||
fErrStr = "fatal error running mysql_use_result() or empty result set in libmysql_client lib";
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LibMySQL::handleMySqlError(const char* errStr, int errCode)
|
||||
{
|
||||
ostringstream oss;
|
||||
ostringstream oss;
|
||||
|
||||
if (getErrno())
|
||||
{
|
||||
oss << errStr << " (" << getErrno() << ")";
|
||||
oss << " (" << getErrorMsg() << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << errStr << " (" << errCode << ")";
|
||||
oss << " (unknown)";
|
||||
}
|
||||
if (getErrno())
|
||||
{
|
||||
oss << errStr << " (" << getErrno() << ")";
|
||||
oss << " (" << getErrorMsg() << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << errStr << " (" << errCode << ")";
|
||||
oss << " (unknown)";
|
||||
}
|
||||
|
||||
throw logging::IDBExcept(oss.str(), logging::ERR_CROSS_ENGINE_CONNECT);
|
||||
throw logging::IDBExcept(oss.str(), logging::ERR_CROSS_ENGINE_CONNECT);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace utils
|
||||
|
@ -25,72 +25,69 @@
|
||||
|
||||
namespace utils
|
||||
{
|
||||
|
||||
class LibMySQL
|
||||
{
|
||||
public:
|
||||
LibMySQL();
|
||||
~LibMySQL();
|
||||
public:
|
||||
LibMySQL();
|
||||
~LibMySQL();
|
||||
|
||||
// init: host port username passwd db
|
||||
int init(const char*, unsigned int, const char*, const char*, const char*);
|
||||
// init: host port username passwd db
|
||||
int init(const char*, unsigned int, const char*, const char*, const char*);
|
||||
|
||||
// run the query
|
||||
int run(const char* q, bool resultExpected = true);
|
||||
// run the query
|
||||
int run(const char* q, bool resultExpected = true);
|
||||
|
||||
void handleMySqlError(const char*, int);
|
||||
void handleMySqlError(const char*, int);
|
||||
|
||||
MYSQL* getMySqlCon()
|
||||
{
|
||||
return fCon;
|
||||
}
|
||||
int getFieldCount()
|
||||
{
|
||||
return mysql_num_fields(fRes);
|
||||
}
|
||||
int getRowCount()
|
||||
{
|
||||
return mysql_num_rows(fRes);
|
||||
}
|
||||
char** nextRow()
|
||||
{
|
||||
char** row = mysql_fetch_row(fRes);
|
||||
fieldLengths = mysql_fetch_lengths(fRes);
|
||||
fFields = mysql_fetch_fields(fRes);
|
||||
return row;
|
||||
}
|
||||
long getFieldLength(int field)
|
||||
{
|
||||
return fieldLengths[field];
|
||||
}
|
||||
MYSQL_FIELD* getField(int field)
|
||||
{
|
||||
return &fFields[field];
|
||||
}
|
||||
const std::string& getError()
|
||||
{
|
||||
return fErrStr;
|
||||
}
|
||||
unsigned int getErrno()
|
||||
{
|
||||
return mysql_errno(fCon);
|
||||
}
|
||||
const char* getErrorMsg()
|
||||
{
|
||||
return mysql_error(fCon);
|
||||
}
|
||||
MYSQL* getMySqlCon()
|
||||
{
|
||||
return fCon;
|
||||
}
|
||||
int getFieldCount()
|
||||
{
|
||||
return mysql_num_fields(fRes);
|
||||
}
|
||||
int getRowCount()
|
||||
{
|
||||
return mysql_num_rows(fRes);
|
||||
}
|
||||
char** nextRow()
|
||||
{
|
||||
char** row = mysql_fetch_row(fRes);
|
||||
fieldLengths = mysql_fetch_lengths(fRes);
|
||||
fFields = mysql_fetch_fields(fRes);
|
||||
return row;
|
||||
}
|
||||
long getFieldLength(int field)
|
||||
{
|
||||
return fieldLengths[field];
|
||||
}
|
||||
MYSQL_FIELD* getField(int field)
|
||||
{
|
||||
return &fFields[field];
|
||||
}
|
||||
const std::string& getError()
|
||||
{
|
||||
return fErrStr;
|
||||
}
|
||||
unsigned int getErrno()
|
||||
{
|
||||
return mysql_errno(fCon);
|
||||
}
|
||||
const char* getErrorMsg()
|
||||
{
|
||||
return mysql_error(fCon);
|
||||
}
|
||||
|
||||
private:
|
||||
MYSQL* fCon;
|
||||
MYSQL_RES* fRes;
|
||||
MYSQL_FIELD* fFields;
|
||||
std::string fErrStr;
|
||||
unsigned long* fieldLengths;
|
||||
private:
|
||||
MYSQL* fCon;
|
||||
MYSQL_RES* fRes;
|
||||
MYSQL_FIELD* fFields;
|
||||
std::string fErrStr;
|
||||
unsigned long* fieldLengths;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif // UTILS_LIBMYSQL_CL_H
|
||||
|
||||
|
Reference in New Issue
Block a user