2013-10-26 02:50:23 +00:00
|
|
|
#pragma once
|
2011-03-03 19:57:34 +00:00
|
|
|
|
2013-10-26 02:50:23 +00:00
|
|
|
#include <sstream>
|
2011-03-03 19:57:34 +00:00
|
|
|
#include <Poco/Exception.h>
|
2020-01-21 08:54:26 +00:00
|
|
|
#include <mysqlxx/Types.h>
|
2011-03-03 19:57:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace mysqlxx
|
|
|
|
{
|
2020-01-21 08:54:26 +00:00
|
|
|
/// 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) {}
|
2017-04-01 07:20:54 +00:00
|
|
|
int errnum() const { return code(); }
|
2020-01-21 08:54:26 +00:00
|
|
|
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
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
/// Cannot connect to MySQL server
|
2011-03-04 20:58:19 +00:00
|
|
|
struct ConnectionFailed : public Exception
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
ConnectionFailed(const std::string & msg, int code = 0) : Exception(msg, code) {}
|
2020-01-21 08:54:26 +00:00
|
|
|
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
|
|
|
|
2021-02-27 08:18:28 +00:00
|
|
|
/// Connection to MySQL server was lost
|
|
|
|
struct ConnectionLost : public Exception
|
|
|
|
{
|
|
|
|
ConnectionLost(const std::string & msg, int code = 0) : Exception(msg, code) {}
|
|
|
|
const char * name() const throw() override { return "mysqlxx::ConnectionLost"; }
|
|
|
|
const char * className() const throw() override { return "mysqlxx::ConnectionLost"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
/// Erroneous query.
|
2011-03-04 20:58:19 +00:00
|
|
|
struct BadQuery : public Exception
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
BadQuery(const std::string & msg, int code = 0) : Exception(msg, code) {}
|
2020-01-21 08:54:26 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
/// Value parsing failure
|
2011-03-18 20:26:54 +00:00
|
|
|
struct CannotParseValue : public Exception
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
CannotParseValue(const std::string & msg, int code = 0) : Exception(msg, code) {}
|
2020-01-21 08:54:26 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-13 20:37:37 +00:00
|
|
|
std::string errorMessage(MYSQL * driver);
|
2011-03-03 19:57:34 +00:00
|
|
|
|
2017-01-13 20:37:37 +00:00
|
|
|
/// For internal need of library.
|
|
|
|
void checkError(MYSQL * driver);
|
2020-05-09 22:59:34 +00:00
|
|
|
[[noreturn]] void onError(MYSQL * driver);
|
2011-03-03 19:57:34 +00:00
|
|
|
|
|
|
|
}
|