The Battle for Wesnoth  1.15.3+dev
private.hpp
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright Sylvain Rochette Langlois 2013,
5 // Frantisek Boranek 2015,
6 // The ViaDuck Project 2016 - 2018.
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef _MARIADB_PRIVATE_HPP_
12 #define _MARIADB_PRIVATE_HPP_
13 
14 #include <mariadb++/exceptions.hpp>
15 #include <ctime>
16 
17 namespace mariadb {
18 #if _WIN32
19 inline int localtime_safe(struct tm* _tm, const time_t* _time) { return localtime_s(_tm, _time); }
20 
21 inline int gmtime_safe(struct tm* _tm, const time_t* _time) { return gmtime_s(_tm, _time); }
22 #else
23 inline int localtime_safe(struct tm* _tm, const time_t* _time) {
24  return localtime_r(_time, _tm) ? 0 : -1;
25 }
26 
27 inline int gmtime_safe(struct tm* _tm, const time_t* _time) {
28  return gmtime_r(_time, _tm) ? 0 : -1;
29 }
30 #endif
31 }
32 #if _WIN32
33 
34 #if __MINGW32__
35 // this is needed because on mingw sprintf_s is broken (due to msvcrt not following c99 standard
36 // with sprintf...)
37 #define snprintf(buffer, szbuffer, format, ...) __mingw_sprintf(buffer, format, ##__VA_ARGS__)
38 #else
39 #define snprintf sprintf_s
40 #endif
41 
42 #endif
43 
44 #define MARIADB_ERROR_THROW_CONNECTION(error_id, error) \
45  throw exception::connection(error_id, error);
46 #define MARIADB_ERROR_THROW_DATE(_year, _month, _day, _hour, _minute, _second, _millisecond) \
47  throw exception::date_time(_year, _month, _day, _hour, _minute, _second, _millisecond);
48 #define MARIADB_ERROR_THROW_TIME(_hour, _minute, _second, _millisecond) \
49  throw exception::time(_hour, _minute, _second, _millisecond);
50 
51 #define MARIADB_ERROR(error_id, error) \
52  std::cerr << "MariaDB Error(" << error_id << "): " << error \
53  << "\nIn function: " << __FUNCTION__ << "\nIn file " << __FILE__ << "\nOn line " \
54  << __LINE__ << '\n'; \
55  MARIADB_ERROR_THROW_CONNECTION(error_id, error)
56 
57 #define MYSQL_ERROR_NO_BRAKET(mysql) \
58  m_last_error_no = mysql_errno(mysql); \
59  m_last_error = mysql_error(mysql); \
60  MARIADB_ERROR(m_last_error_no, m_last_error);
61 
62 #define MYSQL_ERROR(mysql) \
63  { MYSQL_ERROR_NO_BRAKET(mysql) }
64 
65 #define STMT_ERROR_NO_BRAKET(statement) \
66  m_last_error_no = mysql_stmt_errno(statement); \
67  m_last_error = mysql_stmt_error(statement); \
68  MARIADB_ERROR(m_last_error_no, m_last_error);
69 
70 #define STMT_ERROR(statement) \
71  { STMT_ERROR_NO_BRAKET(statement) }
72 
73 #endif
int gmtime_safe(struct tm *_tm, const time_t *_time)
Definition: private.hpp:27
int localtime_safe(struct tm *_tm, const time_t *_time)
Definition: private.hpp:23