cloudflare/ClickHouse
Publicmirrored fromhttps://github.com/cloudflare/ClickHouse
base/mysqlxx/Exception.h
53lines · modecode
| 1 | #pragma once |
| 2 | |
| 3 | #include <sstream> |
| 4 | #include <Poco/Exception.h> |
| 5 | #include <mysqlxx/Types.h> |
| 6 | |
| 7 | |
| 8 | namespace mysqlxx |
| 9 | { |
| 10 | /// Common exception class for MySQL library. Functions code() and errnum() return error numbers from MySQL, for details see mysqld_error.h |
| 11 | struct Exception : public Poco::Exception |
| 12 | { |
| 13 | Exception(const std::string & msg, int code = 0) : Poco::Exception(msg, code) {} |
| 14 | int errnum() const { return code(); } |
| 15 | const char * name() const throw() override { return "mysqlxx::Exception"; } |
| 16 | const char * className() const throw() override { return "mysqlxx::Exception"; } |
| 17 | }; |
| 18 | |
| 19 | |
| 20 | /// Cannot connect to MySQL server |
| 21 | struct ConnectionFailed : public Exception |
| 22 | { |
| 23 | ConnectionFailed(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 24 | const char * name() const throw() override { return "mysqlxx::ConnectionFailed"; } |
| 25 | const char * className() const throw() override { return "mysqlxx::ConnectionFailed"; } |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | /// Erroneous query. |
| 30 | struct BadQuery : public Exception |
| 31 | { |
| 32 | BadQuery(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 33 | const char * name() const throw() override { return "mysqlxx::BadQuery"; } |
| 34 | const char * className() const throw() override { return "mysqlxx::BadQuery"; } |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | /// Value parsing failure |
| 39 | struct CannotParseValue : public Exception |
| 40 | { |
| 41 | CannotParseValue(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 42 | const char * name() const throw() override { return "mysqlxx::CannotParseValue"; } |
| 43 | const char * className() const throw() override { return "mysqlxx::CannotParseValue"; } |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | std::string errorMessage(MYSQL * driver); |
| 48 | |
| 49 | /// For internal need of library. |
| 50 | void checkError(MYSQL * driver); |
| 51 | [[noreturn]] void onError(MYSQL * driver); |
| 52 | |
| 53 | } |