| 1 | #pragma once |
| 2 | |
| 3 | #include <sstream> |
| 4 | #include <mysqlxx/Types.h> |
| 5 | #include <Poco/Exception.h> |
| 6 | |
| 7 | |
| 8 | namespace mysqlxx |
| 9 | { |
| 10 | |
| 11 | /** Общий класс исключений, которые могут быть выкинуты функциями из библиотеки. |
| 12 | * Функции code() и errnum() возвращают номер ошибки MySQL. (см. mysqld_error.h) |
| 13 | */ |
| 14 | struct Exception : public Poco::Exception |
| 15 | { |
| 16 | Exception(const std::string & msg, int code = 0) : Poco::Exception(msg, code) {} |
| 17 | int errnum() const { return code(); } |
| 18 | const char * name() const throw() { return "mysqlxx::Exception" ; } |
| 19 | const char * className() const throw() { return "mysqlxx::Exception" ; } |
| 20 | }; |
| 21 | |
| 22 | |
| 23 | /// Не удалось соединиться с сервером. |
| 24 | struct ConnectionFailed : public Exception |
| 25 | { |
| 26 | ConnectionFailed(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 27 | const char * name() const throw() { return "mysqlxx::ConnectionFailed" ; } |
| 28 | const char * className() const throw() { return "mysqlxx::ConnectionFailed" ; } |
| 29 | }; |
| 30 | |
| 31 | |
| 32 | /// Запрос содержит ошибку. |
| 33 | struct BadQuery : public Exception |
| 34 | { |
| 35 | BadQuery(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 36 | const char * name() const throw() { return "mysqlxx::BadQuery" ; } |
| 37 | const char * className() const throw() { return "mysqlxx::BadQuery" ; } |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | /// Невозможно распарсить значение. |
| 42 | struct CannotParseValue : public Exception |
| 43 | { |
| 44 | CannotParseValue(const std::string & msg, int code = 0) : Exception(msg, code) {} |
| 45 | const char * name() const throw() { return "mysqlxx::CannotParseValue" ; } |
| 46 | const char * className() const throw() { return "mysqlxx::CannotParseValue" ; } |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | std::string errorMessage(MYSQL * driver); |
| 51 | |
| 52 | /// For internal need of library. |
| 53 | void checkError(MYSQL * driver); |
| 54 | void onError(MYSQL * driver); |
| 55 | |
| 56 | } |
| 57 | |