ClickHouse/base/mysqlxx/Exception.h

54 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
2011-03-03 19:57:34 +00:00
#include <sstream>
2011-03-03 19:57:34 +00:00
#include <Poco/Exception.h>
#include <mysqlxx/Types.h>
2011-03-03 19:57:34 +00:00
namespace mysqlxx
{
/// Common exception class for MySQL library. Functions code() and errnum() return error numbers from MySQL, for details see mysqld_error.h
2011-03-04 20:58:19 +00:00
struct Exception : public Poco::Exception
{
Exception(const std::string & msg, int code = 0) : Poco::Exception(msg, code) {}
int errnum() const { return code(); }
const char * name() const throw() override { return "mysqlxx::Exception"; }
const char * className() const throw() override { return "mysqlxx::Exception"; }
2011-03-04 20:58:19 +00:00
};
2011-03-18 20:26:54 +00:00
/// Cannot connect to MySQL server
2011-03-04 20:58:19 +00:00
struct ConnectionFailed : public Exception
{
ConnectionFailed(const std::string & msg, int code = 0) : Exception(msg, code) {}
const char * name() const throw() override { return "mysqlxx::ConnectionFailed"; }
const char * className() const throw() override { return "mysqlxx::ConnectionFailed"; }
2011-03-04 20:58:19 +00:00
};
2011-03-18 20:26:54 +00:00
/// Erroneous query.
2011-03-04 20:58:19 +00:00
struct BadQuery : public Exception
{
BadQuery(const std::string & msg, int code = 0) : Exception(msg, code) {}
const char * name() const throw() override { return "mysqlxx::BadQuery"; }
const char * className() const throw() override { return "mysqlxx::BadQuery"; }
2011-03-04 20:58:19 +00:00
};
2011-03-03 19:57:34 +00:00
/// Value parsing failure
2011-03-18 20:26:54 +00:00
struct CannotParseValue : public Exception
{
CannotParseValue(const std::string & msg, int code = 0) : Exception(msg, code) {}
const char * name() const throw() override { return "mysqlxx::CannotParseValue"; }
const char * className() const throw() override { return "mysqlxx::CannotParseValue"; }
2011-03-18 20:26:54 +00:00
};
std::string errorMessage(MYSQL * driver);
2011-03-03 19:57:34 +00:00
/// For internal need of library.
void checkError(MYSQL * driver);
[[noreturn]] void onError(MYSQL * driver);
2011-03-03 19:57:34 +00:00
}