MySQL++  3.2.4
common.h
Go to the documentation of this file.
1 
7 /***********************************************************************
8  Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB,
9  © 2004-2009, 2018 by Educational Technology Resources, Inc., and
10  © 2009 by Warren Young. Others may also hold copyrights on code
11  in this file. See the CREDITS.txt file in the top directory of the
12  distribution for details.
13 
14  This file is part of MySQL++.
15 
16  MySQL++ is free software; you can redistribute it and/or modify it
17  under the terms of the GNU Lesser General Public License as published
18  by the Free Software Foundation; either version 2.1 of the License, or
19  (at your option) any later version.
20 
21  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public
27  License along with MySQL++; if not, write to the Free Software
28  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29  USA
30 ***********************************************************************/
31 
32 #if !defined(MYSQLPP_COMMON_H)
33 #define MYSQLPP_COMMON_H
34 
35 #if !defined(DOXYGEN_IGNORE)
36 // Doxygen will not generate documentation for the following stuff.
37 
38 // Enable SSQLS by default. Turned off below on platforms where we
39 // know it doesn't work.
40 #define MYSQLPP_SSQLS_COMPATIBLE
41 
42 // For all platforms but Visual C++ 2003, the following macro is just
43 // an alias for "*this". It needs a more complicated definition on
44 // VC++ 2003 to work around an error in the overloaded operator lookup
45 // logic. For an explanation of the problem, see:
46 // http://groups.google.com/group/microsoft.public.vc.stl/browse_thread/thread/9a68d84644e64f15
47 #define MYSQLPP_QUERY_THISPTR *this
48 
49 // Work out major platform-specific stuff here.
50 #if defined(__WIN32__) || defined(_WIN32)
51 # define MYSQLPP_PLATFORM_WINDOWS
52  // Windows compiler support. Tested with Microsoft Visual C++,
53  // Borland C++ Builder, and MinGW GCC.
54 
55  // Don't let windows.h (via Connector/C) #define min/max
56  #define NOMINMAX
57 
58  // Stuff for Visual C++ only
59 # if defined(_MSC_VER)
60 # define MYSQLPP_PLATFORM_VISUAL_CPP
61  // MS *still* doesn't ship stdint.h, through VC++ 2008 at least.
62  // This means we have to take a wild guess at appropriate
63  // integer types in lib/sql_types.h. See test/inttypes.cpp for
64  // tests that check whether we've guessed well.
65 # define MYSQLPP_NO_STDINT_H
66 # if _MSC_VER < 1400
67  // Workarounds for limitations of VC++ 2003 that are fixed
68  // in 2005 and later.
69 # undef MYSQLPP_QUERY_THISPTR
70 # define MYSQLPP_QUERY_THISPTR dynamic_cast<std::ostream&>(*this)
71 # undef MYSQLPP_SSQLS_COMPATIBLE
72 # elif !defined(_STLP_VERSION) && !defined(_STLP_VERSION_STR)
73  // VC++ 2005 or newer and not using STLport, so #define
74  // portability flags indicating features we can use from
75  // the compiler's native RTL.
76 # define MYSQLPP_HAVE_LOCALTIME_S
77 # define MYSQLPP_HAVE_STD__NOINIT
78 # endif
79 
80  // Disable complaints about STL data members: VC++ believes
81  // these need to be __declspec(dllexport) for some reason.
82 # pragma warning(disable: 4251)
83  // Disable complaint that VC++ doesn't grok throw specs
84 # pragma warning(disable: 4290)
85  // Disable whining about using 'this' as a member initializer on VC++.
86 # pragma warning(disable: 4355)
87  // Disable whining about implicit conversions to bool
88 # pragma warning(disable: 4800)
89  // Disable nagging about new "secure" functions like strncpy_s()
90 # pragma warning(disable: 4996)
91 
92  // Prior to Visual C++ 2015, we must use _snprintf()
93 # if _MSC_VER < 1900
94 # define snprintf _snprintf
95 # endif
96 # endif
97 
98  // Define DLL import/export tags for Windows compilers, where we build
99  // the library into a DLL, for LGPL license compatibility reasons.
100  // (This is based on a similar mechanism in wxWindows.)
101 
102  #ifdef MYSQLPP_MAKING_DLL
103  // When making the DLL, export tagged symbols, so they appear
104  // in the import library.
105  #define MYSQLPP_EXPORT __declspec(dllexport)
106  #elif !defined(MYSQLPP_NO_DLL)
107  // We must be _using_ the DLL, so import symbols instead.
108  #define MYSQLPP_EXPORT __declspec(dllimport)
109  #else
110  // Not making a DLL at all, so no-op these declspecs
111  #define MYSQLPP_EXPORT
112  #endif
113 
114  // We need to use the DOS/Windows path separator here
115  #define MYSQLPP_PATH_SEPARATOR '\\'
116 #else
117  // If not VC++, MinGW, or Xcode, we assume we're on a system using
118  // autoconf, so bring in the config.h file it wrote containing the
119  // config test results. Only do this during the library build, and
120  // even then, not if included from a MySQL++ header file, since
121  // config.h cannot be safely installed with the other headers.
122 # if defined(MYSQLPP_NOT_HEADER) && !defined(MYSQLPP_XCODE)
123 # include "config.h"
124 # endif
125 
126  // Make DLL stuff a no-op on this platform.
127  #define MYSQLPP_EXPORT
128 
129  // Assume POSIX path separator
130  #define MYSQLPP_PATH_SEPARATOR '/'
131 #endif
132 
133 // Workarounds for deprecations in C++11 and newer. We must still
134 // support systems whose contemporaneous C++ compiler only understands
135 // C++98. Because of the large gap between C++98 and C++11, it will
136 // likely be years yet until we can start using C++11 unconditionally
137 // within MySQL++, then years more until we can use C++14, etc.
138 //
139 // Our test here currently only works for g++ and clang++: it's testing
140 // for C++17.
141 //
142 // That release finally did away with throwspecs, a feature of C++ that
143 // is only used by the oldest parts of MySQL++. We can't drop the
144 // throwspecs until MySQL++ 4, if we ever get around to that, since
145 // that would break the library's ABI on systems whose C++ compiler
146 // still supports throwspecs.
147 #if __cplusplus < 201703L
148 # define MAY_THROW(what) throw(what)
149 #else
150 # define MAY_THROW(junk) noexcept(false)
151 #endif
152 
153 // C++11 added unique_ptr as a replacement for auto_ptr. We don't have
154 // the ABI problem above with this one, so we switch to it with the
155 // oldest release possible. As with the above ifdef, this one only
156 // currently works for g++ and clang++.
157 #if __cplusplus >= 201103L
158 # define UNIQUE_PTR(what) std::unique_ptr<what>
159 #else
160 # define UNIQUE_PTR(what) std::auto_ptr<what>
161 #endif
162 
163 
164 namespace mysqlpp {
165 
168 const bool use_exceptions = true;
169 
171 enum sql_cmp_type { sql_use_compare };
172 
173 #if !defined(DOXYGEN_IGNORE)
174 // Figure out how to get large integer support on this system. Suppress
175 // refman documentation for these typedefs, as they're system-dependent.
176 #if defined(MYSQLPP_NO_LONG_LONGS)
177 // Alias "longlong" and "ulonglong" to the regular "long" counterparts
178 typedef unsigned long ulonglong;
179 typedef long longlong;
180 #elif defined(_MSC_VER)
181 // It's VC++, so we'll use Microsoft's 64-bit integer types
182 typedef unsigned __int64 ulonglong;
183 typedef __int64 longlong;
184 #else
185 // No better idea, so assume the C99 convention. If your compiler
186 // doesn't support this, please provide a patch to extend this ifdef, or
187 // define MYSQLPP_NO_LONG_LONGS.
188 typedef unsigned long long ulonglong;
189 typedef long long longlong;
190 #endif
191 #endif // !defined(DOXYGEN_IGNORE)
192 
193 #if !defined(MYSQLPP_NO_UNSIGNED_INT_TYPES)
194 typedef unsigned long ulong;
200 #endif
201 
202 } // end namespace mysqlpp
203 
204 // The MySQL headers define these macros, which is completely wrong in a
205 // C++ project. Undo the damage.
206 #undef min
207 #undef max
208 
209 #endif // !defined(DOXYGEN_IGNORE)
210 
211 
212 // Now that we've defined all the stuff above, we can pull in the full
213 // MySQL header. Basically, the above largely replaces MySQL's my_global.h
214 // while actually working with C++. This is why we disobey the MySQL
215 // developer docs, which recommend including my_global.h before mysql.h.
216 #if defined(MYSQLPP_MYSQL_HEADERS_BURIED)
217 # include <mysql/mysql.h>
218 #else
219 # include <mysql.h>
220 #endif
221 
222 // The Unicode chapter of the user manual justifies the following.
223 #if MYSQL_VERSION_ID >= 50500
224 # define MYSQLPP_UTF8_CS "utf8mb4"
231 
234 # define MYSQLPP_UTF8_COL "utf8mb4_general_ci"
235 #else
236 # define MYSQLPP_UTF8_CS "utf8"
242 
245 # define MYSQLPP_UTF8_COL "utf8_general_ci"
246 #endif
247 
248 #endif // !defined(MYSQLPP_COMMON_H)
Definition: autoflag.h:31