common.h
Go to the documentation of this file.
1 
7 /***********************************************************************
8  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB,
9  (c) 2004-2009 by Educational Technology Resources, Inc., and
10  (c) 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 #if defined(MYSQLPP_MYSQL_HEADERS_BURIED)
134 # include <mysql/mysql_version.h>
135 #else
136 # include <mysql_version.h>
137 #endif
138 
139 namespace mysqlpp {
140 
143 const bool use_exceptions = true;
144 
146 enum sql_cmp_type { sql_use_compare };
147 
148 #if !defined(DOXYGEN_IGNORE)
149 // Figure out how to get large integer support on this system. Suppress
150 // refman documentation for these typedefs, as they're system-dependent.
151 #if defined(MYSQLPP_NO_LONG_LONGS)
152 // Alias "longlong" and "ulonglong" to the regular "long" counterparts
153 typedef unsigned long ulonglong;
154 typedef long longlong;
155 #elif defined(_MSC_VER)
156 // It's VC++, so we'll use Microsoft's 64-bit integer types
157 typedef unsigned __int64 ulonglong;
158 typedef __int64 longlong;
159 #else
160 // No better idea, so assume the C99 convention. If your compiler
161 // doesn't support this, please provide a patch to extend this ifdef, or
162 // define MYSQLPP_NO_LONG_LONGS.
163 typedef unsigned long long ulonglong;
164 typedef long long longlong;
165 #endif
166 #endif // !defined(DOXYGEN_IGNORE)
167 
168 #if !defined(MYSQLPP_NO_UNSIGNED_INT_TYPES)
169 typedef unsigned long ulong;
175 #endif
176 
177 } // end namespace mysqlpp
178 
179 // The MySQL headers define these macros, which is completely wrong in a
180 // C++ project. Undo the damage.
181 #undef min
182 #undef max
183 
184 #endif // !defined(DOXYGEN_IGNORE)
185 
186 
187 // Now that we've defined all the stuff above, we can pull in the full
188 // MySQL header. Basically, the above largely replaces MySQL's my_global.h
189 // while actually working with C++. This is why we disobey the MySQL
190 // developer docs, which recommend including my_global.h before mysql.h.
191 #if defined(MYSQLPP_MYSQL_HEADERS_BURIED)
192 # include <mysql/mysql.h>
193 #else
194 # include <mysql.h>
195 #endif
196 
197 #endif // !defined(MYSQLPP_COMMON_H)