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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <config.h> |
2007
by Brian Aker
Refactor naming for integers. |
23 |
#include <drizzled/field/int64.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> |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
27 |
#include <drizzled/internal/my_sys.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. |
28 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
29 |
#include <math.h> |
30 |
||
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
31 |
#include <algorithm> |
32 |
||
33 |
using namespace std; |
|
34 |
||
2318.6.16
by Olaf van der Spek
Remove unused Field::sql_type() |
35 |
namespace drizzled { |
36 |
namespace field { |
|
2007
by Brian Aker
Refactor naming for integers. |
37 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
38 |
/****************************************************************************
|
2007
by Brian Aker
Refactor naming for integers. |
39 |
Field type Int64 int (8 bytes)
|
40 |
****************************************************************************/
|
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
41 |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
42 |
int Int64::store(const char *from,uint32_t len, const charset_info_st * const cs) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
43 |
{
|
44 |
int error= 0; |
|
45 |
char *end; |
|
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 |
||
2318.6.16
by Olaf van der Spek
Remove unused Field::sql_type() |
49 |
uint64_t tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error); |
2241.4.22
by Stewart Smith
remove MY_ERRNO_EDOM and MY_ERRNO_ERANGE. Instead, we should consistently use the system EDOM and ERANGE. If on any platform, they weren't 33 and 34 respectively, we would have had bugs. |
50 |
if (error == ERANGE) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
51 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
52 |
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/ |
53 |
error= 1; |
54 |
}
|
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
55 |
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error)) |
56 |
{
|
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
57 |
error= 1; |
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
58 |
}
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
59 |
else
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
60 |
{
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
61 |
error= 0; |
62 |
}
|
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
63 |
|
64 |
int64_tstore(ptr,tmp); |
|
65 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
66 |
return error; |
67 |
}
|
|
68 |
||
69 |
||
2007
by Brian Aker
Refactor naming for integers. |
70 |
int Int64::store(double nr) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
71 |
{
|
72 |
int error= 0; |
|
73 |
int64_t res; |
|
74 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
75 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
76 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
77 |
nr= rint(nr); |
509
by Brian Aker
Incremental patch for removing unsigned. |
78 |
|
79 |
if (nr <= (double) INT64_MIN) |
|
80 |
{
|
|
81 |
res= INT64_MIN; |
|
82 |
error= (nr < (double) INT64_MIN); |
|
83 |
}
|
|
84 |
else if (nr >= (double) (uint64_t) INT64_MAX) |
|
85 |
{
|
|
86 |
res= INT64_MAX; |
|
87 |
error= (nr > (double) INT64_MAX); |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
88 |
}
|
89 |
else
|
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
90 |
{
|
509
by Brian Aker
Incremental patch for removing unsigned. |
91 |
res=(int64_t) nr; |
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
92 |
}
|
509
by Brian Aker
Incremental patch for removing unsigned. |
93 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
94 |
if (error) |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
95 |
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/ |
96 |
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
97 |
int64_tstore(ptr, res); |
98 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
99 |
return error; |
100 |
}
|
|
101 |
||
102 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
103 |
int Int64::store(int64_t nr, bool arg) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
104 |
{
|
105 |
int error= 0; |
|
106 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
107 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
2318.6.16
by Olaf van der Spek
Remove unused Field::sql_type() |
108 |
if (arg && nr < 0) // Only a partial fix for overflow |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
109 |
{
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
110 |
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); |
111 |
error= 1; |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
112 |
}
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
113 |
|
114 |
int64_tstore(ptr,nr); |
|
115 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
116 |
return error; |
117 |
}
|
|
118 |
||
119 |
||
2318.6.16
by Olaf van der Spek
Remove unused Field::sql_type() |
120 |
double Int64::val_real() const |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
121 |
{
|
122 |
int64_t j; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
123 |
|
124 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
125 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
126 |
int64_tget(j,ptr); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
127 |
/* The following is open coded to avoid a bug in gcc 3.3 */
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
128 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
129 |
return (double) j; |
130 |
}
|
|
131 |
||
132 |
||
2318.6.16
by Olaf van der Spek
Remove unused Field::sql_type() |
133 |
int64_t Int64::val_int() const |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
134 |
{
|
135 |
int64_t j; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
136 |
|
137 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
138 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
139 |
int64_tget(j,ptr); |
140 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
141 |
return j; |
142 |
}
|
|
143 |
||
144 |
||
2181.2.1
by Brian Aker
Protect all of the val_* methods from modification. |
145 |
String *Int64::val_str(String *val_buffer, String *) const |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
146 |
{
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
147 |
const charset_info_st * const cs= &my_charset_bin; |
482
by Brian Aker
Remove uint. |
148 |
uint32_t length; |
1067.4.6
by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max. |
149 |
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
150 |
val_buffer->alloc(mlength); |
151 |
char *to=(char*) val_buffer->ptr(); |
|
152 |
int64_t j; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
153 |
|
154 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
155 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
156 |
int64_tget(j,ptr); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
157 |
|
895
by Brian Aker
Completion (?) of uint conversion. |
158 |
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j); |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
159 |
val_buffer->length(length); |
216
by Brian Aker
Remove completely ZEROFILL |
160 |
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
161 |
return val_buffer; |
162 |
}
|
|
163 |
||
2007
by Brian Aker
Refactor naming for integers. |
164 |
int Int64::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/ |
165 |
{
|
166 |
int64_t a,b; |
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
167 |
|
168 |
int64_tget(a,a_ptr); |
|
169 |
int64_tget(b,b_ptr); |
|
170 |
||
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
171 |
return (a < b) ? -1 : (a > b) ? 1 : 0; |
172 |
}
|
|
173 |
||
2007
by Brian Aker
Refactor naming for integers. |
174 |
void Int64::sort_string(unsigned char *to,uint32_t ) |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
175 |
{
|
176 |
#ifdef WORDS_BIGENDIAN
|
|
177 |
{
|
|
509
by Brian Aker
Incremental patch for removing unsigned. |
178 |
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */ |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
179 |
to[1] = ptr[1]; |
180 |
to[2] = ptr[2]; |
|
181 |
to[3] = ptr[3]; |
|
182 |
to[4] = ptr[4]; |
|
183 |
to[5] = ptr[5]; |
|
184 |
to[6] = ptr[6]; |
|
185 |
to[7] = ptr[7]; |
|
186 |
}
|
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
187 |
#else
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
188 |
{
|
509
by Brian Aker
Incremental patch for removing unsigned. |
189 |
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */ |
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
190 |
to[1] = ptr[6]; |
191 |
to[2] = ptr[5]; |
|
192 |
to[3] = ptr[4]; |
|
193 |
to[4] = ptr[3]; |
|
194 |
to[5] = ptr[2]; |
|
195 |
to[6] = ptr[1]; |
|
196 |
to[7] = ptr[0]; |
|
197 |
}
|
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
198 |
#endif
|
173.1.12
by Toru Maesaka
Moved out SHORT, LONG and INT64_T to field/ |
199 |
}
|
200 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
201 |
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool) |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
202 |
{
|
203 |
int64_t val; |
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
204 |
|
205 |
int64_tget(val, from); |
|
206 |
int64_tstore(to, val); |
|
207 |
||
590.3.1
by Lee Bieber
changes to get build working on Solaris |
208 |
return to + sizeof(val); |
209 |
}
|
|
210 |
||
211 |
||
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
212 |
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool) |
590.3.1
by Lee Bieber
changes to get build working on Solaris |
213 |
{
|
214 |
int64_t val; |
|
2008.2.2
by Brian Aker
Remove MyISAM byte bit flip. |
215 |
|
216 |
int64_tget(val, from); |
|
217 |
int64_tstore(to, val); |
|
218 |
||
590.3.1
by Lee Bieber
changes to get build working on Solaris |
219 |
return from + sizeof(val); |
220 |
}
|
|
221 |
||
2007
by Brian Aker
Refactor naming for integers. |
222 |
} /* namespace field */ |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
223 |
} /* namespace drizzled */ |