466
by Monty Taylor
Fixed modelines... these files are c++. |
1 |
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
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" |
670.1.1
by Monty Taylor
Renamed fdecimal.* to decimal.*. Let's see how many things we can break! |
23 |
#include <drizzled/field/decimal.h> |
549
by Monty Taylor
Took gettext.h out of header files. |
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> |
|
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
27 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
28 |
namespace drizzled |
29 |
{
|
|
30 |
||
520.6.7
by Monty Taylor
Moved a bunch of crap out of common_includes. |
31 |
extern my_decimal decimal_zero; |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
32 |
|
33 |
/****************************************************************************
|
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
34 |
** File_decimal
|
35 |
****************************************************************************/
|
|
36 |
||
37 |
Field_decimal::Field_decimal(unsigned char *ptr_arg, |
|
38 |
uint32_t len_arg, |
|
39 |
unsigned char *null_ptr_arg, |
|
40 |
unsigned char null_bit_arg, |
|
41 |
enum utype unireg_check_arg, |
|
42 |
const char *field_name_arg, |
|
43 |
uint8_t dec_arg, |
|
44 |
bool zero_arg, |
|
45 |
bool unsigned_arg) |
|
46 |
:Field_num(ptr_arg, |
|
47 |
len_arg, |
|
48 |
null_ptr_arg, |
|
49 |
null_bit_arg, |
|
50 |
unireg_check_arg, |
|
51 |
field_name_arg, |
|
52 |
dec_arg, zero_arg, |
|
53 |
unsigned_arg) |
|
54 |
{
|
|
55 |
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg); |
|
56 |
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION); |
|
57 |
assert((precision <= DECIMAL_MAX_PRECISION) && |
|
58 |
(dec <= DECIMAL_MAX_SCALE)); |
|
59 |
bin_size= my_decimal_get_binary_size(precision, dec); |
|
60 |
}
|
|
61 |
||
62 |
Field_decimal::Field_decimal(uint32_t len_arg, |
|
63 |
bool maybe_null_arg, |
|
64 |
const char *name, |
|
65 |
uint8_t dec_arg, |
|
66 |
bool unsigned_arg) |
|
67 |
:Field_num((unsigned char*) 0, |
|
68 |
len_arg, |
|
69 |
maybe_null_arg ? (unsigned char*) "": 0, |
|
70 |
0, |
|
71 |
NONE, |
|
72 |
name, |
|
73 |
dec_arg, |
|
74 |
0, |
|
75 |
unsigned_arg) |
|
76 |
{
|
|
77 |
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg); |
|
78 |
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION); |
|
79 |
assert((precision <= DECIMAL_MAX_PRECISION) && |
|
80 |
(dec <= DECIMAL_MAX_SCALE)); |
|
81 |
bin_size= my_decimal_get_binary_size(precision, dec); |
|
82 |
}
|
|
83 |
||
84 |
||
85 |
int Field_decimal::reset(void) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
86 |
{
|
87 |
store_value(&decimal_zero); |
|
88 |
return 0; |
|
89 |
}
|
|
90 |
||
91 |
||
92 |
/**
|
|
93 |
Generate max/min decimal value in case of overflow.
|
|
94 |
||
95 |
@param decimal_value buffer for value
|
|
96 |
@param sign sign of value which caused overflow
|
|
97 |
*/
|
|
98 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
99 |
void Field_decimal::set_value_on_overflow(my_decimal *decimal_value, |
100 |
bool sign) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
101 |
{
|
102 |
max_my_decimal(decimal_value, precision, decimals()); |
|
103 |
if (sign) |
|
509
by Brian Aker
Incremental patch for removing unsigned. |
104 |
decimal_value->sign(true); |
105 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
106 |
return; |
107 |
}
|
|
108 |
||
109 |
||
110 |
/**
|
|
111 |
Store decimal value in the binary buffer.
|
|
112 |
||
113 |
Checks if decimal_value fits into field size.
|
|
114 |
If it does, stores the decimal in the buffer using binary format.
|
|
115 |
Otherwise sets maximal number that can be stored in the field.
|
|
116 |
||
117 |
@param decimal_value my_decimal
|
|
118 |
||
119 |
@retval
|
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
120 |
0 ok
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
121 |
@retval
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
122 |
1 error
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
123 |
*/
|
124 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
125 |
bool Field_decimal::store_value(const my_decimal *decimal_value) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
126 |
{
|
970.2.2
by Padraig O'Sullivan
Decided that we when we have an integer divided by an integer that returns a |
127 |
int error= 0; |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
128 |
|
970.2.2
by Padraig O'Sullivan
Decided that we when we have an integer divided by an integer that returns a |
129 |
if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, |
130 |
decimal_value, ptr, precision, dec))) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
131 |
{
|
132 |
my_decimal buff; |
|
970.2.2
by Padraig O'Sullivan
Decided that we when we have an integer divided by an integer that returns a |
133 |
set_value_on_overflow(&buff, decimal_value->sign()); |
134 |
my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
135 |
error= 1; |
136 |
}
|
|
137 |
return(error); |
|
138 |
}
|
|
139 |
||
140 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
141 |
int Field_decimal::store(const char *from, uint32_t length, |
142 |
const CHARSET_INFO * const charset_arg) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
143 |
{
|
144 |
int err; |
|
145 |
my_decimal decimal_value; |
|
146 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
147 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
148 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
149 |
if ((err= str2my_decimal(E_DEC_FATAL_ERROR & |
150 |
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM), |
|
151 |
from, length, charset_arg, |
|
152 |
&decimal_value)) && |
|
153 |
table->in_use->abort_on_warning) |
|
154 |
{
|
|
155 |
/* Because "from" is not NUL-terminated and we use %s in the ER() */
|
|
156 |
String from_as_str; |
|
157 |
from_as_str.copy(from, length, &my_charset_bin); |
|
158 |
||
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
159 |
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
160 |
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, |
161 |
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), |
|
162 |
"decimal", from_as_str.c_ptr(), field_name, |
|
290
by Brian Aker
Update for ulong change over. |
163 |
(uint32_t) table->in_use->row_count); |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
164 |
|
165 |
return(err); |
|
166 |
}
|
|
167 |
||
168 |
switch (err) { |
|
169 |
case E_DEC_TRUNCATED: |
|
970.2.3
by Padraig O'Sullivan
Fixed up 1 more test case based on the modifications I have made. |
170 |
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); |
171 |
set_value_on_overflow(&decimal_value, decimal_value.sign()); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
172 |
break; |
173 |
case E_DEC_OVERFLOW: |
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
174 |
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
175 |
set_value_on_overflow(&decimal_value, decimal_value.sign()); |
176 |
break; |
|
177 |
case E_DEC_BAD_NUM: |
|
178 |
{
|
|
179 |
/* Because "from" is not NUL-terminated and we use %s in the ER() */
|
|
180 |
String from_as_str; |
|
181 |
from_as_str.copy(from, length, &my_charset_bin); |
|
182 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
183 |
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN, |
184 |
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, |
|
185 |
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
186 |
"decimal", from_as_str.c_ptr(), field_name, |
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
187 |
(uint32_t) table->in_use->row_count); |
188 |
my_decimal_set_zero(&decimal_value); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
189 |
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
190 |
break; |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
191 |
}
|
192 |
}
|
|
193 |
||
194 |
store_value(&decimal_value); |
|
195 |
return(err); |
|
196 |
}
|
|
197 |
||
198 |
||
199 |
/**
|
|
200 |
@todo
|
|
201 |
Fix following when double2my_decimal when double2decimal
|
|
202 |
will return E_DEC_TRUNCATED always correctly
|
|
203 |
*/
|
|
204 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
205 |
int Field_decimal::store(double nr) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
206 |
{
|
207 |
my_decimal decimal_value; |
|
208 |
int err; |
|
209 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
210 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
211 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
212 |
err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr, |
213 |
&decimal_value); |
|
214 |
if (err) |
|
215 |
{
|
|
216 |
if (check_overflow(err)) |
|
217 |
set_value_on_overflow(&decimal_value, decimal_value.sign()); |
|
218 |
/* Only issue a warning if store_value doesn't issue an warning */
|
|
219 |
table->in_use->got_warning= 0; |
|
220 |
}
|
|
221 |
if (store_value(&decimal_value)) |
|
222 |
err= 1; |
|
223 |
else if (err && !table->in_use->got_warning) |
|
224 |
err= warn_if_overflow(err); |
|
225 |
return(err); |
|
226 |
}
|
|
227 |
||
228 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
229 |
int Field_decimal::store(int64_t nr, bool unsigned_val) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
230 |
{
|
231 |
my_decimal decimal_value; |
|
232 |
int err; |
|
233 |
||
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
234 |
ASSERT_COLUMN_MARKED_FOR_WRITE; |
235 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
236 |
if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, |
237 |
nr, unsigned_val, &decimal_value))) |
|
238 |
{
|
|
239 |
if (check_overflow(err)) |
|
240 |
set_value_on_overflow(&decimal_value, decimal_value.sign()); |
|
241 |
/* Only issue a warning if store_value doesn't issue an warning */
|
|
242 |
table->in_use->got_warning= 0; |
|
243 |
}
|
|
244 |
if (store_value(&decimal_value)) |
|
245 |
err= 1; |
|
246 |
else if (err && !table->in_use->got_warning) |
|
247 |
err= warn_if_overflow(err); |
|
248 |
return err; |
|
249 |
}
|
|
250 |
||
251 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
252 |
int Field_decimal::store_decimal(const my_decimal *decimal_value) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
253 |
{
|
254 |
return store_value(decimal_value); |
|
255 |
}
|
|
256 |
||
257 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
258 |
int Field_decimal::store_time(DRIZZLE_TIME *ltime, |
259 |
enum enum_drizzle_timestamp_type ) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
260 |
{
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
261 |
my_decimal decimal_value; |
262 |
return store_value(date2my_decimal(ltime, &decimal_value)); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
263 |
}
|
264 |
||
265 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
266 |
double Field_decimal::val_real(void) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
267 |
{
|
268 |
double dbl; |
|
269 |
my_decimal decimal_value; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
270 |
|
271 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
272 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
273 |
my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
274 |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
275 |
return dbl; |
276 |
}
|
|
277 |
||
278 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
279 |
int64_t Field_decimal::val_int(void) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
280 |
{
|
281 |
int64_t i; |
|
282 |
my_decimal decimal_value; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
283 |
|
284 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
285 |
||
509
by Brian Aker
Incremental patch for removing unsigned. |
286 |
my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), false, &i); |
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
287 |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
288 |
return i; |
289 |
}
|
|
290 |
||
291 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
292 |
my_decimal* Field_decimal::val_decimal(my_decimal *decimal_value) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
293 |
{
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
294 |
ASSERT_COLUMN_MARKED_FOR_READ; |
295 |
||
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
296 |
binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value, |
297 |
precision, dec); |
|
298 |
return(decimal_value); |
|
299 |
}
|
|
300 |
||
301 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
302 |
String *Field_decimal::val_str(String *val_buffer, |
303 |
String *) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
304 |
{
|
305 |
my_decimal decimal_value; |
|
1089.1.3
by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix |
306 |
|
307 |
ASSERT_COLUMN_MARKED_FOR_READ; |
|
308 |
||
482
by Brian Aker
Remove uint. |
309 |
uint32_t fixed_precision= decimal_precision ? precision : 0; |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
310 |
my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), |
311 |
fixed_precision, dec, '0', val_buffer); |
|
312 |
return val_buffer; |
|
313 |
}
|
|
314 |
||
315 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
316 |
int Field_decimal::cmp(const unsigned char *a,const unsigned char*b) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
317 |
{
|
318 |
return memcmp(a, b, bin_size); |
|
319 |
}
|
|
320 |
||
321 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
322 |
void Field_decimal::sort_string(unsigned char *buff, |
323 |
uint32_t ) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
324 |
{
|
325 |
memcpy(buff, ptr, bin_size); |
|
326 |
}
|
|
327 |
||
328 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
329 |
void Field_decimal::sql_type(String &str) const |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
330 |
{
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
331 |
const CHARSET_INFO * const cs= str.charset(); |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
332 |
str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(), |
333 |
"decimal(%d,%d)", precision, (int)dec)); |
|
334 |
}
|
|
335 |
||
336 |
||
337 |
/**
|
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
338 |
Returns the number of bytes field uses in row-based replication
|
339 |
row packed size.
|
|
340 |
||
341 |
This method is used in row-based replication to determine the number
|
|
342 |
of bytes that the field consumes in the row record format. This is
|
|
343 |
used to skip fields in the master that do not exist on the slave.
|
|
344 |
||
345 |
@param field_metadata Encoded size in field metadata
|
|
346 |
||
347 |
@returns The size of the field based on the field metadata.
|
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
348 |
*/
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
349 |
uint32_t Field_decimal::pack_length_from_metadata(uint32_t field_metadata) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
350 |
{
|
482
by Brian Aker
Remove uint. |
351 |
uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
352 |
uint32_t const source_decimal= field_metadata & 0x00ff; |
353 |
uint32_t const source_size= my_decimal_get_binary_size(source_precision, |
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
354 |
source_decimal); |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
355 |
return (source_size); |
356 |
}
|
|
357 |
||
358 |
||
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
359 |
uint32_t Field_decimal::is_equal(CreateField *new_field_ptr) |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
360 |
{
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
361 |
return ((new_field_ptr->sql_type == real_type()) && |
362 |
((new_field_ptr->flags & UNSIGNED_FLAG) == |
|
363 |
(uint32_t) (flags & UNSIGNED_FLAG)) && |
|
364 |
((new_field_ptr->flags & AUTO_INCREMENT_FLAG) == |
|
365 |
(uint32_t) (flags & AUTO_INCREMENT_FLAG)) && |
|
366 |
(new_field_ptr->length == max_display_length()) && |
|
367 |
(new_field_ptr->decimals == dec)); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
368 |
}
|
369 |
||
370 |
||
371 |
/**
|
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
372 |
Unpack a decimal field from row data.
|
373 |
||
374 |
This method is used to unpack a decimal or numeric field from a master
|
|
375 |
whose size of the field is less than that of the slave.
|
|
376 |
||
377 |
@param to Destination of the data
|
|
378 |
@param from Source of the data
|
|
379 |
@param param_data Precision (upper) and decimal (lower) values
|
|
380 |
||
381 |
@return New pointer into memory based on from + length of the data
|
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
382 |
*/
|
481
by Brian Aker
Remove all of uchar. |
383 |
const unsigned char * |
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
384 |
Field_decimal::unpack(unsigned char* to, |
385 |
const unsigned char *from, |
|
386 |
uint32_t param_data, |
|
387 |
bool low_byte_first) |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
388 |
{
|
389 |
if (param_data == 0) |
|
390 |
return Field::unpack(to, from, param_data, low_byte_first); |
|
391 |
||
482
by Brian Aker
Remove uint. |
392 |
uint32_t from_precision= (param_data & 0xff00) >> 8U; |
393 |
uint32_t from_decimal= param_data & 0x00ff; |
|
394 |
uint32_t length=pack_length(); |
|
395 |
uint32_t from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal); |
|
396 |
uint32_t len= (param_data && (from_pack_len < length)) ? |
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
397 |
from_pack_len : length; |
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
398 |
if ((from_pack_len && (from_pack_len < length)) || |
399 |
(from_precision < precision) || |
|
400 |
(from_decimal < decimals())) |
|
401 |
{
|
|
402 |
/*
|
|
403 |
If the master's data is smaller than the slave, we need to convert
|
|
404 |
the binary to decimal then resize the decimal converting it back to
|
|
405 |
a decimal and write that to the raw data buffer.
|
|
406 |
*/
|
|
407 |
decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION]; |
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
408 |
decimal_t conv_dec; |
409 |
conv_dec.len= from_precision; |
|
410 |
conv_dec.buf= dec_buf; |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
411 |
/*
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
412 |
Note: bin2decimal does not change the length of the field. So it is
|
413 |
just the first step the resizing operation. The second step does the
|
|
414 |
resizing using the precision and decimals from the slave.
|
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
415 |
*/
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
416 |
bin2decimal((unsigned char *)from, &conv_dec, from_precision, from_decimal); |
417 |
decimal2bin(&conv_dec, to, precision, decimals()); |
|
173.1.8
by Toru Maesaka
ripped out STRING and renamed new_decimal and new_date |
418 |
}
|
419 |
else
|
|
420 |
memcpy(to, from, len); // Sizes are the same, just copy the data. |
|
421 |
return from+len; |
|
422 |
}
|
|
423 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
424 |
} /* namespace drizzled */ |