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