mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
mysqlxx: added server address to exception messages [#METR-9068].
This commit is contained in:
parent
8fd6963212
commit
fa7a666a96
@ -1,6 +1,6 @@
|
||||
#ifndef MYSQLXX_EXCEPTION_H
|
||||
#define MYSQLXX_EXCEPTION_H
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
#include <Poco/Exception.h>
|
||||
@ -48,22 +48,28 @@ struct CannotParseValue : public Exception
|
||||
};
|
||||
|
||||
|
||||
inline std::string errorMessage(MYSQL * driver)
|
||||
{
|
||||
std::stringstream res;
|
||||
res << mysql_error(driver) << " (" << driver->host << ":" << driver->port << ")";
|
||||
return res.str();
|
||||
}
|
||||
|
||||
|
||||
/// Для внутренних нужд библиотеки.
|
||||
inline void checkError(MYSQL * driver)
|
||||
{
|
||||
unsigned num = mysql_errno(driver);
|
||||
|
||||
if (num)
|
||||
throw Exception(mysql_error(driver), num);
|
||||
throw Exception(errorMessage(driver), num);
|
||||
}
|
||||
|
||||
|
||||
/// Для внутренних нужд библиотеки.
|
||||
inline void onError(MYSQL * driver)
|
||||
{
|
||||
throw Exception(mysql_error(driver), mysql_errno(driver));
|
||||
throw Exception(errorMessage(driver), mysql_errno(driver));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -48,30 +48,30 @@ void Connection::connect(const char* db,
|
||||
LibrarySingleton::instance();
|
||||
|
||||
if (!mysql_init(&driver))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
/// Установим таймауты
|
||||
if (mysql_options(&driver, MYSQL_OPT_CONNECT_TIMEOUT, reinterpret_cast<const char *>(&timeout)))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
if (mysql_options(&driver, MYSQL_OPT_READ_TIMEOUT, reinterpret_cast<const char *>(&rw_timeout)))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
if (mysql_options(&driver, MYSQL_OPT_WRITE_TIMEOUT, reinterpret_cast<const char *>(&rw_timeout)))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
/** Включаем возможность использовать запрос LOAD DATA LOCAL INFILE с серверами,
|
||||
* которые были скомпилированы без опции --enable-local-infile.
|
||||
*/
|
||||
if (mysql_options(&driver, MYSQL_OPT_LOCAL_INFILE, NULL))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
if (!mysql_real_connect(&driver, server, user, password, db, port, NULL, driver.client_flag))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
/// Установим кодировки по-умолчанию - UTF-8.
|
||||
if (mysql_set_character_set(&driver, "UTF8"))
|
||||
throw ConnectionFailed(mysql_error(&driver), mysql_errno(&driver));
|
||||
throw ConnectionFailed(errorMessage(&driver), mysql_errno(&driver));
|
||||
|
||||
is_connected = true;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void Query::executeImpl()
|
||||
{
|
||||
std::string query_string = query_buf.str();
|
||||
if (mysql_real_query(conn->getDriver(), query_string.data(), query_string.size()))
|
||||
throw BadQuery(mysql_error(conn->getDriver()), mysql_errno(conn->getDriver()));
|
||||
throw BadQuery(errorMessage(conn->getDriver()), mysql_errno(conn->getDriver()));
|
||||
}
|
||||
|
||||
UseQueryResult Query::use()
|
||||
|
Loading…
Reference in New Issue
Block a user