| 1 | #if __has_include(<mysql.h>) |
|---|---|
| 2 | #include <mysql.h> |
| 3 | #else |
| 4 | #include <mysql/mysql.h> |
| 5 | #endif |
| 6 | #include <mysqlxx/Exception.h> |
| 7 | |
| 8 | |
| 9 | namespace mysqlxx |
| 10 | { |
| 11 | |
| 12 | std::string errorMessage(MYSQL * driver) |
| 13 | { |
| 14 | std::stringstream res; |
| 15 | res << mysql_error(driver) |
| 16 | << " ("<< (driver->host ? driver->host : "(nullptr)") |
| 17 | << ":"<< driver->port << ")"; |
| 18 | return res.str(); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | /// Для внутренних нужд библиотеки. |
| 23 | void checkError(MYSQL * driver) |
| 24 | { |
| 25 | unsigned num = mysql_errno(driver); |
| 26 | |
| 27 | if (num) |
| 28 | throw Exception(errorMessage(driver), num); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /// Для внутренних нужд библиотеки. |
| 33 | void onError(MYSQL * driver) |
| 34 | { |
| 35 | throw Exception(errorMessage(driver), mysql_errno(driver)); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 |