~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/fdecimal.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
23
 
#include <drizzled/field/decimal.h>
24
 
#include <drizzled/error.h>
25
 
#include <drizzled/table.h>
26
 
#include <drizzled/session.h>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
extern my_decimal decimal_zero;
 
22
#include <drizzled/server_includes.h>
 
23
#include <drizzled/field/fdecimal.h>
 
24
#include <drizzled/drizzled_error_messages.h>
 
25
 
32
26
 
33
27
/****************************************************************************
34
 
 ** File_decimal
35
 
 ****************************************************************************/
36
 
 
37
 
Field_decimal::Field_decimal(unsigned char *ptr_arg,
38
 
                             uint32_t len_arg,
39
 
                             unsigned char *null_ptr_arg,
40
 
                             unsigned char null_bit_arg,
41
 
                             enum utype unireg_check_arg,
42
 
                             const char *field_name_arg,
43
 
                             uint8_t dec_arg,
44
 
                             bool zero_arg,
45
 
                             bool unsigned_arg)
46
 
:Field_num(ptr_arg,
47
 
           len_arg,
48
 
           null_ptr_arg,
49
 
           null_bit_arg,
50
 
           unireg_check_arg,
51
 
           field_name_arg,
52
 
           dec_arg, zero_arg,
53
 
           unsigned_arg)
54
 
{
55
 
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
56
 
  set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
57
 
  assert((precision <= DECIMAL_MAX_PRECISION) &&
58
 
         (dec <= DECIMAL_MAX_SCALE));
59
 
  bin_size= my_decimal_get_binary_size(precision, dec);
60
 
}
61
 
 
62
 
Field_decimal::Field_decimal(uint32_t len_arg,
63
 
                             bool maybe_null_arg,
64
 
                             const char *name,
65
 
                             uint8_t dec_arg,
66
 
                             bool unsigned_arg)
67
 
:Field_num((unsigned char*) 0,
68
 
           len_arg,
69
 
           maybe_null_arg ? (unsigned char*) "": 0,
70
 
           0,
71
 
           NONE,
72
 
           name,
73
 
           dec_arg,
74
 
           0,
75
 
           unsigned_arg)
76
 
{
77
 
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
78
 
  set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
79
 
  assert((precision <= DECIMAL_MAX_PRECISION) &&
80
 
         (dec <= DECIMAL_MAX_SCALE));
81
 
  bin_size= my_decimal_get_binary_size(precision, dec);
82
 
}
83
 
 
84
 
 
85
 
int Field_decimal::reset(void)
 
28
** Field_new_decimal
 
29
****************************************************************************/
 
30
 
 
31
Field_new_decimal::Field_new_decimal(unsigned char *ptr_arg,
 
32
                                     uint32_t len_arg, unsigned char *null_ptr_arg,
 
33
                                     unsigned char null_bit_arg,
 
34
                                     enum utype unireg_check_arg,
 
35
                                     const char *field_name_arg,
 
36
                                     uint8_t dec_arg,bool zero_arg,
 
37
                                     bool unsigned_arg)
 
38
  :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
39
             unireg_check_arg, field_name_arg, dec_arg, zero_arg, unsigned_arg)
 
40
{
 
41
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
 
42
  set_if_smaller(precision, DECIMAL_MAX_PRECISION);
 
43
  assert((precision <= DECIMAL_MAX_PRECISION) &&
 
44
              (dec <= DECIMAL_MAX_SCALE));
 
45
  bin_size= my_decimal_get_binary_size(precision, dec);
 
46
}
 
47
 
 
48
 
 
49
Field_new_decimal::Field_new_decimal(uint32_t len_arg,
 
50
                                     bool maybe_null_arg,
 
51
                                     const char *name,
 
52
                                     uint8_t dec_arg,
 
53
                                     bool unsigned_arg)
 
54
  :Field_num((unsigned char*) 0, len_arg,
 
55
             maybe_null_arg ? (unsigned char*) "": 0, 0,
 
56
             NONE, name, dec_arg, 0, unsigned_arg)
 
57
{
 
58
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
 
59
  set_if_smaller(precision, DECIMAL_MAX_PRECISION);
 
60
  assert((precision <= DECIMAL_MAX_PRECISION) &&
 
61
              (dec <= DECIMAL_MAX_SCALE));
 
62
  bin_size= my_decimal_get_binary_size(precision, dec);
 
63
}
 
64
 
 
65
 
 
66
int Field_new_decimal::reset(void)
86
67
{
87
68
  store_value(&decimal_zero);
88
69
  return 0;
96
77
  @param sign              sign of value which caused overflow
97
78
*/
98
79
 
99
 
void Field_decimal::set_value_on_overflow(my_decimal *decimal_value,
100
 
                                          bool sign)
 
80
void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value,
 
81
                                              bool sign)
101
82
{
102
83
  max_my_decimal(decimal_value, precision, decimals());
103
84
  if (sign)
117
98
  @param decimal_value   my_decimal
118
99
 
119
100
  @retval
120
 
  0 ok
 
101
    0 ok
121
102
  @retval
122
 
  1 error
 
103
    1 error
123
104
*/
124
105
 
125
 
bool Field_decimal::store_value(const my_decimal *decimal_value)
 
106
bool Field_new_decimal::store_value(const my_decimal *decimal_value)
126
107
{
127
 
  int error= my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
128
 
                                         decimal_value, ptr, precision, dec);
129
 
  if (warn_if_overflow(error))
 
108
  int error= 0;
 
109
 
 
110
  if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
 
111
                                         decimal_value, ptr, precision, dec)))
130
112
  {
131
 
    if (error != E_DEC_TRUNCATED)
132
 
    {
133
 
      my_decimal buff;
134
 
      set_value_on_overflow(&buff, decimal_value->sign());
135
 
      my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
136
 
    }
 
113
    my_decimal buff;
 
114
    set_value_on_overflow(&buff, decimal_value->sign());
 
115
    my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
137
116
    error= 1;
138
117
  }
139
118
  return(error);
140
119
}
141
120
 
142
121
 
143
 
int Field_decimal::store(const char *from, uint32_t length,
144
 
                         const CHARSET_INFO * const charset_arg)
 
122
int Field_new_decimal::store(const char *from, uint32_t length,
 
123
                             const CHARSET_INFO * const charset_arg)
145
124
{
146
125
  int err;
147
126
  my_decimal decimal_value;
148
127
 
149
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
150
 
 
151
128
  if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
152
129
                           ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
153
130
                           from, length, charset_arg,
154
131
                           &decimal_value)) &&
155
 
      getTable()->in_use->abort_on_warning)
 
132
      table->in_use->abort_on_warning)
156
133
  {
157
134
    /* Because "from" is not NUL-terminated and we use %s in the ER() */
158
135
    String from_as_str;
159
136
    from_as_str.copy(from, length, &my_charset_bin);
160
137
 
161
 
    push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
138
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
162
139
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
163
140
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
164
141
                        "decimal", from_as_str.c_ptr(), field_name,
165
 
                        (uint32_t) getTable()->in_use->row_count);
 
142
                        (uint32_t) table->in_use->row_count);
166
143
 
167
144
    return(err);
168
145
  }
169
146
 
170
147
  switch (err) {
171
148
  case E_DEC_TRUNCATED:
172
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
173
 
    set_value_on_overflow(&decimal_value, decimal_value.sign());
 
149
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
174
150
    break;
175
151
  case E_DEC_OVERFLOW:
176
152
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
182
158
      String from_as_str;
183
159
      from_as_str.copy(from, length, &my_charset_bin);
184
160
 
185
 
      push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
186
 
                          ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
187
 
                          ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
 
161
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
162
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
 
163
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
188
164
                          "decimal", from_as_str.c_ptr(), field_name,
189
 
                          (uint32_t) getTable()->in_use->row_count);
190
 
      my_decimal_set_zero(&decimal_value);
 
165
                        (uint32_t) table->in_use->row_count);
 
166
    my_decimal_set_zero(&decimal_value);
191
167
 
192
 
      break;
 
168
    break;
193
169
    }
194
170
  }
195
171
 
204
180
  will return E_DEC_TRUNCATED always correctly
205
181
*/
206
182
 
207
 
int Field_decimal::store(double nr)
 
183
int Field_new_decimal::store(double nr)
208
184
{
209
185
  my_decimal decimal_value;
210
186
  int err;
211
187
 
212
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
213
 
 
214
188
  err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
215
189
                         &decimal_value);
216
190
  if (err)
218
192
    if (check_overflow(err))
219
193
      set_value_on_overflow(&decimal_value, decimal_value.sign());
220
194
    /* Only issue a warning if store_value doesn't issue an warning */
221
 
    getTable()->in_use->got_warning= 0;
 
195
    table->in_use->got_warning= 0;
222
196
  }
223
197
  if (store_value(&decimal_value))
224
198
    err= 1;
225
 
  else if (err && !getTable()->in_use->got_warning)
 
199
  else if (err && !table->in_use->got_warning)
226
200
    err= warn_if_overflow(err);
227
201
  return(err);
228
202
}
229
203
 
230
204
 
231
 
int Field_decimal::store(int64_t nr, bool unsigned_val)
 
205
int Field_new_decimal::store(int64_t nr, bool unsigned_val)
232
206
{
233
207
  my_decimal decimal_value;
234
208
  int err;
235
209
 
236
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
237
 
 
238
210
  if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
239
211
                           nr, unsigned_val, &decimal_value)))
240
212
  {
241
213
    if (check_overflow(err))
242
214
      set_value_on_overflow(&decimal_value, decimal_value.sign());
243
215
    /* Only issue a warning if store_value doesn't issue an warning */
244
 
    getTable()->in_use->got_warning= 0;
 
216
    table->in_use->got_warning= 0;
245
217
  }
246
218
  if (store_value(&decimal_value))
247
219
    err= 1;
248
 
  else if (err && not getTable()->in_use->got_warning)
 
220
  else if (err && !table->in_use->got_warning)
249
221
    err= warn_if_overflow(err);
250
222
  return err;
251
223
}
252
224
 
253
225
 
254
 
int Field_decimal::store_decimal(const my_decimal *decimal_value)
 
226
int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
255
227
{
256
228
  return store_value(decimal_value);
257
229
}
258
230
 
259
231
 
260
 
int Field_decimal::store_time(DRIZZLE_TIME *ltime,
261
 
                              enum enum_drizzle_timestamp_type )
 
232
int Field_new_decimal::store_time(DRIZZLE_TIME *ltime,
 
233
                                  enum enum_drizzle_timestamp_type t_type __attribute__((unused)))
262
234
{
263
 
  my_decimal decimal_value;
264
 
  return store_value(date2my_decimal(ltime, &decimal_value));
 
235
    my_decimal decimal_value;
 
236
    return store_value(date2my_decimal(ltime, &decimal_value));
265
237
}
266
238
 
267
239
 
268
 
double Field_decimal::val_real(void)
 
240
double Field_new_decimal::val_real(void)
269
241
{
270
242
  double dbl;
271
243
  my_decimal decimal_value;
272
 
 
273
 
  ASSERT_COLUMN_MARKED_FOR_READ;
274
 
 
275
244
  my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
276
 
 
277
245
  return dbl;
278
246
}
279
247
 
280
248
 
281
 
int64_t Field_decimal::val_int(void)
 
249
int64_t Field_new_decimal::val_int(void)
282
250
{
283
251
  int64_t i;
284
252
  my_decimal decimal_value;
285
 
 
286
 
  ASSERT_COLUMN_MARKED_FOR_READ;
287
 
 
288
253
  my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), false, &i);
289
 
 
290
254
  return i;
291
255
}
292
256
 
293
257
 
294
 
my_decimal* Field_decimal::val_decimal(my_decimal *decimal_value)
 
258
my_decimal* Field_new_decimal::val_decimal(my_decimal *decimal_value)
295
259
{
296
 
  ASSERT_COLUMN_MARKED_FOR_READ;
297
 
 
298
260
  binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
299
261
                    precision, dec);
300
262
  return(decimal_value);
301
263
}
302
264
 
303
265
 
304
 
String *Field_decimal::val_str(String *val_buffer,
305
 
                               String *)
 
266
String *Field_new_decimal::val_str(String *val_buffer,
 
267
                                   String *val_ptr __attribute__((unused)))
306
268
{
307
269
  my_decimal decimal_value;
308
 
 
309
 
  ASSERT_COLUMN_MARKED_FOR_READ;
310
 
 
311
270
  uint32_t fixed_precision= decimal_precision ? precision : 0;
312
271
  my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
313
272
                    fixed_precision, dec, '0', val_buffer);
315
274
}
316
275
 
317
276
 
318
 
int Field_decimal::cmp(const unsigned char *a,const unsigned char*b)
 
277
int Field_new_decimal::cmp(const unsigned char *a,const unsigned char*b)
319
278
{
320
279
  return memcmp(a, b, bin_size);
321
280
}
322
281
 
323
282
 
324
 
void Field_decimal::sort_string(unsigned char *buff,
325
 
                                uint32_t )
 
283
void Field_new_decimal::sort_string(unsigned char *buff,
 
284
                                    uint32_t length __attribute__((unused)))
326
285
{
327
286
  memcpy(buff, ptr, bin_size);
328
287
}
329
288
 
330
289
 
331
 
void Field_decimal::sql_type(String &str) const
 
290
void Field_new_decimal::sql_type(String &str) const
332
291
{
333
292
  const CHARSET_INFO * const cs= str.charset();
334
293
  str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(),
337
296
 
338
297
 
339
298
/**
340
 
  Returns the number of bytes field uses in row-based replication
341
 
  row packed size.
342
 
 
343
 
  This method is used in row-based replication to determine the number
344
 
  of bytes that the field consumes in the row record format. This is
345
 
  used to skip fields in the master that do not exist on the slave.
346
 
 
347
 
  @param   field_metadata   Encoded size in field metadata
348
 
 
349
 
  @returns The size of the field based on the field metadata.
350
 
*/
351
 
uint32_t Field_decimal::pack_length_from_metadata(uint32_t field_metadata)
 
299
   Save the field metadata for new decimal fields.
 
300
 
 
301
   Saves the precision in the first byte and decimals() in the second
 
302
   byte of the field metadata array at index of *metadata_ptr and 
 
303
   *(metadata_ptr + 1).
 
304
 
 
305
   @param   metadata_ptr   First byte of field metadata
 
306
 
 
307
   @returns number of bytes written to metadata_ptr
 
308
*/
 
309
int Field_new_decimal::do_save_field_metadata(unsigned char *metadata_ptr)
 
310
{
 
311
  *metadata_ptr= precision;
 
312
  *(metadata_ptr + 1)= decimals();
 
313
  return 2;
 
314
}
 
315
 
 
316
 
 
317
/**
 
318
   Returns the number of bytes field uses in row-based replication 
 
319
   row packed size.
 
320
 
 
321
   This method is used in row-based replication to determine the number
 
322
   of bytes that the field consumes in the row record format. This is
 
323
   used to skip fields in the master that do not exist on the slave.
 
324
 
 
325
   @param   field_metadata   Encoded size in field metadata
 
326
 
 
327
   @returns The size of the field based on the field metadata.
 
328
*/
 
329
uint32_t Field_new_decimal::pack_length_from_metadata(uint32_t field_metadata)
352
330
{
353
331
  uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
354
 
  uint32_t const source_decimal= field_metadata & 0x00ff;
355
 
  uint32_t const source_size= my_decimal_get_binary_size(source_precision,
356
 
                                                         source_decimal);
 
332
  uint32_t const source_decimal= field_metadata & 0x00ff; 
 
333
  uint32_t const source_size= my_decimal_get_binary_size(source_precision, 
 
334
                                                     source_decimal);
357
335
  return (source_size);
358
336
}
359
337
 
360
338
 
361
 
uint32_t Field_decimal::is_equal(CreateField *new_field_ptr)
362
 
{
363
 
  return ((new_field_ptr->sql_type == real_type()) &&
364
 
          ((new_field_ptr->flags & UNSIGNED_FLAG) ==
365
 
           (uint32_t) (flags & UNSIGNED_FLAG)) &&
366
 
          ((new_field_ptr->flags & AUTO_INCREMENT_FLAG) ==
367
 
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
368
 
          (new_field_ptr->length == max_display_length()) &&
369
 
          (new_field_ptr->decimals == dec));
370
 
}
371
 
 
372
 
 
373
 
/**
374
 
  Unpack a decimal field from row data.
375
 
 
376
 
  This method is used to unpack a decimal or numeric field from a master
377
 
  whose size of the field is less than that of the slave.
378
 
 
379
 
  @param   to         Destination of the data
380
 
  @param   from       Source of the data
381
 
  @param   param_data Precision (upper) and decimal (lower) values
382
 
 
383
 
  @return  New pointer into memory based on from + length of the data
 
339
/**
 
340
   Check to see if field size is compatible with destination.
 
341
 
 
342
   This method is used in row-based replication to verify that the slave's
 
343
   field size is less than or equal to the master's field size. The 
 
344
   encoded field metadata (from the master or source) is decoded and compared
 
345
   to the size of this field (the slave or destination). 
 
346
 
 
347
   @param   field_metadata   Encoded size in field metadata
 
348
 
 
349
   @retval 0 if this field's size is < the source field's size
 
350
   @retval 1 if this field's size is >= the source field's size
 
351
*/
 
352
int Field_new_decimal::compatible_field_size(uint32_t field_metadata)
 
353
{
 
354
  int compatible= 0;
 
355
  uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
 
356
  uint32_t const source_decimal= field_metadata & 0x00ff; 
 
357
  uint32_t const source_size= my_decimal_get_binary_size(source_precision, 
 
358
                                                     source_decimal);
 
359
  uint32_t const destination_size= row_pack_length();
 
360
  compatible= (source_size <= destination_size);
 
361
  if (compatible)
 
362
    compatible= (source_precision <= precision) &&
 
363
                (source_decimal <= decimals());
 
364
  return (compatible);
 
365
}
 
366
 
 
367
 
 
368
uint32_t Field_new_decimal::is_equal(Create_field *new_field)
 
369
{
 
370
  return ((new_field->sql_type == real_type()) &&
 
371
          ((new_field->flags & UNSIGNED_FLAG) == 
 
372
           (uint) (flags & UNSIGNED_FLAG)) &&
 
373
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
 
374
           (uint) (flags & AUTO_INCREMENT_FLAG)) &&
 
375
          (new_field->length == max_display_length()) &&
 
376
          (new_field->decimals == dec));
 
377
}
 
378
 
 
379
 
 
380
/**
 
381
   Unpack a decimal field from row data.
 
382
 
 
383
   This method is used to unpack a decimal or numeric field from a master
 
384
   whose size of the field is less than that of the slave.
 
385
  
 
386
   @param   to         Destination of the data
 
387
   @param   from       Source of the data
 
388
   @param   param_data Precision (upper) and decimal (lower) values
 
389
 
 
390
   @return  New pointer into memory based on from + length of the data
384
391
*/
385
392
const unsigned char *
386
 
Field_decimal::unpack(unsigned char* to,
387
 
                      const unsigned char *from,
388
 
                      uint32_t param_data,
389
 
                      bool low_byte_first)
 
393
Field_new_decimal::unpack(unsigned char* to,
 
394
                          const unsigned char *from,
 
395
                          uint32_t param_data,
 
396
                          bool low_byte_first)
390
397
{
391
398
  if (param_data == 0)
392
399
    return Field::unpack(to, from, param_data, low_byte_first);
396
403
  uint32_t length=pack_length();
397
404
  uint32_t from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal);
398
405
  uint32_t len= (param_data && (from_pack_len < length)) ?
399
 
    from_pack_len : length;
 
406
            from_pack_len : length;
400
407
  if ((from_pack_len && (from_pack_len < length)) ||
401
408
      (from_precision < precision) ||
402
409
      (from_decimal < decimals()))
407
414
      a decimal and write that to the raw data buffer.
408
415
    */
409
416
    decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION];
410
 
    decimal_t conv_dec;
411
 
    conv_dec.len= from_precision;
412
 
    conv_dec.buf= dec_buf;
 
417
    decimal_t dec;
 
418
    dec.len= from_precision;
 
419
    dec.buf= dec_buf;
413
420
    /*
414
 
Note: bin2decimal does not change the length of the field. So it is
415
 
just the first step the resizing operation. The second step does the
416
 
resizing using the precision and decimals from the slave.
 
421
      Note: bin2decimal does not change the length of the field. So it is
 
422
      just the first step the resizing operation. The second step does the
 
423
      resizing using the precision and decimals from the slave.
417
424
    */
418
 
    bin2decimal((unsigned char *)from, &conv_dec, from_precision, from_decimal);
419
 
    decimal2bin(&conv_dec, to, precision, decimals());
 
425
    bin2decimal((unsigned char *)from, &dec, from_precision, from_decimal);
 
426
    decimal2bin(&dec, to, precision, decimals());
420
427
  }
421
428
  else
422
429
    memcpy(to, from, len); // Sizes are the same, just copy the data.
423
430
  return from+len;
424
431
}
425
432
 
426
 
} /* namespace drizzled */