MySQL++ Reference Manual

MySQL++: common.h Source File

MySQL++ 3.3.0

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 // Disable warning about exporting a class from a DLL which is
93 // derived from a non-exported class in another DLL. This is
94 // safe to do with Standard C++ library types per:
95 //
96 // https://msdn.microsoft.com/en-us/library/3tdb471s.aspx
97 //
98 // We don't hit this any other way in MySQL++.
99 # pragma warning(disable: 4275)
100
101 // Squish warning about passing no args to MAY_THROW() when
102 // building with newer C++ support. We're doing it on purpose.
103 # pragma warning(disable: 4003)
104
105 // Prior to Visual C++ 2015, we must use _snprintf()
106 # if _MSC_VER < 1900
107 # define snprintf _snprintf
108 # endif
109 # endif
110
111 // Define DLL import/export tags for Windows compilers, where we build
112 // the library into a DLL, for LGPL license compatibility reasons.
113 // (This is based on a similar mechanism in wxWindows.)
114
115 #ifdef MYSQLPP_MAKING_DLL
116 // When making the DLL, export tagged symbols, so they appear
117 // in the import library.
118 #define MYSQLPP_EXPORT __declspec(dllexport)
119 #elif !defined(MYSQLPP_NO_DLL)
120 // We must be _using_ the DLL, so import symbols instead.
121 #define MYSQLPP_EXPORT __declspec(dllimport)
122 #else
123 // Not making a DLL at all, so no-op these declspecs
124 #define MYSQLPP_EXPORT
125 #endif
126
127 // We need to use the DOS/Windows path separator here
128 #define MYSQLPP_PATH_SEPARATOR '\\'
129 #else
130 // If not VC++, MinGW, or Xcode, we assume we're on a system using
131 // autoconf, so bring in the config.h file it wrote containing the
132 // config test results. Only do this during the library build, and
133 // even then, not if included from a MySQL++ header file, since
134 // config.h cannot be safely installed with the other headers.
135 # if defined(MYSQLPP_NOT_HEADER) && !defined(MYSQLPP_XCODE)
136 # include "config.h"
137 # endif
138
139 // Make DLL stuff a no-op on this platform.
140 #define MYSQLPP_EXPORT
141
142 // Assume POSIX path separator
143 #define MYSQLPP_PATH_SEPARATOR '/'
144 #endif
145
146 // Workarounds for deprecations in C++11 and newer. We must still
147 // support systems whose contemporaneous C++ compiler only understands
148 // C++98. Because of the large gap between C++98 and C++11, it will
149 // likely be years yet until we can start using C++11 unconditionally
150 // within MySQL++, then years more until we can use C++14, etc.
151 //
152 // C++11 deprecated throwspecs, a feature of C++ that is only used by
153 // the oldest parts of MySQL++. We can't drop the throwspecs until
154 // MySQL++ 4, if we ever get around to that, since that would break
155 // the library's ABI on systems whose C++ compiler still supports
156 // throwspecs. This feature isn't completely gone until C++17, but we
157 // don't want the warnings on certain newer compilers expecting C++11
158 // or newer C++ dialects.
159 #if __cplusplus < 201103L
160 # define MAY_THROW(what) throw(what)
161 #else
162 # define MAY_THROW(junk) noexcept(false)
163 #endif
164
165 // C++11 added unique_ptr as a replacement for auto_ptr. We don't have
166 // the ABI problem above with this one, so we switch to it with the
167 // oldest release possible. As with the above ifdef, this one only
168 // currently works for g++ and clang++.
169 #if __cplusplus >= 201103L
170 # define UNIQUE_PTR(what) std::unique_ptr<what>
171 #else
172 # define UNIQUE_PTR(what) std::auto_ptr<what>
173 #endif
174
175
176 namespace mysqlpp {
177
180 const bool use_exceptions = true;
181
183 enum sql_cmp_type { sql_use_compare };
184
185 #if !defined(DOXYGEN_IGNORE)
186 // Figure out how to get large integer support on this system. Suppress
187 // refman documentation for these typedefs, as they're system-dependent.
188 #if defined(MYSQLPP_NO_LONG_LONGS)
189 // Alias "longlong" and "ulonglong" to the regular "long" counterparts
190 typedef unsigned long ulonglong;
191 typedef long longlong;
192 #elif defined(_MSC_VER)
193 // It's VC++, so we'll use Microsoft's 64-bit integer types
194 typedef unsigned __int64 ulonglong;
195 typedef __int64 longlong;
196 #else
197 // No better idea, so assume the C99 convention. If your compiler
198 // doesn't support this, please provide a patch to extend this ifdef, or
199 // define MYSQLPP_NO_LONG_LONGS.
200 typedef unsigned long long ulonglong;
201 typedef long long longlong;
202 #endif
203 #endif // !defined(DOXYGEN_IGNORE)
204
205 #if !defined(MYSQLPP_NO_UNSIGNED_INT_TYPES)
211 typedef unsigned long ulong;
212 #endif
213
214 } // end namespace mysqlpp
215
216 // The MySQL headers define these macros, which is completely wrong in a
217 // C++ project. Undo the damage.
218 #undef min
219 #undef max
220
221 #endif // !defined(DOXYGEN_IGNORE)
222
223
224 // Now that we've defined all the stuff above, we can pull in the full
225 // MySQL header. Basically, the above largely replaces MySQL's my_global.h
226 // while actually working with C++. This is why we disobey the MySQL
227 // developer docs, which recommend including my_global.h before mysql.h.
228 extern "C" {
229 #if defined(MYSQLPP_MYSQL_HEADERS_BURIED)
230 # include <mysql/mysql.h>
231 #else
232 # include <mysql.h>
233 #endif
234 }
235
236 // The Unicode chapter of the user manual justifies the following.
237 #if MYSQL_VERSION_ID >= 50500
244 # define MYSQLPP_UTF8_CS "utf8mb4"
245
248 # define MYSQLPP_UTF8_COL "utf8mb4_general_ci"
249 #else
255 # define MYSQLPP_UTF8_CS "utf8"
256
259 # define MYSQLPP_UTF8_COL "utf8_general_ci"
260 #endif
261
262 #endif // !defined(MYSQLPP_COMMON_H)