# sql_types.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008 /***********************************************************************
    00009  Copyright (c) 2006-2009 by Educational Technology Resources, Inc.
    00010  Others may also hold copyrights on code in this file.  See the
    00011  CREDITS.txt file in the top directory of the distribution for details.
    00012
    00013  This file is part of MySQL++.
    00014
    00015  MySQL++ is free software; you can redistribute it and/or modify it
    00016  under the terms of the GNU Lesser General Public License as published
    00017  by the Free Software Foundation; either version 2.1 of the License, or
    00018  (at your option) any later version.
    00019
    00020  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00021  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00022  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00023  License for more details.
    00024
    00025  You should have received a copy of the GNU Lesser General Public
    00026  License along with MySQL++; if not, write to the Free Software
    00027  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00028  USA
    00029 ***********************************************************************/
    00030
    00031 #if !defined(MYSQLPP_SQL_TYPES_H_MAIN)
    00032 #define MYSQLPP_SQL_TYPES_H_MAIN
    00033
    00034 #include "common.h"
    00035 #include "tiny_int.h"
    00036
    00037 #include <string>
    00038
    00039 #if !defined(MYSQLPP_NO_STDINT_H)
    00040 #       include <stdint.h>
    00041 #endif
    00042
    00043 namespace mysqlpp {
    00044
    00045 #if !defined(DOXYGEN_IGNORE)
    00046 // Suppress refman documentation for these typedefs, as they're
    00047 // system-dependent.
    00048
    00049 // Define C++ integer types that are most nearly equivalent to those
    00050 // used by the MySQL server.
    00051 #if defined(MYSQLPP_NO_STDINT_H)
    00052         // Boo, we're going to have to wing it.
    00053         typedef tiny_int<signed char>   sql_tinyint;
    00054         typedef tiny_int<unsigned char> sql_tinyint_unsigned;
    00055         typedef signed short                    sql_smallint;
    00056         typedef unsigned short                  sql_smallint_unsigned;
    00057         typedef signed int                              sql_int;
    00058         typedef unsigned int                    sql_int_unsigned;
    00059         typedef signed int                              sql_mediumint;
    00060         typedef unsigned int                    sql_mediumint_unsigned;
    00061         typedef longlong                                sql_bigint;
    00062         typedef ulonglong                               sql_bigint_unsigned;
    00063 #else
    00064         // Assume a system where C99 is supported in C++ in advance of
    00065         // actual standardization, so we can do this portably.
    00066         typedef tiny_int<int8_t>                sql_tinyint;
    00067         typedef tiny_int<uint8_t>               sql_tinyint_unsigned;
    00068         typedef int16_t                                 sql_smallint;
    00069         typedef uint16_t                                sql_smallint_unsigned;
    00070         typedef int32_t                                 sql_int;
    00071         typedef uint32_t                                sql_int_unsigned;
    00072         typedef int32_t                                 sql_mediumint;
    00073         typedef uint32_t                                sql_mediumint_unsigned;
    00074         typedef int64_t                                 sql_bigint;
    00075         typedef uint64_t                                sql_bigint_unsigned;
    00076 #endif
    00077
    00078 // Now define typedef equivalencies for the other standard MySQL
    00079 // data types.  There aren't serious portability issues here.
    00080 typedef float                                   sql_float;
    00081 typedef double                                  sql_double;
    00082 typedef double                                  sql_decimal;
    00083 typedef std::string                             sql_enum;
    00084 typedef std::string                             sql_char;
    00085 typedef std::string                             sql_varchar;
    00086 typedef std::string                             sql_tinytext;
    00087 typedef std::string                             sql_text;
    00088 typedef std::string                             sql_mediumtext;
    00089 typedef std::string                             sql_longtext;
    00090
    00091 // Aliases to match the rules MySQL uses in translating data types
    00092 // from other database servers into its own type system.  From:
    00093 // http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
    00094 typedef sql_tinyint                             sql_bool;
    00095 typedef sql_tinyint                             sql_boolean;
    00096 typedef sql_varchar                             sql_character_varying;
    00097 typedef sql_decimal                             sql_fixed;
    00098 typedef sql_float                               sql_float4;
    00099 typedef sql_double                              sql_float8;
    00100 typedef sql_tinyint                             sql_int1;
    00101 typedef sql_smallint                    sql_int2;
    00102 typedef sql_mediumint                   sql_int3;
    00103 typedef sql_int                                 sql_int4;
    00104 typedef sql_bigint                              sql_int8;
    00105 typedef sql_mediumtext                  sql_long_varchar;
    00106 typedef sql_mediumtext                  sql_long;
    00107 typedef sql_mediumint                   sql_middleint;
    00108 typedef sql_decimal                             sql_numeric;
    00109 #endif // !defined(DOXYGEN_IGNORE)
    00110
    00111 } // end namespace mysqlpp
    00112
    00113 #endif // !defined(MYSQLPP_SQL_TYPES_H_MAIN)
    00114
    00115
    00116 // The following sections are treated separately to avoid making the
    00117 // #include tree too dense: if mystring.h (for example) is not yet
    00118 // #included, no sense pulling it in to define all the typedefs based
    00119 // on String.  The separate #include guards for each section allow
    00120 // this file to be #included as many times as necessary to build up the
    00121 // full typedef set.  This trickery is necessary because sql_types.h
    00122 // is needed in a few places within MySQL++, but we can't (and don't)
    00123 // depend on having the full set of typedefs.  mysql++.h #includes this
    00124 // at a late stage, ensuring that end-user code does see the full set.
    00125 #if defined(MYSQLPP_MYSTRING_H) && !defined(MYSQLPP_SQL_TYPES_H_MYSTRING) && !defined(DOXYGEN_IGNORE)
    00126 #       define MYSQLPP_SQL_TYPES_H_MYSTRING
    00127         namespace mysqlpp {
    00128                 typedef String                  sql_blob;
    00129                 typedef String                  sql_tinyblob;
    00130                 typedef String                  sql_mediumblob;
    00131                 typedef String                  sql_longblob;
    00132                 typedef sql_mediumblob  sql_long_varbinary;
    00133         } // end namespace mysqlpp
    00134 #endif
    00135
    00136
    00137 #if defined(MYSQLPP_DATETIME_H) && !defined(MYSQLPP_SQL_TYPES_H_DATETIME) && !defined(DOXYGEN_IGNORE)
    00138 #       define MYSQLPP_SQL_TYPES_H_DATETIME
    00139         namespace mysqlpp {
    00140                 typedef Date                    sql_date;
    00141                 typedef Time                    sql_time;
    00142                 typedef DateTime                sql_timestamp;
    00143                 typedef DateTime                sql_datetime;
    00144         } // end namespace mysqlpp
    00145 #endif
    00146
    00147
    00148 #if defined(MYSQLPP_MYSET_H) && !defined(MYSQLPP_SQL_TYPES_H_SET) && !defined(DOXYGEN_IGNORE)
    00149 #       define MYSQLPP_SQL_TYPES_H_SET
    00150         namespace mysqlpp {
    00151                 typedef Set<>                           sql_set;
    00152         } // end namespace mysqlpp
    00153 #endif
    00154
    00155 #if defined(MYSQLPP_NULL_H) && !defined(MYSQLPP_SQL_TYPES_H_NULL) && !defined(DOXYGEN_IGNORE)
    00156 #       define MYSQLPP_SQL_TYPES_H_NULL
    00157         // We have null.h, so define nullable versions of all the above
    00158         namespace mysqlpp {
    00159                 typedef Null<sql_bigint> sql_bigint_null;
    00160                 typedef Null<sql_bigint_unsigned> sql_bigint_unsigned_null;
    00161                 typedef Null<sql_bool> sql_bool_null;
    00162                 typedef Null<sql_boolean> sql_boolean_null;
    00163                 typedef Null<sql_char> sql_char_null;
    00164                 typedef Null<sql_character_varying> sql_character_varying_null;
    00165                 typedef Null<sql_decimal> sql_decimal_null;
    00166                 typedef Null<sql_double> sql_double_null;
    00167                 typedef Null<sql_enum> sql_enum_null;
    00168                 typedef Null<sql_fixed> sql_fixed_null;
    00169                 typedef Null<sql_float> sql_float_null;
    00170                 typedef Null<sql_float4> sql_float4_null;
    00171                 typedef Null<sql_float8> sql_float8_null;
    00172                 typedef Null<sql_int> sql_int_null;
    00173                 typedef Null<sql_int1> sql_int1_null;
    00174                 typedef Null<sql_int2> sql_int2_null;
    00175                 typedef Null<sql_int3> sql_int3_null;
    00176                 typedef Null<sql_int4> sql_int4_null;
    00177                 typedef Null<sql_int8> sql_int8_null;
    00178                 typedef Null<sql_int_unsigned> sql_int_unsigned_null;
    00179                 typedef Null<sql_long> sql_long_null;
    00180                 typedef Null<sql_longtext> sql_longtext_null;
    00181                 typedef Null<sql_long_varchar> sql_long_varchar_null;
    00182                 typedef Null<sql_mediumint> sql_mediumint_null;
    00183                 typedef Null<sql_mediumint_unsigned> sql_mediumint_unsigned_null;
    00184                 typedef Null<sql_mediumtext> sql_mediumtext_null;
    00185                 typedef Null<sql_middleint> sql_middleint_null;
    00186                 typedef Null<sql_numeric> sql_numeric_null;
    00187                 typedef Null<sql_smallint> sql_smallint_null;
    00188                 typedef Null<sql_smallint_unsigned> sql_smallint_unsigned_null;
    00189                 typedef Null<sql_text> sql_text_null;
    00190                 typedef Null<sql_tinyint> sql_tinyint_null;
    00191                 typedef Null<sql_tinyint_unsigned> sql_tinyint_unsigned_null;
    00192                 typedef Null<sql_tinytext> sql_tinytext_null;
    00193                 typedef Null<sql_varchar> sql_varchar_null;
    00194
    00195                 // Also do nullable versions of optional sql_* types, where possible
    00196 #               if defined(MYSQLPP_SQL_TYPES_H_MYSTRING)
    00197                         typedef Null<sql_blob> sql_blob_null;
    00198                         typedef Null<sql_longblob> sql_longblob_null;
    00199                         typedef Null<sql_mediumblob> sql_mediumblob_null;
    00200                         typedef Null<sql_tinyblob> sql_tinyblob_null;
    00201                         typedef Null<sql_long_varbinary> sql_long_varbinary_null;
    00202 #               endif
    00203 #               if defined(MYSQLPP_SQL_TYPES_H_DATETIME)
    00204                         typedef Null<sql_date> sql_date_null;
    00205                         typedef Null<sql_datetime> sql_datetime_null;
    00206                         typedef Null<sql_time> sql_time_null;
    00207                         typedef Null<sql_timestamp> sql_timestamp_null;
    00208 #               endif
    00209 #               if defined(MYSQLPP_SQL_TYPES_H_SET)
    00210                         typedef Null<sql_set> sql_set_null;
    00211 #               endif
    00212         } // end namespace mysqlpp
    00213 #endif