466
by Monty Taylor
Fixed modelines... these files are c++. |
1 |
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
3 |
*
|
|
4 |
* Copyright (C) 2008 MySQL
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
22 |
#include "config.h" |
214
by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing). |
23 |
#include <drizzled/field/long.h> |
550
by Monty Taylor
Moved error.h into just the files that need it. |
24 |
#include <drizzled/error.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
25 |
#include <drizzled/table.h> |
26 |
#include <drizzled/session.h> |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
27 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
28 |
#include <math.h> |
29 |
||
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
30 |
#include <algorithm> |
31 |
||
32 |
using namespace std; |
|
33 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
34 |
namespace drizzled |
35 |
{
|
|
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
36 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
37 |
/****************************************************************************
|
38 |
** long int
|
|
39 |
****************************************************************************/
|
|
40 |
||
482
by Brian Aker
Remove uint. |
41 |
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
42 |
{
|
43 |
long store_tmp; |
|
44 |
int error; |
|
45 |
int64_t rnd; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
46 |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
47 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
48 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
49 |
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX); |
509
by Brian Aker
Incremental patch for removing unsigned. |
50 |
store_tmp= (long) rnd; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
51 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
52 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
53 |
{
|
54 |
int4store(ptr, store_tmp); |
|
55 |
}
|
|
56 |
else
|
|
57 |
#endif
|
|
58 |
longstore(ptr, store_tmp); |
|
59 |
return error; |
|
60 |
}
|
|
61 |
||
62 |
||
63 |
int Field_long::store(double nr) |
|
64 |
{
|
|
65 |
int error= 0; |
|
205
by Brian Aker
uint32 -> uin32_t |
66 |
int32_t res; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
67 |
nr=rint(nr); |
509
by Brian Aker
Incremental patch for removing unsigned. |
68 |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
69 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
70 |
||
509
by Brian Aker
Incremental patch for removing unsigned. |
71 |
if (nr < (double) INT32_MIN) |
72 |
{
|
|
73 |
res=(int32_t) INT32_MIN; |
|
74 |
error= 1; |
|
75 |
}
|
|
76 |
else if (nr > (double) INT32_MAX) |
|
77 |
{
|
|
78 |
res=(int32_t) INT32_MAX; |
|
79 |
error= 1; |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
80 |
}
|
81 |
else
|
|
509
by Brian Aker
Incremental patch for removing unsigned. |
82 |
res=(int32_t) (int64_t) nr; |
83 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
84 |
if (error) |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
85 |
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
86 |
|
87 |
#ifdef WORDS_BIGENDIAN
|
|
1830.1.3
by Brian Aker
Fix for Solaris |
88 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
89 |
{
|
90 |
int4store(ptr,res); |
|
91 |
}
|
|
92 |
else
|
|
93 |
#endif
|
|
94 |
longstore(ptr,res); |
|
95 |
return error; |
|
96 |
}
|
|
97 |
||
98 |
||
99 |
int Field_long::store(int64_t nr, bool unsigned_val) |
|
100 |
{
|
|
101 |
int error= 0; |
|
205
by Brian Aker
uint32 -> uin32_t |
102 |
int32_t res; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
103 |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
104 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
105 |
||
509
by Brian Aker
Incremental patch for removing unsigned. |
106 |
if (nr < 0 && unsigned_val) |
107 |
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
108 |
if (nr < (int64_t) INT32_MIN) |
509
by Brian Aker
Incremental patch for removing unsigned. |
109 |
{
|
110 |
res=(int32_t) INT32_MIN; |
|
111 |
error= 1; |
|
112 |
}
|
|
113 |
else if (nr > (int64_t) INT32_MAX) |
|
114 |
{
|
|
115 |
res=(int32_t) INT32_MAX; |
|
116 |
error= 1; |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
117 |
}
|
118 |
else
|
|
509
by Brian Aker
Incremental patch for removing unsigned. |
119 |
res=(int32_t) nr; |
120 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
121 |
if (error) |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
122 |
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
123 |
|
124 |
#ifdef WORDS_BIGENDIAN
|
|
1830.1.3
by Brian Aker
Fix for Solaris |
125 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
126 |
{
|
127 |
int4store(ptr,res); |
|
128 |
}
|
|
129 |
else
|
|
130 |
#endif
|
|
131 |
longstore(ptr,res); |
|
132 |
return error; |
|
133 |
}
|
|
134 |
||
135 |
||
136 |
double Field_long::val_real(void) |
|
137 |
{
|
|
205
by Brian Aker
uint32 -> uin32_t |
138 |
int32_t j; |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
139 |
|
140 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
141 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
142 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
143 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
144 |
j=sint4korr(ptr); |
145 |
else
|
|
146 |
#endif
|
|
147 |
longget(j,ptr); |
|
509
by Brian Aker
Incremental patch for removing unsigned. |
148 |
return (double) j; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
149 |
}
|
150 |
||
151 |
int64_t Field_long::val_int(void) |
|
152 |
{
|
|
205
by Brian Aker
uint32 -> uin32_t |
153 |
int32_t j; |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
154 |
|
155 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
156 |
||
481.1.3
by Monty Taylor
Replaced long long with int64_t. |
157 |
/* See the comment in Field_long::store(int64_t) */
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
158 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
159 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
160 |
j=sint4korr(ptr); |
161 |
else
|
|
162 |
#endif
|
|
163 |
longget(j,ptr); |
|
509
by Brian Aker
Incremental patch for removing unsigned. |
164 |
return (int64_t) j; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
165 |
}
|
166 |
||
167 |
String *Field_long::val_str(String *val_buffer, |
|
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
168 |
String *) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
169 |
{
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
170 |
const CHARSET_INFO * const cs= &my_charset_bin; |
482
by Brian Aker
Remove uint. |
171 |
uint32_t length; |
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
172 |
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
173 |
val_buffer->alloc(mlength); |
174 |
char *to=(char*) val_buffer->ptr(); |
|
205
by Brian Aker
uint32 -> uin32_t |
175 |
int32_t j; |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
176 |
|
177 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
178 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
179 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
180 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
181 |
j=sint4korr(ptr); |
182 |
else
|
|
183 |
#endif
|
|
184 |
longget(j,ptr); |
|
185 |
||
509
by Brian Aker
Incremental patch for removing unsigned. |
186 |
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
187 |
val_buffer->length(length); |
216
by Brian Aker
Remove completely ZEROFILL |
188 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
189 |
return val_buffer; |
190 |
}
|
|
191 |
||
481
by Brian Aker
Remove all of uchar. |
192 |
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
193 |
{
|
205
by Brian Aker
uint32 -> uin32_t |
194 |
int32_t a,b; |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
195 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
196 |
if (getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
197 |
{
|
198 |
a=sint4korr(a_ptr); |
|
199 |
b=sint4korr(b_ptr); |
|
200 |
}
|
|
201 |
else
|
|
202 |
#endif
|
|
203 |
{
|
|
204 |
longget(a,a_ptr); |
|
205 |
longget(b,b_ptr); |
|
206 |
}
|
|
509
by Brian Aker
Incremental patch for removing unsigned. |
207 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
208 |
return (a < b) ? -1 : (a > b) ? 1 : 0; |
209 |
}
|
|
210 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
211 |
void Field_long::sort_string(unsigned char *to,uint32_t ) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
212 |
{
|
213 |
#ifdef WORDS_BIGENDIAN
|
|
1830.1.3
by Brian Aker
Fix for Solaris |
214 |
if (!getTable()->getShare()->db_low_byte_first) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
215 |
{
|
509
by Brian Aker
Incremental patch for removing unsigned. |
216 |
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */ |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
217 |
to[1] = ptr[1]; |
218 |
to[2] = ptr[2]; |
|
219 |
to[3] = ptr[3]; |
|
220 |
}
|
|
221 |
else
|
|
222 |
#endif
|
|
223 |
{
|
|
509
by Brian Aker
Incremental patch for removing unsigned. |
224 |
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */ |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
225 |
to[1] = ptr[2]; |
226 |
to[2] = ptr[1]; |
|
227 |
to[3] = ptr[0]; |
|
228 |
}
|
|
229 |
}
|
|
230 |
||
231 |
||
232 |
void Field_long::sql_type(String &res) const |
|
233 |
{
|
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
234 |
const CHARSET_INFO * const cs=res.charset(); |
221
by Brian Aker
First pass of removing length types for ints. |
235 |
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int")); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
236 |
}
|
237 |
||
590.3.1
by Lee Bieber
changes to get build working on Solaris |
238 |
unsigned char *Field_long::pack(unsigned char* to, const unsigned char *from, |
239 |
uint32_t, |
|
240 |
#ifdef WORDS_BIGENDIAN
|
|
241 |
bool low_byte_first |
|
242 |
#else
|
|
243 |
bool
|
|
244 |
#endif
|
|
245 |
)
|
|
246 |
{
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
247 |
int32_t val; |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
248 |
#ifdef WORDS_BIGENDIAN
|
1830.1.3
by Brian Aker
Fix for Solaris |
249 |
if (getTable()->getShare()->db_low_byte_first) |
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
250 |
val = sint4korr(from); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
251 |
else
|
252 |
#endif
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
253 |
longget(val, from); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
254 |
|
255 |
#ifdef WORDS_BIGENDIAN
|
|
256 |
if (low_byte_first) |
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
257 |
int4store(to, val); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
258 |
else
|
259 |
#endif
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
260 |
longstore(to, val); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
261 |
return to + sizeof(val); |
262 |
}
|
|
263 |
||
264 |
||
265 |
const unsigned char *Field_long::unpack(unsigned char* to, const unsigned char *from, uint32_t, |
|
266 |
#ifdef WORDS_BIGENDIAN
|
|
267 |
bool low_byte_first |
|
268 |
#else
|
|
269 |
bool
|
|
270 |
#endif
|
|
271 |
)
|
|
272 |
{
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
273 |
int32_t val; |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
274 |
#ifdef WORDS_BIGENDIAN
|
275 |
if (low_byte_first) |
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
276 |
val = sint4korr(from); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
277 |
else
|
278 |
#endif
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
279 |
longget(val, from); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
280 |
|
281 |
#ifdef WORDS_BIGENDIAN
|
|
1830.1.3
by Brian Aker
Fix for Solaris |
282 |
if (getTable()->getShare()->db_low_byte_first) |
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
283 |
int4store(to, val); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
284 |
else
|
285 |
#endif
|
|
629.3.3
by Kristian Nielsen
Fix bad patch that errorneously replaced Field_long::{un,}pack() with |
286 |
longstore(to, val); |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
287 |
return from + sizeof(val); |
288 |
}
|
|
289 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
290 |
} /* namespace drizzled */ |