2019-09-24 22:28:59 +00:00
|
|
|
#if __has_include(<mysql.h>)
|
|
|
|
#include <mysql.h>
|
2018-07-25 11:29:26 +00:00
|
|
|
#else
|
2017-01-24 21:07:08 +00:00
|
|
|
#include <mysql/mysql.h>
|
2018-07-25 11:29:26 +00:00
|
|
|
#endif
|
2017-01-13 20:37:37 +00:00
|
|
|
#include <mysqlxx/Exception.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace mysqlxx
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string errorMessage(MYSQL * driver)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::stringstream res;
|
2017-12-13 20:22:23 +00:00
|
|
|
res << mysql_error(driver)
|
|
|
|
<< " (" << (driver->host ? driver->host : "(nullptr)")
|
|
|
|
<< ":" << driver->port << ")";
|
2017-04-01 07:20:54 +00:00
|
|
|
return res.str();
|
2017-01-13 20:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Для внутренних нужд библиотеки.
|
|
|
|
void checkError(MYSQL * driver)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
unsigned num = mysql_errno(driver);
|
2017-01-13 20:37:37 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (num)
|
|
|
|
throw Exception(errorMessage(driver), num);
|
2017-01-13 20:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Для внутренних нужд библиотеки.
|
|
|
|
void onError(MYSQL * driver)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception(errorMessage(driver), mysql_errno(driver));
|
2017-01-13 20:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|