- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

sql_types.h
Go to the documentation of this file.
1
8 /***********************************************************************
9 Copyright (c) 2006-2009 by Educational Technology Resources, Inc.
10 Others may also hold copyrights on code in this file. See the
11 CREDITS.txt file in the top directory of the distribution for details.
12
13 This file is part of MySQL++.
14
15 MySQL++ is free software; you can redistribute it and/or modify it
16 under the terms of the GNU Lesser General Public License as published
17 by the Free Software Foundation; either version 2.1 of the License, or
18 (at your option) any later version.
19
20 MySQL++ is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
23 License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with MySQL++; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
28 USA
29 ***********************************************************************/
30
31 #if !defined(MYSQLPP_SQL_TYPES_H_MAIN)
32 #define MYSQLPP_SQL_TYPES_H_MAIN
33
34 #include "common.h"
35 #include "tiny_int.h"
36
37 #include <string>
38
39 #if !defined(MYSQLPP_NO_STDINT_H)
40 # include <stdint.h>
41 #endif
42
43 namespace mysqlpp {
44
45 #if !defined(DOXYGEN_IGNORE)
46 // Suppress refman documentation for these typedefs, as they're
47 // system-dependent.
48
49 // Define C++ integer types that are most nearly equivalent to those
50 // used by the MySQL server.
51 #if defined(MYSQLPP_NO_STDINT_H)
52 // Boo, we're going to have to wing it.
53 typedef tiny_int<signed char> sql_tinyint;
54 typedef tiny_int<unsigned char> sql_tinyint_unsigned;
55 typedef signed short sql_smallint;
56 typedef unsigned short sql_smallint_unsigned;
57 typedef signed int sql_int;
58 typedef unsigned int sql_int_unsigned;
59 typedef signed int sql_mediumint;
60 typedef unsigned int sql_mediumint_unsigned;
61 typedef longlong sql_bigint;
62 typedef ulonglong sql_bigint_unsigned;
63 #else
64 // Assume a system where C99 is supported in C++ in advance of
65 // actual standardization, so we can do this portably.
66 typedef tiny_int<int8_t> sql_tinyint;
67 typedef tiny_int<uint8_t> sql_tinyint_unsigned;
68 typedef int16_t sql_smallint;
69 typedef uint16_t sql_smallint_unsigned;
70 typedef int32_t sql_int;
71 typedef uint32_t sql_int_unsigned;
72 typedef int32_t sql_mediumint;
73 typedef uint32_t sql_mediumint_unsigned;
74 typedef int64_t sql_bigint;
75 typedef uint64_t sql_bigint_unsigned;
76 #endif
77
78 // Now define typedef equivalencies for the other standard MySQL
79 // data types. There aren't serious portability issues here.
80 typedef float sql_float;
81 typedef double sql_double;
82 typedef double sql_decimal;
83 typedef std::string sql_enum;
84 typedef std::string sql_char;
85 typedef std::string sql_varchar;
86 typedef std::string sql_tinytext;
87 typedef std::string sql_text;
88 typedef std::string sql_mediumtext;
89 typedef std::string sql_longtext;
90
91 // Aliases to match the rules MySQL uses in translating data types
92 // from other database servers into its own type system. From:
93 // http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
94 typedef sql_tinyint sql_bool;
95 typedef sql_tinyint sql_boolean;
96 typedef sql_varchar sql_character_varying;
97 typedef sql_decimal sql_fixed;
98 typedef sql_float sql_float4;
99 typedef sql_double sql_float8;
100 typedef sql_tinyint sql_int1;
101 typedef sql_smallint sql_int2;
102 typedef sql_mediumint sql_int3;
103 typedef sql_int sql_int4;
104 typedef sql_bigint sql_int8;
105 typedef sql_mediumtext sql_long_varchar;
106 typedef sql_mediumtext sql_long;
107 typedef sql_mediumint sql_middleint;
108 typedef sql_decimal sql_numeric;
109 #endif // !defined(DOXYGEN_IGNORE)
110
111 } // end namespace mysqlpp
112
113 #endif // !defined(MYSQLPP_SQL_TYPES_H_MAIN)
114
115
116 // The following sections are treated separately to avoid making the
117 // #include tree too dense: if mystring.h (for example) is not yet
118 // #included, no sense pulling it in to define all the typedefs based
119 // on String. The separate #include guards for each section allow
120 // this file to be #included as many times as necessary to build up the
121 // full typedef set. This trickery is necessary because sql_types.h
122 // is needed in a few places within MySQL++, but we can't (and don't)
123 // depend on having the full set of typedefs. mysql++.h #includes this
124 // at a late stage, ensuring that end-user code does see the full set.
125 #if defined(MYSQLPP_MYSTRING_H) && !defined(MYSQLPP_SQL_TYPES_H_MYSTRING) && !defined(DOXYGEN_IGNORE)
126 # define MYSQLPP_SQL_TYPES_H_MYSTRING
127 namespace mysqlpp {
128 typedef String sql_blob;
129 typedef String sql_tinyblob;
130 typedef String sql_mediumblob;
131 typedef String sql_longblob;
132 typedef sql_mediumblob sql_long_varbinary;
133 } // end namespace mysqlpp
134 #endif
135
136
137 #if defined(MYSQLPP_DATETIME_H) && !defined(MYSQLPP_SQL_TYPES_H_DATETIME) && !defined(DOXYGEN_IGNORE)
138 # define MYSQLPP_SQL_TYPES_H_DATETIME
139 namespace mysqlpp {
140 typedef Date sql_date;
141 typedef Time sql_time;
142 typedef DateTime sql_timestamp;
143 typedef DateTime sql_datetime;
144 } // end namespace mysqlpp
145 #endif
146
147
148 #if defined(MYSQLPP_MYSET_H) && !defined(MYSQLPP_SQL_TYPES_H_SET) && !defined(DOXYGEN_IGNORE)
149 # define MYSQLPP_SQL_TYPES_H_SET
150 namespace mysqlpp {
151 typedef Set<> sql_set;
152 } // end namespace mysqlpp
153 #endif
154
155 #if defined(MYSQLPP_NULL_H) && !defined(MYSQLPP_SQL_TYPES_H_NULL) && !defined(DOXYGEN_IGNORE)
156 # define MYSQLPP_SQL_TYPES_H_NULL
157 // We have null.h, so define nullable versions of all the above
158 namespace mysqlpp {
159 typedef Null<sql_bigint> sql_bigint_null;
160 typedef Null<sql_bigint_unsigned> sql_bigint_unsigned_null;
161 typedef Null<sql_bool> sql_bool_null;
162 typedef Null<sql_boolean> sql_boolean_null;
163 typedef Null<sql_char> sql_char_null;
164 typedef Null<sql_character_varying> sql_character_varying_null;
165 typedef Null<sql_decimal> sql_decimal_null;
166 typedef Null<sql_double> sql_double_null;
167 typedef Null<sql_enum> sql_enum_null;
168 typedef Null<sql_fixed> sql_fixed_null;
169 typedef Null<sql_float> sql_float_null;
170 typedef Null<sql_float4> sql_float4_null;
171 typedef Null<sql_float8> sql_float8_null;
172 typedef Null<sql_int> sql_int_null;
173 typedef Null<sql_int1> sql_int1_null;
174 typedef Null<sql_int2> sql_int2_null;
175 typedef Null<sql_int3> sql_int3_null;
176 typedef Null<sql_int4> sql_int4_null;
177 typedef Null<sql_int8> sql_int8_null;
178 typedef Null<sql_int_unsigned> sql_int_unsigned_null;
179 typedef Null<sql_long> sql_long_null;
180 typedef Null<sql_longtext> sql_longtext_null;
181 typedef Null<sql_long_varchar> sql_long_varchar_null;
182 typedef Null<sql_mediumint> sql_mediumint_null;
183 typedef Null<sql_mediumint_unsigned> sql_mediumint_unsigned_null;
184 typedef Null<sql_mediumtext> sql_mediumtext_null;
185 typedef Null<sql_middleint> sql_middleint_null;
186 typedef Null<sql_numeric> sql_numeric_null;
187 typedef Null<sql_smallint> sql_smallint_null;
188 typedef Null<sql_smallint_unsigned> sql_smallint_unsigned_null;
189 typedef Null<sql_text> sql_text_null;
190 typedef Null<sql_tinyint> sql_tinyint_null;
191 typedef Null<sql_tinyint_unsigned> sql_tinyint_unsigned_null;
192 typedef Null<sql_tinytext> sql_tinytext_null;
193 typedef Null<sql_varchar> sql_varchar_null;
194
195 // Also do nullable versions of optional sql_* types, where possible
196 # if defined(MYSQLPP_SQL_TYPES_H_MYSTRING)
197 typedef Null<sql_blob> sql_blob_null;
198 typedef Null<sql_longblob> sql_longblob_null;
199 typedef Null<sql_mediumblob> sql_mediumblob_null;
200 typedef Null<sql_tinyblob> sql_tinyblob_null;
201 typedef Null<sql_long_varbinary> sql_long_varbinary_null;
202 # endif
203 # if defined(MYSQLPP_SQL_TYPES_H_DATETIME)
204 typedef Null<sql_date> sql_date_null;
205 typedef Null<sql_datetime> sql_datetime_null;
206 typedef Null<sql_time> sql_time_null;
207 typedef Null<sql_timestamp> sql_timestamp_null;
208 # endif
209 # if defined(MYSQLPP_SQL_TYPES_H_SET)
210 typedef Null<sql_set> sql_set_null;
211 # endif
212 } // end namespace mysqlpp
213 #endif
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
tiny_int.h
Declares class for holding a SQL TINYINT.