Merge lp:~dedzone/drizzle/ded-decimal into lp:~drizzle-trunk/drizzle/development
- ded-decimal
- Merge into development
Proposed by
Djellel E. Difallah
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~dedzone/drizzle/ded-decimal |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Diff against target: |
1360 lines (+579/-647) 11 files modified
drizzled/cached_item.h (+1/-1) drizzled/decimal.cc (+223/-0) drizzled/decimal.h (+351/-1) drizzled/field.h (+1/-1) drizzled/hybrid_type.h (+1/-1) drizzled/include.am (+0/-2) drizzled/item.h (+1/-1) drizzled/my_decimal.cc (+0/-243) drizzled/my_decimal.h (+0/-395) drizzled/temporal.cc (+1/-1) support-files/drizzle.spec.in (+0/-1) |
To merge this branch: | bzr merge lp:~dedzone/drizzle/ded-decimal |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Monty Taylor | Approve | ||
Review via email: mp+22314@code.launchpad.net |
This proposal supersedes a proposal from 2010-03-27.
Commit message
Description of the change
Have just merged decimal and my_decimal, and updated the references then tested it.
To post a comment you must log in.
Revision history for this message
Monty Taylor (mordred) wrote : Posted in a previous version of this proposal | # |
review:
Needs Fixing
Revision history for this message
Monty Taylor (mordred) wrote : | # |
Awesome. Looks great!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'drizzled/cached_item.h' |
2 | --- drizzled/cached_item.h 2010-02-04 08:14:46 +0000 |
3 | +++ drizzled/cached_item.h 2010-03-28 01:34:23 +0000 |
4 | @@ -22,7 +22,7 @@ |
5 | |
6 | #include "drizzled/memory/sql_alloc.h" |
7 | #include "drizzled/sql_string.h" |
8 | -#include "drizzled/my_decimal.h" |
9 | +#include "drizzled/decimal.h" |
10 | |
11 | namespace drizzled |
12 | { |
13 | |
14 | === modified file 'drizzled/decimal.cc' |
15 | --- drizzled/decimal.cc 2010-02-04 08:14:46 +0000 |
16 | +++ drizzled/decimal.cc 2010-03-28 01:34:23 +0000 |
17 | @@ -112,11 +112,233 @@ |
18 | #endif |
19 | |
20 | #include <algorithm> |
21 | +#include <time.h> |
22 | +#include "drizzled/current_session.h" |
23 | +#include "drizzled/error.h" |
24 | +#include "drizzled/field.h" |
25 | +#include "drizzled/internal/my_sys.h" |
26 | |
27 | using namespace std; |
28 | |
29 | namespace drizzled |
30 | { |
31 | +/** |
32 | + report result of decimal operation. |
33 | + |
34 | + @param result decimal library return code (E_DEC_* see include/decimal.h) |
35 | + |
36 | + @todo |
37 | + Fix error messages |
38 | + |
39 | + @return |
40 | + result |
41 | +*/ |
42 | + |
43 | +int decimal_operation_results(int result) |
44 | +{ |
45 | + switch (result) { |
46 | + case E_DEC_OK: |
47 | + break; |
48 | + case E_DEC_TRUNCATED: |
49 | + push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN, |
50 | + ER_WARN_DATA_TRUNCATED, ER(ER_WARN_DATA_TRUNCATED), |
51 | + "", (long)-1); |
52 | + break; |
53 | + case E_DEC_OVERFLOW: |
54 | + push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
55 | + ER_TRUNCATED_WRONG_VALUE, |
56 | + ER(ER_TRUNCATED_WRONG_VALUE), |
57 | + "DECIMAL", ""); |
58 | + break; |
59 | + case E_DEC_DIV_ZERO: |
60 | + push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
61 | + ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO)); |
62 | + break; |
63 | + case E_DEC_BAD_NUM: |
64 | + push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
65 | + ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, |
66 | + ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), |
67 | + "decimal", "", "", (long)-1); |
68 | + break; |
69 | + case E_DEC_OOM: |
70 | + my_error(ER_OUT_OF_RESOURCES, MYF(0)); |
71 | + break; |
72 | + default: |
73 | + assert(0); |
74 | + } |
75 | + return result; |
76 | +} |
77 | + |
78 | + |
79 | +/** |
80 | + @brief Converting decimal to string |
81 | + |
82 | + @details Convert given my_decimal to String; allocate buffer as needed. |
83 | + |
84 | + @param[in] mask what problems to warn on (mask of E_DEC_* values) |
85 | + @param[in] d the decimal to print |
86 | + @param[in] fixed_prec overall number of digits if ZEROFILL, 0 otherwise |
87 | + @param[in] fixed_dec number of decimal places (if fixed_prec != 0) |
88 | + @param[in] filler what char to pad with (ZEROFILL et al.) |
89 | + @param[out] *str where to store the resulting string |
90 | + |
91 | + @return error coce |
92 | + @retval E_DEC_OK |
93 | + @retval E_DEC_TRUNCATED |
94 | + @retval E_DEC_OVERFLOW |
95 | + @retval E_DEC_OOM |
96 | +*/ |
97 | + |
98 | +int my_decimal2string(uint32_t mask, const my_decimal *d, |
99 | + uint32_t fixed_prec, uint32_t fixed_dec, |
100 | + char filler, String *str) |
101 | +{ |
102 | + /* |
103 | + Calculate the size of the string: For DECIMAL(a,b), fixed_prec==a |
104 | + holds true iff the type is also ZEROFILL, which in turn implies |
105 | + UNSIGNED. Hence the buffer for a ZEROFILLed value is the length |
106 | + the user requested, plus one for a possible decimal point, plus |
107 | + one if the user only wanted decimal places, but we force a leading |
108 | + zero on them. Because the type is implicitly UNSIGNED, we do not |
109 | + need to reserve a character for the sign. For all other cases, |
110 | + fixed_prec will be 0, and my_decimal_string_length() will be called |
111 | + instead to calculate the required size of the buffer. |
112 | + */ |
113 | + int length= (fixed_prec |
114 | + ? (fixed_prec + ((fixed_prec == fixed_dec) ? 1 : 0) + 1) |
115 | + : my_decimal_string_length(d)); |
116 | + int result; |
117 | + if (str->alloc(length)) |
118 | + return check_result(mask, E_DEC_OOM); |
119 | + result= decimal2string((decimal_t*) d, (char*) str->ptr(), |
120 | + &length, (int)fixed_prec, fixed_dec, |
121 | + filler); |
122 | + str->length(length); |
123 | + return check_result(mask, result); |
124 | +} |
125 | + |
126 | + |
127 | +/* |
128 | + Convert from decimal to binary representation |
129 | + |
130 | + SYNOPSIS |
131 | + my_decimal2binary() |
132 | + mask error processing mask |
133 | + d number for conversion |
134 | + bin pointer to buffer where to write result |
135 | + prec overall number of decimal digits |
136 | + scale number of decimal digits after decimal point |
137 | + |
138 | + NOTE |
139 | + Before conversion we round number if it need but produce truncation |
140 | + error in this case |
141 | + |
142 | + RETURN |
143 | + E_DEC_OK |
144 | + E_DEC_TRUNCATED |
145 | + E_DEC_OVERFLOW |
146 | +*/ |
147 | + |
148 | +int my_decimal2binary(uint32_t mask, const my_decimal *d, unsigned char *bin, int prec, |
149 | + int scale) |
150 | +{ |
151 | + int err1= E_DEC_OK, err2; |
152 | + my_decimal rounded; |
153 | + my_decimal2decimal(d, &rounded); |
154 | + rounded.frac= decimal_actual_fraction(&rounded); |
155 | + if (scale < rounded.frac) |
156 | + { |
157 | + err1= E_DEC_TRUNCATED; |
158 | + /* decimal_round can return only E_DEC_TRUNCATED */ |
159 | + decimal_round(&rounded, &rounded, scale, HALF_UP); |
160 | + } |
161 | + err2= decimal2bin(&rounded, bin, prec, scale); |
162 | + if (!err2) |
163 | + err2= err1; |
164 | + return check_result(mask, err2); |
165 | +} |
166 | + |
167 | + |
168 | +/* |
169 | + Convert string for decimal when string can be in some multibyte charset |
170 | + |
171 | + SYNOPSIS |
172 | + str2my_decimal() |
173 | + mask error processing mask |
174 | + from string to process |
175 | + length length of given string |
176 | + charset charset of given string |
177 | + decimal_value buffer for result storing |
178 | + |
179 | + RESULT |
180 | + E_DEC_OK |
181 | + E_DEC_TRUNCATED |
182 | + E_DEC_OVERFLOW |
183 | + E_DEC_BAD_NUM |
184 | + E_DEC_OOM |
185 | +*/ |
186 | + |
187 | +int str2my_decimal(uint32_t mask, const char *from, uint32_t length, |
188 | + const CHARSET_INFO * charset, my_decimal *decimal_value) |
189 | +{ |
190 | + char *end, *from_end; |
191 | + int err; |
192 | + char buff[STRING_BUFFER_USUAL_SIZE]; |
193 | + String tmp(buff, sizeof(buff), &my_charset_bin); |
194 | + if (charset->mbminlen > 1) |
195 | + { |
196 | + uint32_t dummy_errors; |
197 | + tmp.copy(from, length, charset, &my_charset_utf8_general_ci, &dummy_errors); |
198 | + from= tmp.ptr(); |
199 | + length= tmp.length(); |
200 | + charset= &my_charset_bin; |
201 | + } |
202 | + from_end= end= (char*) from+length; |
203 | + err= string2decimal((char *)from, (decimal_t*) decimal_value, &end); |
204 | + if (end != from_end && !err) |
205 | + { |
206 | + /* Give warning if there is something other than end space */ |
207 | + for ( ; end < from_end; end++) |
208 | + { |
209 | + if (!my_isspace(&my_charset_utf8_general_ci, *end)) |
210 | + { |
211 | + err= E_DEC_TRUNCATED; |
212 | + break; |
213 | + } |
214 | + } |
215 | + } |
216 | + check_result_and_overflow(mask, err, decimal_value); |
217 | + return err; |
218 | +} |
219 | + |
220 | + |
221 | +my_decimal *date2my_decimal(DRIZZLE_TIME *ltime, my_decimal *dec) |
222 | +{ |
223 | + int64_t date; |
224 | + date = (ltime->year*100L + ltime->month)*100L + ltime->day; |
225 | + if (ltime->time_type > DRIZZLE_TIMESTAMP_DATE) |
226 | + date= ((date*100L + ltime->hour)*100L+ ltime->minute)*100L + ltime->second; |
227 | + if (int2my_decimal(E_DEC_FATAL_ERROR, date, false, dec)) |
228 | + return dec; |
229 | + if (ltime->second_part) |
230 | + { |
231 | + dec->buf[(dec->intg-1) / 9 + 1]= ltime->second_part * 1000; |
232 | + dec->frac= 6; |
233 | + } |
234 | + return dec; |
235 | +} |
236 | + |
237 | + |
238 | +void my_decimal_trim(uint32_t *precision, uint32_t *scale) |
239 | +{ |
240 | + if (!(*precision) && !(*scale)) |
241 | + { |
242 | + *precision= 10; |
243 | + *scale= 0; |
244 | + return; |
245 | + } |
246 | +} |
247 | + |
248 | |
249 | /* |
250 | Internally decimal numbers are stored base 10^9 (see DIG_BASE below) |
251 | @@ -236,6 +458,7 @@ |
252 | } while (0) |
253 | |
254 | |
255 | + |
256 | /* |
257 | Get maximum value for given precision and scale |
258 | |
259 | |
260 | === modified file 'drizzled/decimal.h' |
261 | --- drizzled/decimal.h 2010-03-01 01:20:07 +0000 |
262 | +++ drizzled/decimal.h 2010-03-28 01:34:23 +0000 |
263 | @@ -15,7 +15,10 @@ |
264 | |
265 | #ifndef DRIZZLED_DECIMAL_H |
266 | #define DRIZZLED_DECIMAL_H |
267 | - |
268 | +#include <assert.h> |
269 | +#include <drizzled/sql_string.h> |
270 | +#include "drizzled/definitions.h" |
271 | +#include "drizzled/my_time.h" |
272 | namespace drizzled |
273 | { |
274 | |
275 | @@ -101,6 +104,353 @@ |
276 | |
277 | #define E_DEC_ERROR 31 |
278 | #define E_DEC_FATAL_ERROR 30 |
279 | +#define DECIMAL_LONGLONG_DIGITS 22 |
280 | +#define DECIMAL_LONG_DIGITS 10 |
281 | +#define DECIMAL_LONG3_DIGITS 8 |
282 | + |
283 | +/** maximum length of buffer in our big digits (uint32_t). */ |
284 | +#define DECIMAL_BUFF_LENGTH 9 |
285 | + |
286 | +/* the number of digits that my_decimal can possibly contain */ |
287 | +#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9) |
288 | + |
289 | + |
290 | +/** |
291 | + maximum guaranteed precision of number in decimal digits (number of our |
292 | + digits * number of decimal digits in one our big digit - number of decimal |
293 | + digits in one our big digit decreased by 1 (because we always put decimal |
294 | + point on the border of our big digits)) |
295 | +*/ |
296 | +#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2) |
297 | +#define DECIMAL_MAX_SCALE 30 |
298 | +#define DECIMAL_NOT_SPECIFIED 31 |
299 | + |
300 | +/** |
301 | + maximum length of string representation (number of maximum decimal |
302 | + digits + 1 position for sign + 1 position for decimal point) |
303 | +*/ |
304 | +#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2) |
305 | + |
306 | +/** |
307 | + maximum size of packet length. |
308 | +*/ |
309 | +#define DECIMAL_MAX_FIELD_SIZE DECIMAL_MAX_PRECISION |
310 | + |
311 | +inline int my_decimal_int_part(uint32_t precision, uint32_t decimals) |
312 | +{ |
313 | + return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals); |
314 | +} |
315 | + |
316 | + |
317 | +/** |
318 | + my_decimal class limits 'decimal_t' type to what we need in MySQL. |
319 | + |
320 | + It contains internally all necessary space needed by the instance so |
321 | + no extra memory is needed. One should call fix_buffer_pointer() function |
322 | + when he moves my_decimal objects in memory. |
323 | +*/ |
324 | + |
325 | +class my_decimal :public decimal_t |
326 | +{ |
327 | + decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; |
328 | + |
329 | +public: |
330 | + |
331 | + void init() |
332 | + { |
333 | + len= DECIMAL_BUFF_LENGTH; |
334 | + buf= buffer; |
335 | + #if !defined (HAVE_purify) |
336 | + /* Set buffer to 'random' value to find wrong buffer usage */ |
337 | + for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++) |
338 | + buffer[i]= i; |
339 | + #endif |
340 | + } |
341 | + my_decimal() |
342 | + { |
343 | + init(); |
344 | + } |
345 | + void fix_buffer_pointer() { buf= buffer; } |
346 | + bool sign() const { return decimal_t::sign; } |
347 | + void sign(bool s) { decimal_t::sign= s; } |
348 | + uint32_t precision() const { return intg + frac; } |
349 | +}; |
350 | + |
351 | +int decimal_operation_results(int result); |
352 | + |
353 | +inline void max_my_decimal(my_decimal *to, int precision, int frac) |
354 | +{ |
355 | + assert((precision <= DECIMAL_MAX_PRECISION)&& |
356 | + (frac <= DECIMAL_MAX_SCALE)); |
357 | + max_decimal(precision, frac, (decimal_t*) to); |
358 | +} |
359 | + |
360 | +inline void max_internal_decimal(my_decimal *to) |
361 | +{ |
362 | + max_my_decimal(to, DECIMAL_MAX_PRECISION, 0); |
363 | +} |
364 | + |
365 | +inline int check_result(uint32_t mask, int result) |
366 | +{ |
367 | + if (result & mask) |
368 | + decimal_operation_results(result); |
369 | + return result; |
370 | +} |
371 | + |
372 | +inline int check_result_and_overflow(uint32_t mask, int result, my_decimal *val) |
373 | +{ |
374 | + if (check_result(mask, result) & E_DEC_OVERFLOW) |
375 | + { |
376 | + bool sign= val->sign(); |
377 | + val->fix_buffer_pointer(); |
378 | + max_internal_decimal(val); |
379 | + val->sign(sign); |
380 | + } |
381 | + return result; |
382 | +} |
383 | + |
384 | +inline uint32_t my_decimal_length_to_precision(uint32_t length, uint32_t scale, |
385 | + bool unsigned_flag) |
386 | +{ |
387 | + return (uint32_t) (length - (scale>0 ? 1:0) - (unsigned_flag ? 0:1)); |
388 | +} |
389 | + |
390 | +inline uint32_t my_decimal_precision_to_length(uint32_t precision, uint8_t scale, |
391 | + bool unsigned_flag) |
392 | +{ |
393 | + set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION); |
394 | + return static_cast<uint32_t>(precision + (scale>0 ? 1:0) + (unsigned_flag ? 0:1)); |
395 | +} |
396 | + |
397 | +inline |
398 | +int my_decimal_string_length(const my_decimal *d) |
399 | +{ |
400 | + return decimal_string_size(d); |
401 | +} |
402 | + |
403 | + |
404 | +inline |
405 | +int my_decimal_max_length(const my_decimal *d) |
406 | +{ |
407 | + /* -1 because we do not count \0 */ |
408 | + return decimal_string_size(d) - 1; |
409 | +} |
410 | + |
411 | + |
412 | +inline |
413 | +int my_decimal_get_binary_size(uint32_t precision, uint32_t scale) |
414 | +{ |
415 | + return decimal_bin_size(static_cast<int>(precision), static_cast<int>(scale)); |
416 | +} |
417 | + |
418 | + |
419 | +inline |
420 | +void my_decimal2decimal(const my_decimal *from, my_decimal *to) |
421 | +{ |
422 | + *to= *from; |
423 | + to->fix_buffer_pointer(); |
424 | +} |
425 | + |
426 | + |
427 | +int my_decimal2binary(uint32_t mask, const my_decimal *d, unsigned char *bin, int prec, |
428 | + int scale); |
429 | + |
430 | + |
431 | +inline |
432 | +int binary2my_decimal(uint32_t mask, const unsigned char *bin, my_decimal *d, int prec, |
433 | + int scale) |
434 | +{ |
435 | + return check_result(mask, bin2decimal(bin, static_cast<decimal_t*>(d), prec, scale)); |
436 | +} |
437 | + |
438 | + |
439 | +inline |
440 | +int my_decimal_set_zero(my_decimal *d) |
441 | +{ |
442 | + decimal_make_zero(static_cast<decimal_t*> (d)); |
443 | + return 0; |
444 | +} |
445 | + |
446 | + |
447 | +inline |
448 | +bool my_decimal_is_zero(const my_decimal *decimal_value) |
449 | +{ |
450 | + return decimal_is_zero(static_cast<const decimal_t*>(decimal_value)); |
451 | +} |
452 | + |
453 | + |
454 | +inline |
455 | +int my_decimal_round(uint32_t mask, const my_decimal *from, int scale, |
456 | + bool truncate, my_decimal *to) |
457 | +{ |
458 | + return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, scale, |
459 | + (truncate ? TRUNCATE : HALF_UP))); |
460 | +} |
461 | + |
462 | + |
463 | +inline |
464 | +int my_decimal_floor(uint32_t mask, const my_decimal *from, my_decimal *to) |
465 | +{ |
466 | + return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, FLOOR)); |
467 | +} |
468 | + |
469 | + |
470 | +inline |
471 | +int my_decimal_ceiling(uint32_t mask, const my_decimal *from, my_decimal *to) |
472 | +{ |
473 | + return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, CEILING)); |
474 | +} |
475 | + |
476 | + |
477 | +int my_decimal2string(uint32_t mask, const my_decimal *d, uint32_t fixed_prec, |
478 | + uint32_t fixed_dec, char filler, String *str); |
479 | + |
480 | +inline |
481 | +int my_decimal2int(uint32_t mask, const my_decimal *d, bool unsigned_flag, |
482 | + int64_t *l) |
483 | +{ |
484 | + my_decimal rounded; |
485 | + /* decimal_round can return only E_DEC_TRUNCATED */ |
486 | + decimal_round(static_cast<const decimal_t*>(d), &rounded, 0, HALF_UP); |
487 | + return check_result(mask, (unsigned_flag ? |
488 | + decimal2uint64_t(&rounded, reinterpret_cast<uint64_t *>(l)) : |
489 | + decimal2int64_t(&rounded, l))); |
490 | +} |
491 | + |
492 | + |
493 | +inline |
494 | +int my_decimal2double(uint32_t, const my_decimal *d, double *result) |
495 | +{ |
496 | + /* No need to call check_result as this will always succeed */ |
497 | + return decimal2double(static_cast<const decimal_t*>(d), result); |
498 | +} |
499 | + |
500 | + |
501 | +inline |
502 | +int str2my_decimal(uint32_t mask, char *str, my_decimal *d, char **end) |
503 | +{ |
504 | + return check_result_and_overflow(mask, string2decimal(str, static_cast<decimal_t*>(d),end), |
505 | + d); |
506 | +} |
507 | + |
508 | + |
509 | +int str2my_decimal(uint32_t mask, const char *from, uint32_t length, |
510 | + const CHARSET_INFO * charset, my_decimal *decimal_value); |
511 | + |
512 | +inline |
513 | +int string2my_decimal(uint32_t mask, const String *str, my_decimal *d) |
514 | +{ |
515 | + return str2my_decimal(mask, str->ptr(), str->length(), str->charset(), d); |
516 | +} |
517 | + |
518 | + |
519 | +my_decimal *date2my_decimal(DRIZZLE_TIME *ltime, my_decimal *dec); |
520 | + |
521 | + |
522 | +inline |
523 | +int double2my_decimal(uint32_t mask, double val, my_decimal *d) |
524 | +{ |
525 | + return check_result_and_overflow(mask, double2decimal(val, static_cast<decimal_t*>(d)), d); |
526 | +} |
527 | + |
528 | + |
529 | +inline |
530 | +int int2my_decimal(uint32_t mask, int64_t i, bool unsigned_flag, my_decimal *d) |
531 | +{ |
532 | + return check_result(mask, (unsigned_flag ? |
533 | + uint64_t2decimal(static_cast<uint64_t>(i), d) : |
534 | + int64_t2decimal(i, d))); |
535 | +} |
536 | + |
537 | + |
538 | +inline |
539 | +void my_decimal_neg(decimal_t *arg) |
540 | +{ |
541 | + if (decimal_is_zero(arg)) |
542 | + { |
543 | + arg->sign= 0; |
544 | + return; |
545 | + } |
546 | + decimal_neg(arg); |
547 | +} |
548 | + |
549 | + |
550 | +inline |
551 | +int my_decimal_add(uint32_t mask, my_decimal *res, const my_decimal *a, |
552 | + const my_decimal *b) |
553 | +{ |
554 | + return check_result_and_overflow(mask, |
555 | + decimal_add(static_cast<const decimal_t*>(a), |
556 | + static_cast<const decimal_t*>(b), res), |
557 | + res); |
558 | +} |
559 | + |
560 | + |
561 | +inline |
562 | +int my_decimal_sub(uint32_t mask, my_decimal *res, const my_decimal *a, |
563 | + const my_decimal *b) |
564 | +{ |
565 | + return check_result_and_overflow(mask, |
566 | + decimal_sub(static_cast<const decimal_t*>(a), |
567 | + static_cast<const decimal_t*>(b), res), |
568 | + res); |
569 | +} |
570 | + |
571 | + |
572 | +inline |
573 | +int my_decimal_mul(uint32_t mask, my_decimal *res, const my_decimal *a, |
574 | + const my_decimal *b) |
575 | +{ |
576 | + return check_result_and_overflow(mask, |
577 | + decimal_mul(static_cast<const decimal_t*>(a), |
578 | + static_cast<const decimal_t*>(b),res), |
579 | + res); |
580 | +} |
581 | + |
582 | + |
583 | +inline |
584 | +int my_decimal_div(uint32_t mask, my_decimal *res, const my_decimal *a, |
585 | + const my_decimal *b, int div_scale_inc) |
586 | +{ |
587 | + return check_result_and_overflow(mask, |
588 | + decimal_div(static_cast<const decimal_t*>(a), |
589 | + static_cast<const decimal_t*>(b),res, |
590 | + div_scale_inc), |
591 | + res); |
592 | +} |
593 | + |
594 | + |
595 | +inline |
596 | +int my_decimal_mod(uint32_t mask, my_decimal *res, const my_decimal *a, |
597 | + const my_decimal *b) |
598 | +{ |
599 | + return check_result_and_overflow(mask, |
600 | + decimal_mod(static_cast<const decimal_t*>(a), |
601 | + static_cast<const decimal_t*>(b),res), |
602 | + res); |
603 | +} |
604 | + |
605 | + |
606 | +/** |
607 | + @return |
608 | + -1 if a<b, 1 if a>b and 0 if a==b |
609 | +*/ |
610 | +inline |
611 | +int my_decimal_cmp(const my_decimal *a, const my_decimal *b) |
612 | +{ |
613 | + return decimal_cmp(static_cast<const decimal_t*>(a), |
614 | + static_cast<const decimal_t*>(b)); |
615 | +} |
616 | + |
617 | + |
618 | +inline |
619 | +int my_decimal_intg(const my_decimal *a) |
620 | +{ |
621 | + return decimal_intg(static_cast<const decimal_t*>(a)); |
622 | +} |
623 | + |
624 | + |
625 | +void my_decimal_trim(uint32_t *precision, uint32_t *scale); |
626 | |
627 | } /* namespace drizzled */ |
628 | |
629 | |
630 | === modified file 'drizzled/field.h' |
631 | --- drizzled/field.h 2010-03-02 06:41:59 +0000 |
632 | +++ drizzled/field.h 2010-03-28 01:34:23 +0000 |
633 | @@ -26,7 +26,7 @@ |
634 | #define DRIZZLED_FIELD_H |
635 | |
636 | #include "drizzled/sql_error.h" |
637 | -#include "drizzled/my_decimal.h" |
638 | +#include "drizzled/decimal.h" |
639 | #include "drizzled/key_map.h" |
640 | #include "drizzled/sql_bitmap.h" |
641 | #include "drizzled/sql_list.h" |
642 | |
643 | === modified file 'drizzled/hybrid_type.h' |
644 | --- drizzled/hybrid_type.h 2010-02-04 08:14:46 +0000 |
645 | +++ drizzled/hybrid_type.h 2010-03-28 01:34:23 +0000 |
646 | @@ -20,7 +20,7 @@ |
647 | #ifndef DRIZZLED_HYBRID_TYPE_H |
648 | #define DRIZZLED_HYBRID_TYPE_H |
649 | |
650 | -#include <drizzled/my_decimal.h> |
651 | +#include <drizzled/decimal.h> |
652 | |
653 | namespace drizzled |
654 | { |
655 | |
656 | === modified file 'drizzled/include.am' |
657 | --- drizzled/include.am 2010-03-22 17:38:58 +0000 |
658 | +++ drizzled/include.am 2010-03-28 01:34:23 +0000 |
659 | @@ -255,7 +255,6 @@ |
660 | drizzled/memory/sql_alloc.h \ |
661 | drizzled/memory/multi_malloc.h \ |
662 | drizzled/memory/root.h \ |
663 | - drizzled/my_decimal.h \ |
664 | drizzled/my_getopt.h \ |
665 | drizzled/my_hash.h \ |
666 | drizzled/my_time.h \ |
667 | @@ -632,7 +631,6 @@ |
668 | drizzled/key_map.cc \ |
669 | drizzled/lock.cc \ |
670 | drizzled/lookup_symbol.cc \ |
671 | - drizzled/my_decimal.cc \ |
672 | drizzled/my_getsystime.cc \ |
673 | drizzled/my_hash.cc \ |
674 | drizzled/my_time.cc \ |
675 | |
676 | === modified file 'drizzled/item.h' |
677 | --- drizzled/item.h 2010-03-02 06:41:59 +0000 |
678 | +++ drizzled/item.h 2010-03-28 01:34:23 +0000 |
679 | @@ -22,7 +22,7 @@ |
680 | |
681 | #include <drizzled/dtcollation.h> |
682 | #include <drizzled/my_time.h> |
683 | -#include <drizzled/my_decimal.h> |
684 | +#include <drizzled/decimal.h> |
685 | #include <drizzled/sql_bitmap.h> |
686 | #include <drizzled/sql_list.h> |
687 | #include "drizzled/memory/sql_alloc.h" |
688 | |
689 | === removed file 'drizzled/my_decimal.cc' |
690 | --- drizzled/my_decimal.cc 2010-02-04 08:14:46 +0000 |
691 | +++ drizzled/my_decimal.cc 1970-01-01 00:00:00 +0000 |
692 | @@ -1,243 +0,0 @@ |
693 | -/* Copyright (C) 2005-2006 MySQL AB |
694 | - |
695 | - This program is free software; you can redistribute it and/or modify |
696 | - it under the terms of the GNU General Public License as published by |
697 | - the Free Software Foundation; version 2 of the License. |
698 | - |
699 | - This program is distributed in the hope that it will be useful, |
700 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
701 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
702 | - GNU General Public License for more details. |
703 | - |
704 | - You should have received a copy of the GNU General Public License |
705 | - along with this program; if not, write to the Free Software |
706 | - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
707 | - |
708 | -#include "config.h" |
709 | -#include <time.h> |
710 | -#include "drizzled/current_session.h" |
711 | -#include "drizzled/error.h" |
712 | -#include "drizzled/field.h" |
713 | -#include "drizzled/internal/my_sys.h" |
714 | - |
715 | -namespace drizzled |
716 | -{ |
717 | - |
718 | -/** |
719 | - report result of decimal operation. |
720 | - |
721 | - @param result decimal library return code (E_DEC_* see include/decimal.h) |
722 | - |
723 | - @todo |
724 | - Fix error messages |
725 | - |
726 | - @return |
727 | - result |
728 | -*/ |
729 | - |
730 | -int decimal_operation_results(int result) |
731 | -{ |
732 | - switch (result) { |
733 | - case E_DEC_OK: |
734 | - break; |
735 | - case E_DEC_TRUNCATED: |
736 | - push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN, |
737 | - ER_WARN_DATA_TRUNCATED, ER(ER_WARN_DATA_TRUNCATED), |
738 | - "", (long)-1); |
739 | - break; |
740 | - case E_DEC_OVERFLOW: |
741 | - push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
742 | - ER_TRUNCATED_WRONG_VALUE, |
743 | - ER(ER_TRUNCATED_WRONG_VALUE), |
744 | - "DECIMAL", ""); |
745 | - break; |
746 | - case E_DEC_DIV_ZERO: |
747 | - push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
748 | - ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO)); |
749 | - break; |
750 | - case E_DEC_BAD_NUM: |
751 | - push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
752 | - ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, |
753 | - ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), |
754 | - "decimal", "", "", (long)-1); |
755 | - break; |
756 | - case E_DEC_OOM: |
757 | - my_error(ER_OUT_OF_RESOURCES, MYF(0)); |
758 | - break; |
759 | - default: |
760 | - assert(0); |
761 | - } |
762 | - return result; |
763 | -} |
764 | - |
765 | - |
766 | -/** |
767 | - @brief Converting decimal to string |
768 | - |
769 | - @details Convert given my_decimal to String; allocate buffer as needed. |
770 | - |
771 | - @param[in] mask what problems to warn on (mask of E_DEC_* values) |
772 | - @param[in] d the decimal to print |
773 | - @param[in] fixed_prec overall number of digits if ZEROFILL, 0 otherwise |
774 | - @param[in] fixed_dec number of decimal places (if fixed_prec != 0) |
775 | - @param[in] filler what char to pad with (ZEROFILL et al.) |
776 | - @param[out] *str where to store the resulting string |
777 | - |
778 | - @return error coce |
779 | - @retval E_DEC_OK |
780 | - @retval E_DEC_TRUNCATED |
781 | - @retval E_DEC_OVERFLOW |
782 | - @retval E_DEC_OOM |
783 | -*/ |
784 | - |
785 | -int my_decimal2string(uint32_t mask, const my_decimal *d, |
786 | - uint32_t fixed_prec, uint32_t fixed_dec, |
787 | - char filler, String *str) |
788 | -{ |
789 | - /* |
790 | - Calculate the size of the string: For DECIMAL(a,b), fixed_prec==a |
791 | - holds true iff the type is also ZEROFILL, which in turn implies |
792 | - UNSIGNED. Hence the buffer for a ZEROFILLed value is the length |
793 | - the user requested, plus one for a possible decimal point, plus |
794 | - one if the user only wanted decimal places, but we force a leading |
795 | - zero on them. Because the type is implicitly UNSIGNED, we do not |
796 | - need to reserve a character for the sign. For all other cases, |
797 | - fixed_prec will be 0, and my_decimal_string_length() will be called |
798 | - instead to calculate the required size of the buffer. |
799 | - */ |
800 | - int length= (fixed_prec |
801 | - ? (fixed_prec + ((fixed_prec == fixed_dec) ? 1 : 0) + 1) |
802 | - : my_decimal_string_length(d)); |
803 | - int result; |
804 | - if (str->alloc(length)) |
805 | - return check_result(mask, E_DEC_OOM); |
806 | - result= decimal2string((decimal_t*) d, (char*) str->ptr(), |
807 | - &length, (int)fixed_prec, fixed_dec, |
808 | - filler); |
809 | - str->length(length); |
810 | - return check_result(mask, result); |
811 | -} |
812 | - |
813 | - |
814 | -/* |
815 | - Convert from decimal to binary representation |
816 | - |
817 | - SYNOPSIS |
818 | - my_decimal2binary() |
819 | - mask error processing mask |
820 | - d number for conversion |
821 | - bin pointer to buffer where to write result |
822 | - prec overall number of decimal digits |
823 | - scale number of decimal digits after decimal point |
824 | - |
825 | - NOTE |
826 | - Before conversion we round number if it need but produce truncation |
827 | - error in this case |
828 | - |
829 | - RETURN |
830 | - E_DEC_OK |
831 | - E_DEC_TRUNCATED |
832 | - E_DEC_OVERFLOW |
833 | -*/ |
834 | - |
835 | -int my_decimal2binary(uint32_t mask, const my_decimal *d, unsigned char *bin, int prec, |
836 | - int scale) |
837 | -{ |
838 | - int err1= E_DEC_OK, err2; |
839 | - my_decimal rounded; |
840 | - my_decimal2decimal(d, &rounded); |
841 | - rounded.frac= decimal_actual_fraction(&rounded); |
842 | - if (scale < rounded.frac) |
843 | - { |
844 | - err1= E_DEC_TRUNCATED; |
845 | - /* decimal_round can return only E_DEC_TRUNCATED */ |
846 | - decimal_round(&rounded, &rounded, scale, HALF_UP); |
847 | - } |
848 | - err2= decimal2bin(&rounded, bin, prec, scale); |
849 | - if (!err2) |
850 | - err2= err1; |
851 | - return check_result(mask, err2); |
852 | -} |
853 | - |
854 | - |
855 | -/* |
856 | - Convert string for decimal when string can be in some multibyte charset |
857 | - |
858 | - SYNOPSIS |
859 | - str2my_decimal() |
860 | - mask error processing mask |
861 | - from string to process |
862 | - length length of given string |
863 | - charset charset of given string |
864 | - decimal_value buffer for result storing |
865 | - |
866 | - RESULT |
867 | - E_DEC_OK |
868 | - E_DEC_TRUNCATED |
869 | - E_DEC_OVERFLOW |
870 | - E_DEC_BAD_NUM |
871 | - E_DEC_OOM |
872 | -*/ |
873 | - |
874 | -int str2my_decimal(uint32_t mask, const char *from, uint32_t length, |
875 | - const CHARSET_INFO * charset, my_decimal *decimal_value) |
876 | -{ |
877 | - char *end, *from_end; |
878 | - int err; |
879 | - char buff[STRING_BUFFER_USUAL_SIZE]; |
880 | - String tmp(buff, sizeof(buff), &my_charset_bin); |
881 | - if (charset->mbminlen > 1) |
882 | - { |
883 | - uint32_t dummy_errors; |
884 | - tmp.copy(from, length, charset, &my_charset_utf8_general_ci, &dummy_errors); |
885 | - from= tmp.ptr(); |
886 | - length= tmp.length(); |
887 | - charset= &my_charset_bin; |
888 | - } |
889 | - from_end= end= (char*) from+length; |
890 | - err= string2decimal((char *)from, (decimal_t*) decimal_value, &end); |
891 | - if (end != from_end && !err) |
892 | - { |
893 | - /* Give warning if there is something other than end space */ |
894 | - for ( ; end < from_end; end++) |
895 | - { |
896 | - if (!my_isspace(&my_charset_utf8_general_ci, *end)) |
897 | - { |
898 | - err= E_DEC_TRUNCATED; |
899 | - break; |
900 | - } |
901 | - } |
902 | - } |
903 | - check_result_and_overflow(mask, err, decimal_value); |
904 | - return err; |
905 | -} |
906 | - |
907 | - |
908 | -my_decimal *date2my_decimal(DRIZZLE_TIME *ltime, my_decimal *dec) |
909 | -{ |
910 | - int64_t date; |
911 | - date = (ltime->year*100L + ltime->month)*100L + ltime->day; |
912 | - if (ltime->time_type > DRIZZLE_TIMESTAMP_DATE) |
913 | - date= ((date*100L + ltime->hour)*100L+ ltime->minute)*100L + ltime->second; |
914 | - if (int2my_decimal(E_DEC_FATAL_ERROR, date, false, dec)) |
915 | - return dec; |
916 | - if (ltime->second_part) |
917 | - { |
918 | - dec->buf[(dec->intg-1) / 9 + 1]= ltime->second_part * 1000; |
919 | - dec->frac= 6; |
920 | - } |
921 | - return dec; |
922 | -} |
923 | - |
924 | - |
925 | -void my_decimal_trim(uint32_t *precision, uint32_t *scale) |
926 | -{ |
927 | - if (!(*precision) && !(*scale)) |
928 | - { |
929 | - *precision= 10; |
930 | - *scale= 0; |
931 | - return; |
932 | - } |
933 | -} |
934 | - |
935 | -} /* namespace drizzled */ |
936 | |
937 | === removed file 'drizzled/my_decimal.h' |
938 | --- drizzled/my_decimal.h 2010-02-04 08:14:46 +0000 |
939 | +++ drizzled/my_decimal.h 1970-01-01 00:00:00 +0000 |
940 | @@ -1,395 +0,0 @@ |
941 | -/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
942 | - * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
943 | - * |
944 | - * Copyright (C) 2008 Sun Microsystems |
945 | - * |
946 | - * This program is free software; you can redistribute it and/or modify |
947 | - * it under the terms of the GNU General Public License as published by |
948 | - * the Free Software Foundation; version 2 of the License. |
949 | - * |
950 | - * This program is distributed in the hope that it will be useful, |
951 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
952 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
953 | - * GNU General Public License for more details. |
954 | - * |
955 | - * You should have received a copy of the GNU General Public License |
956 | - * along with this program; if not, write to the Free Software |
957 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
958 | - */ |
959 | - |
960 | -/** |
961 | - @file |
962 | - |
963 | - It is interface module to fixed precision decimals library. |
964 | - |
965 | - Most functions use 'uint32_t mask' as parameter, if during operation error |
966 | - which fit in this mask is detected then it will be processed automatically |
967 | - here. (errors are E_DEC_* constants, see drizzled/decimal.h) |
968 | - |
969 | - Most function are just inline wrappers around library calls |
970 | -*/ |
971 | - |
972 | -#ifndef DRIZZLED_MY_DECIMAL_H |
973 | -#define DRIZZLED_MY_DECIMAL_H |
974 | - |
975 | -#include <drizzled/decimal.h> |
976 | -#include <drizzled/my_time.h> |
977 | -#include <drizzled/definitions.h> |
978 | -#include <drizzled/sql_string.h> |
979 | - |
980 | -namespace drizzled |
981 | -{ |
982 | - |
983 | -#define DECIMAL_LONGLONG_DIGITS 22 |
984 | -#define DECIMAL_LONG_DIGITS 10 |
985 | -#define DECIMAL_LONG3_DIGITS 8 |
986 | - |
987 | -/** maximum length of buffer in our big digits (uint32_t). */ |
988 | -#define DECIMAL_BUFF_LENGTH 9 |
989 | - |
990 | -/* the number of digits that my_decimal can possibly contain */ |
991 | -#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9) |
992 | - |
993 | - |
994 | -/** |
995 | - maximum guaranteed precision of number in decimal digits (number of our |
996 | - digits * number of decimal digits in one our big digit - number of decimal |
997 | - digits in one our big digit decreased by 1 (because we always put decimal |
998 | - point on the border of our big digits)) |
999 | -*/ |
1000 | -#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2) |
1001 | -#define DECIMAL_MAX_SCALE 30 |
1002 | -#define DECIMAL_NOT_SPECIFIED 31 |
1003 | - |
1004 | -/** |
1005 | - maximum length of string representation (number of maximum decimal |
1006 | - digits + 1 position for sign + 1 position for decimal point) |
1007 | -*/ |
1008 | -#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2) |
1009 | - |
1010 | -/** |
1011 | - maximum size of packet length. |
1012 | -*/ |
1013 | -#define DECIMAL_MAX_FIELD_SIZE DECIMAL_MAX_PRECISION |
1014 | - |
1015 | -inline int my_decimal_int_part(uint32_t precision, uint32_t decimals) |
1016 | -{ |
1017 | - return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals); |
1018 | -} |
1019 | - |
1020 | - |
1021 | -/** |
1022 | - my_decimal class limits 'decimal_t' type to what we need in MySQL. |
1023 | - |
1024 | - It contains internally all necessary space needed by the instance so |
1025 | - no extra memory is needed. One should call fix_buffer_pointer() function |
1026 | - when he moves my_decimal objects in memory. |
1027 | -*/ |
1028 | - |
1029 | -class my_decimal :public decimal_t |
1030 | -{ |
1031 | - decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; |
1032 | - |
1033 | -public: |
1034 | - |
1035 | - void init() |
1036 | - { |
1037 | - len= DECIMAL_BUFF_LENGTH; |
1038 | - buf= buffer; |
1039 | -#if !defined (HAVE_purify) |
1040 | - /* Set buffer to 'random' value to find wrong buffer usage */ |
1041 | - for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++) |
1042 | - buffer[i]= i; |
1043 | -#endif |
1044 | - } |
1045 | - my_decimal() |
1046 | - { |
1047 | - init(); |
1048 | - } |
1049 | - void fix_buffer_pointer() { buf= buffer; } |
1050 | - |
1051 | - bool sign() const { return decimal_t::sign; } |
1052 | - void sign(bool s) { decimal_t::sign= s; } |
1053 | - uint32_t precision() const { return intg + frac; } |
1054 | -}; |
1055 | - |
1056 | -int decimal_operation_results(int result); |
1057 | - |
1058 | -inline |
1059 | -void max_my_decimal(my_decimal *to, int precision, int frac) |
1060 | -{ |
1061 | - assert((precision <= DECIMAL_MAX_PRECISION)&& |
1062 | - (frac <= DECIMAL_MAX_SCALE)); |
1063 | - max_decimal(precision, frac, (decimal_t*) to); |
1064 | -} |
1065 | - |
1066 | -inline void max_internal_decimal(my_decimal *to) |
1067 | -{ |
1068 | - max_my_decimal(to, DECIMAL_MAX_PRECISION, 0); |
1069 | -} |
1070 | - |
1071 | -inline int check_result(uint32_t mask, int result) |
1072 | -{ |
1073 | - if (result & mask) |
1074 | - decimal_operation_results(result); |
1075 | - return result; |
1076 | -} |
1077 | - |
1078 | -inline int check_result_and_overflow(uint32_t mask, int result, my_decimal *val) |
1079 | -{ |
1080 | - if (check_result(mask, result) & E_DEC_OVERFLOW) |
1081 | - { |
1082 | - bool sign= val->sign(); |
1083 | - val->fix_buffer_pointer(); |
1084 | - max_internal_decimal(val); |
1085 | - val->sign(sign); |
1086 | - } |
1087 | - return result; |
1088 | -} |
1089 | - |
1090 | -inline uint32_t my_decimal_length_to_precision(uint32_t length, uint32_t scale, |
1091 | - bool unsigned_flag) |
1092 | -{ |
1093 | - return (uint32_t) (length - (scale>0 ? 1:0) - (unsigned_flag ? 0:1)); |
1094 | -} |
1095 | - |
1096 | -inline uint32_t my_decimal_precision_to_length(uint32_t precision, uint8_t scale, |
1097 | - bool unsigned_flag) |
1098 | -{ |
1099 | - set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION); |
1100 | - return static_cast<uint32_t>(precision + (scale>0 ? 1:0) + (unsigned_flag ? 0:1)); |
1101 | -} |
1102 | - |
1103 | -inline |
1104 | -int my_decimal_string_length(const my_decimal *d) |
1105 | -{ |
1106 | - return decimal_string_size(d); |
1107 | -} |
1108 | - |
1109 | - |
1110 | -inline |
1111 | -int my_decimal_max_length(const my_decimal *d) |
1112 | -{ |
1113 | - /* -1 because we do not count \0 */ |
1114 | - return decimal_string_size(d) - 1; |
1115 | -} |
1116 | - |
1117 | - |
1118 | -inline |
1119 | -int my_decimal_get_binary_size(uint32_t precision, uint32_t scale) |
1120 | -{ |
1121 | - return decimal_bin_size(static_cast<int>(precision), static_cast<int>(scale)); |
1122 | -} |
1123 | - |
1124 | - |
1125 | -inline |
1126 | -void my_decimal2decimal(const my_decimal *from, my_decimal *to) |
1127 | -{ |
1128 | - *to= *from; |
1129 | - to->fix_buffer_pointer(); |
1130 | -} |
1131 | - |
1132 | - |
1133 | -int my_decimal2binary(uint32_t mask, const my_decimal *d, unsigned char *bin, int prec, |
1134 | - int scale); |
1135 | - |
1136 | - |
1137 | -inline |
1138 | -int binary2my_decimal(uint32_t mask, const unsigned char *bin, my_decimal *d, int prec, |
1139 | - int scale) |
1140 | -{ |
1141 | - return check_result(mask, bin2decimal(bin, static_cast<decimal_t*>(d), prec, scale)); |
1142 | -} |
1143 | - |
1144 | - |
1145 | -inline |
1146 | -int my_decimal_set_zero(my_decimal *d) |
1147 | -{ |
1148 | - decimal_make_zero(static_cast<decimal_t*> (d)); |
1149 | - return 0; |
1150 | -} |
1151 | - |
1152 | - |
1153 | -inline |
1154 | -bool my_decimal_is_zero(const my_decimal *decimal_value) |
1155 | -{ |
1156 | - return decimal_is_zero(static_cast<const decimal_t*>(decimal_value)); |
1157 | -} |
1158 | - |
1159 | - |
1160 | -inline |
1161 | -int my_decimal_round(uint32_t mask, const my_decimal *from, int scale, |
1162 | - bool truncate, my_decimal *to) |
1163 | -{ |
1164 | - return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, scale, |
1165 | - (truncate ? TRUNCATE : HALF_UP))); |
1166 | -} |
1167 | - |
1168 | - |
1169 | -inline |
1170 | -int my_decimal_floor(uint32_t mask, const my_decimal *from, my_decimal *to) |
1171 | -{ |
1172 | - return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, FLOOR)); |
1173 | -} |
1174 | - |
1175 | - |
1176 | -inline |
1177 | -int my_decimal_ceiling(uint32_t mask, const my_decimal *from, my_decimal *to) |
1178 | -{ |
1179 | - return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, CEILING)); |
1180 | -} |
1181 | - |
1182 | - |
1183 | -int my_decimal2string(uint32_t mask, const my_decimal *d, uint32_t fixed_prec, |
1184 | - uint32_t fixed_dec, char filler, String *str); |
1185 | - |
1186 | -inline |
1187 | -int my_decimal2int(uint32_t mask, const my_decimal *d, bool unsigned_flag, |
1188 | - int64_t *l) |
1189 | -{ |
1190 | - my_decimal rounded; |
1191 | - /* decimal_round can return only E_DEC_TRUNCATED */ |
1192 | - decimal_round(static_cast<const decimal_t*>(d), &rounded, 0, HALF_UP); |
1193 | - return check_result(mask, (unsigned_flag ? |
1194 | - decimal2uint64_t(&rounded, reinterpret_cast<uint64_t *>(l)) : |
1195 | - decimal2int64_t(&rounded, l))); |
1196 | -} |
1197 | - |
1198 | - |
1199 | -inline |
1200 | -int my_decimal2double(uint32_t, const my_decimal *d, double *result) |
1201 | -{ |
1202 | - /* No need to call check_result as this will always succeed */ |
1203 | - return decimal2double(static_cast<const decimal_t*>(d), result); |
1204 | -} |
1205 | - |
1206 | - |
1207 | -inline |
1208 | -int str2my_decimal(uint32_t mask, char *str, my_decimal *d, char **end) |
1209 | -{ |
1210 | - return check_result_and_overflow(mask, string2decimal(str, static_cast<decimal_t*>(d),end), |
1211 | - d); |
1212 | -} |
1213 | - |
1214 | - |
1215 | -int str2my_decimal(uint32_t mask, const char *from, uint32_t length, |
1216 | - const CHARSET_INFO * charset, my_decimal *decimal_value); |
1217 | - |
1218 | -inline |
1219 | -int string2my_decimal(uint32_t mask, const String *str, my_decimal *d) |
1220 | -{ |
1221 | - return str2my_decimal(mask, str->ptr(), str->length(), str->charset(), d); |
1222 | -} |
1223 | - |
1224 | - |
1225 | -my_decimal *date2my_decimal(DRIZZLE_TIME *ltime, my_decimal *dec); |
1226 | - |
1227 | - |
1228 | -inline |
1229 | -int double2my_decimal(uint32_t mask, double val, my_decimal *d) |
1230 | -{ |
1231 | - return check_result_and_overflow(mask, double2decimal(val, static_cast<decimal_t*>(d)), d); |
1232 | -} |
1233 | - |
1234 | - |
1235 | -inline |
1236 | -int int2my_decimal(uint32_t mask, int64_t i, bool unsigned_flag, my_decimal *d) |
1237 | -{ |
1238 | - return check_result(mask, (unsigned_flag ? |
1239 | - uint64_t2decimal(static_cast<uint64_t>(i), d) : |
1240 | - int64_t2decimal(i, d))); |
1241 | -} |
1242 | - |
1243 | - |
1244 | -inline |
1245 | -void my_decimal_neg(decimal_t *arg) |
1246 | -{ |
1247 | - if (decimal_is_zero(arg)) |
1248 | - { |
1249 | - arg->sign= 0; |
1250 | - return; |
1251 | - } |
1252 | - decimal_neg(arg); |
1253 | -} |
1254 | - |
1255 | - |
1256 | -inline |
1257 | -int my_decimal_add(uint32_t mask, my_decimal *res, const my_decimal *a, |
1258 | - const my_decimal *b) |
1259 | -{ |
1260 | - return check_result_and_overflow(mask, |
1261 | - decimal_add(static_cast<const decimal_t*>(a), |
1262 | - static_cast<const decimal_t*>(b), res), |
1263 | - res); |
1264 | -} |
1265 | - |
1266 | - |
1267 | -inline |
1268 | -int my_decimal_sub(uint32_t mask, my_decimal *res, const my_decimal *a, |
1269 | - const my_decimal *b) |
1270 | -{ |
1271 | - return check_result_and_overflow(mask, |
1272 | - decimal_sub(static_cast<const decimal_t*>(a), |
1273 | - static_cast<const decimal_t*>(b), res), |
1274 | - res); |
1275 | -} |
1276 | - |
1277 | - |
1278 | -inline |
1279 | -int my_decimal_mul(uint32_t mask, my_decimal *res, const my_decimal *a, |
1280 | - const my_decimal *b) |
1281 | -{ |
1282 | - return check_result_and_overflow(mask, |
1283 | - decimal_mul(static_cast<const decimal_t*>(a), |
1284 | - static_cast<const decimal_t*>(b),res), |
1285 | - res); |
1286 | -} |
1287 | - |
1288 | - |
1289 | -inline |
1290 | -int my_decimal_div(uint32_t mask, my_decimal *res, const my_decimal *a, |
1291 | - const my_decimal *b, int div_scale_inc) |
1292 | -{ |
1293 | - return check_result_and_overflow(mask, |
1294 | - decimal_div(static_cast<const decimal_t*>(a), |
1295 | - static_cast<const decimal_t*>(b),res, |
1296 | - div_scale_inc), |
1297 | - res); |
1298 | -} |
1299 | - |
1300 | - |
1301 | -inline |
1302 | -int my_decimal_mod(uint32_t mask, my_decimal *res, const my_decimal *a, |
1303 | - const my_decimal *b) |
1304 | -{ |
1305 | - return check_result_and_overflow(mask, |
1306 | - decimal_mod(static_cast<const decimal_t*>(a), |
1307 | - static_cast<const decimal_t*>(b),res), |
1308 | - res); |
1309 | -} |
1310 | - |
1311 | - |
1312 | -/** |
1313 | - @return |
1314 | - -1 if a<b, 1 if a>b and 0 if a==b |
1315 | -*/ |
1316 | -inline |
1317 | -int my_decimal_cmp(const my_decimal *a, const my_decimal *b) |
1318 | -{ |
1319 | - return decimal_cmp(static_cast<const decimal_t*>(a), |
1320 | - static_cast<const decimal_t*>(b)); |
1321 | -} |
1322 | - |
1323 | - |
1324 | -inline |
1325 | -int my_decimal_intg(const my_decimal *a) |
1326 | -{ |
1327 | - return decimal_intg(static_cast<const decimal_t*>(a)); |
1328 | -} |
1329 | - |
1330 | - |
1331 | -void my_decimal_trim(uint32_t *precision, uint32_t *scale); |
1332 | - |
1333 | -} /* namespace drizzled */ |
1334 | - |
1335 | -#endif /* DRIZZLED_MY_DECIMAL_H */ |
1336 | |
1337 | === modified file 'drizzled/temporal.cc' |
1338 | --- drizzled/temporal.cc 2010-02-04 08:14:46 +0000 |
1339 | +++ drizzled/temporal.cc 2010-03-28 01:34:23 +0000 |
1340 | @@ -37,7 +37,7 @@ |
1341 | #include "config.h" |
1342 | |
1343 | #include "drizzled/charset_info.h" |
1344 | -#include "drizzled/my_decimal.h" |
1345 | +#include "drizzled/decimal.h" |
1346 | #include "drizzled/calendar.h" |
1347 | #include "drizzled/temporal.h" |
1348 | #ifdef NOTYETIMPLEMENTED |
1349 | |
1350 | === modified file 'support-files/drizzle.spec.in' |
1351 | --- support-files/drizzle.spec.in 2010-02-12 20:53:27 +0000 |
1352 | +++ support-files/drizzle.spec.in 2010-03-28 01:34:23 +0000 |
1353 | @@ -312,7 +312,6 @@ |
1354 | %{_includedir}/drizzled/message/statement_transform.h |
1355 | %{_includedir}/drizzled/message/table.pb.h |
1356 | %{_includedir}/drizzled/message/transaction.pb.h |
1357 | -%{_includedir}/drizzled/my_decimal.h |
1358 | %{_includedir}/drizzled/my_error.h |
1359 | %{_includedir}/drizzled/my_getopt.h |
1360 | %{_includedir}/drizzled/my_hash.h |
Wonderful. Looks like you left in a commentted out section of code:
+//#include "drizzled/error.h"
+//#include "drizzled/field.h"
Could you remove those? Otherwise, looks fantastic.