Author: wyoung
Date: Tue Feb 12 04:09:31 2008
New Revision: 2177
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2177&view=rev
Log:
First cut at using portable integer types in sql_types.h on platforms
where permitted. Also added test/inttypes.cpp, primarily for use on all
other systems, to test whether our guesses about appropriate types
are correct.
Added:
trunk/test/inttypes.cpp
Modified:
trunk/lib/common.h
trunk/lib/sql_types.h
Modified: trunk/lib/common.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/common.h?rev=2177&r1=2176&r2=2177&view=diff
==============================================================================
--- trunk/lib/common.h (original)
+++ trunk/lib/common.h Tue Feb 12 04:09:31 2008
@@ -5,10 +5,10 @@
/// This file mostly takes care of platform differences.
/***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2008 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file. See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2008 by Educational Technology Resources, Inc. Others may
+ also hold copyrights on code in this file. See the CREDITS file in
+ the top directory of the distribution for details.
This file is part of MySQL++.
@@ -56,7 +56,14 @@
// Stuff for Visual C++ only
# if defined(_MSC_VER)
# define MYSQLPP_PLATFORM_VISUAL_CPP
+ // MS *still* doesn't ship stdint.h, through VC++ 2008 at least.
+ // This means we have to take a wild guess at appropriate
+ // integer types in lib/sql_types.h. See test/inttypes.cpp for
+ // tests that check whether we've guessed well.
+# define MYSQLPP_NO_STDINT_H
# if _MSC_VER < 1400
+ // Workarounds for limitations of VC++ 2003 that are
fixed
+ // in 2005 and later.
# undef MYSQLPP_QUERY_THISPTR
# define MYSQLPP_QUERY_THISPTR
dynamic_cast<std::ostream&>(*this)
# undef MYSQLPP_SSQLS_COMPATIBLE
@@ -81,6 +88,11 @@
# pragma warning(disable: 4996)
// Call _snprintf() for VC++ version of snprintf() function
# define snprintf _snprintf
+# elif defined(__MINGW32__)
+ // MinGW uses the MS standard C library, so it, too, lacks
+ // stdint.h. Again, run test/inttypes.cpp to see if the guesses
+ // in lib/sql_types.h are correct on your particular system.
+# define MYSQLPP_NO_STDINT_H
# endif
// Define DLL import/export tags for Windows compilers, where we build
Modified: trunk/lib/sql_types.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/sql_types.h?rev=2177&r1=2176&r2=2177&view=diff
==============================================================================
--- trunk/lib/sql_types.h (original)
+++ trunk/lib/sql_types.h Tue Feb 12 04:09:31 2008
@@ -1,5 +1,9 @@
/// \file sql_types.h
/// \brief Declares the closest C++ equivalent of each MySQL column type
+///
+/// The typedefs defined here are only for the "non-NULL" variants.
+/// To get nullable versions, wrap the appropriate type in the
+/// \c Null<T> template. See null.h for more information.
/***********************************************************************
Copyright (c) 2006-2008 by Educational Technology Resources, Inc.
@@ -27,6 +31,7 @@
#if !defined(MYSQLPP_SQL_TYPES_H_MAIN)
#define MYSQLPP_SQL_TYPES_H_MAIN
+#include "common.h"
#include "tiny_int.h"
#include <string>
@@ -34,28 +39,45 @@
namespace mysqlpp {
#if !defined(DOXYGEN_IGNORE)
-// Doxygen will not generate documentation for this section.
+// Suppress refman documentation for these typedefs, as they're
+// system-dependent.
-// Nearest C++ equivalents of MySQL data types. These are only the "NOT
-// NULL" variants. Wrap these types in MySQL++'s Null<> template to get
-// NULL-able types.
-typedef tiny_int<signed char> sql_tinyint;
-typedef tiny_int<unsigned char> sql_tinyint_unsigned;
-typedef short sql_smallint;
-typedef unsigned short sql_smallint_unsigned;
-typedef int sql_int;
-typedef unsigned int sql_int_unsigned;
-typedef int sql_mediumint;
-typedef unsigned int sql_mediumint_unsigned;
-typedef longlong sql_bigint;
-typedef ulonglong sql_bigint_unsigned;
+// Define C++ integer types that are most nearly equivalent to those
+// used by the MySQL server.
+#if defined(MYSQLPP_NO_STDINT_H)
+ // Boo, we're going to have to wing it.
+ typedef tiny_int<signed char> sql_tinyint;
+ typedef tiny_int<unsigned char> sql_tinyint_unsigned;
+ typedef signed short sql_smallint;
+ typedef unsigned short sql_smallint_unsigned;
+ typedef signed int sql_int;
+ typedef unsigned int sql_int_unsigned;
+ typedef signed int sql_mediumint;
+ typedef unsigned int sql_mediumint_unsigned;
+ typedef longlong sql_bigint;
+ typedef ulonglong sql_bigint_unsigned;
+#else
+ // Assume a system where C99 is supported in C++ in advance of
+ // actual standardization, so we can do this portably.
+# include <stdint.h>
+ typedef tiny_int<int8_t> sql_tinyint;
+ typedef tiny_int<uint8_t> sql_tinyint_unsigned;
+ typedef int16_t sql_smallint;
+ typedef uint16_t sql_smallint_unsigned;
+ typedef int32_t sql_int;
+ typedef uint32_t sql_int_unsigned;
+ typedef int32_t sql_mediumint;
+ typedef uint32_t sql_mediumint_unsigned;
+ typedef int64_t sql_bigint;
+ typedef uint64_t sql_bigint_unsigned;
+#endif
+// Now define typedef equivalencies for the other standard MySQL
+// data types. There aren't serious portability issues here.
typedef float sql_float;
typedef double sql_double;
typedef double sql_decimal;
-
typedef std::string sql_enum;
-
typedef std::string sql_char;
typedef std::string sql_varchar;
typedef std::string sql_tinytext;
Added: trunk/test/inttypes.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/inttypes.cpp?rev=2177&view=auto
==============================================================================
--- trunk/test/inttypes.cpp (added)
+++ trunk/test/inttypes.cpp Tue Feb 12 04:09:31 2008
@@ -1,0 +1,78 @@
+/***********************************************************************
+ test/inttypes.cpp - Tests whether the integer typedef equivalents for
+ SQL types in lib/sql_types.h are correct on this system. If not,
+ you need to change either that file, lib/common.h, or both.
+
+ Copyright (c) 2008 by Educational Technology Resources, Inc.
+ Others may also hold copyrights on code in this file. See the
+ CREDITS file in the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#include <sql_types.h>
+
+#include <iostream>
+
+template <typename IntType>
+static bool
+test_size(const char* desc, IntType value, size_t expected_size)
+{
+ size_t actual_size = sizeof(value);
+ if (actual_size == expected_size) {
+ return true;
+ }
+ else {
+ std::cerr << desc << " is sized incorrectly on this "
+ "platform:" << std::endl << "\t" << actual_size
<<
+ " bytes, not " << expected_size << " as
expected." <<
+ std::endl;
+ return false;
+ }
+}
+
+
+int
+main(int, char* argv[])
+{
+ int failures = 0;
+
+ failures += test_size("sql_tinyint",
+ mysqlpp::sql_tinyint(0), 1) == false;
+ failures += test_size("sql_tinyint_unsigned",
+ mysqlpp::sql_tinyint_unsigned(0), 1) == false;
+ failures += test_size("sql_smallint",
+ mysqlpp::sql_smallint(0), 2) == false;
+ failures += test_size("sql_smallint_unsigned",
+ mysqlpp::sql_smallint_unsigned(0), 2) == false;
+ failures += test_size("sql_mediumint",
+ mysqlpp::sql_mediumint(0), 4) == false;
+ failures += test_size("sql_mediumint_unsigned",
+ mysqlpp::sql_mediumint_unsigned(0), 4) == false;
+ failures += test_size("sql_int",
+ mysqlpp::sql_int(0), 4) == false;
+ failures += test_size("sql_int_unsigned",
+ mysqlpp::sql_int_unsigned(0), 4) == false;
+ failures += test_size("sql_bigint",
+ mysqlpp::sql_bigint(0), 8) == false;
+ failures += test_size("sql_bigint_unsigned",
+ mysqlpp::sql_bigint_unsigned(0), 8) == false;
+
+ return failures;
+}
+
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits