~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/decimal.cc

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <config.h>
 
22
#include "config.h"
23
23
#include <drizzled/field/decimal.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
28
28
namespace drizzled
29
29
{
30
30
 
 
31
extern type::Decimal decimal_zero;
 
32
 
31
33
/****************************************************************************
32
34
 ** File_decimal
33
35
 ****************************************************************************/
38
40
                             unsigned char null_bit_arg,
39
41
                             enum utype unireg_check_arg,
40
42
                             const char *field_name_arg,
41
 
                             uint8_t dec_arg) :
42
 
  Field_num(ptr_arg,
43
 
            len_arg,
44
 
            null_ptr_arg,
45
 
            null_bit_arg,
46
 
            unireg_check_arg,
47
 
            field_name_arg,
48
 
            dec_arg, false,
49
 
            false)
50
 
  {
51
 
    precision= class_decimal_length_to_precision(len_arg, dec_arg, false);
52
 
    set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
53
 
    assert((precision <= DECIMAL_MAX_PRECISION) && (dec <= DECIMAL_MAX_SCALE));
54
 
    bin_size= class_decimal_get_binary_size(precision, dec);
55
 
  }
 
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= class_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= class_decimal_get_binary_size(precision, dec);
 
60
}
56
61
 
57
62
Field_decimal::Field_decimal(uint32_t len_arg,
58
63
                             bool maybe_null_arg,
59
64
                             const char *name,
60
65
                             uint8_t dec_arg,
61
 
                             bool unsigned_arg) :
62
 
  Field_num((unsigned char*) 0,
63
 
            len_arg,
64
 
            maybe_null_arg ? (unsigned char*) "": 0,
65
 
            0,
66
 
            NONE,
67
 
            name,
68
 
            dec_arg,
69
 
            0,
70
 
            unsigned_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)
71
76
{
72
77
  precision= class_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
73
78
  set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
147
152
  if ((err= decimal_value.store(E_DEC_FATAL_ERROR &
148
153
                           ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
149
154
                           from, length, charset_arg)) &&
150
 
      getTable()->in_use->abortOnWarning())
 
155
      getTable()->in_use->abort_on_warning)
151
156
  {
152
157
    /* Because "from" is not NUL-terminated and we use %s in the ER() */
153
158
    String from_as_str;
252
257
}
253
258
 
254
259
 
255
 
int Field_decimal::store_time(type::Time &ltime,
256
 
                              type::timestamp_t )
 
260
int Field_decimal::store_time(type::Time *ltime,
 
261
                              enum enum_drizzle_timestamp_type )
257
262
{
258
263
  type::Decimal decimal_value;
259
 
  return store_value(date2_class_decimal(&ltime, &decimal_value));
 
264
  return store_value(date2_class_decimal(ltime, &decimal_value));
260
265
}
261
266
 
262
267
 
263
 
double Field_decimal::val_real(void) const
 
268
double Field_decimal::val_real(void)
264
269
{
265
270
  double dbl;
266
271
  type::Decimal decimal_value;
273
278
}
274
279
 
275
280
 
276
 
int64_t Field_decimal::val_int(void) const
 
281
int64_t Field_decimal::val_int(void)
277
282
{
278
283
  int64_t i;
279
284
  type::Decimal decimal_value;
286
291
}
287
292
 
288
293
 
289
 
type::Decimal* Field_decimal::val_decimal(type::Decimal *decimal_value) const
 
294
type::Decimal* Field_decimal::val_decimal(type::Decimal *decimal_value)
290
295
{
291
296
  ASSERT_COLUMN_MARKED_FOR_READ;
292
297
 
296
301
}
297
302
 
298
303
 
299
 
String *Field_decimal::val_str(String *val_buffer, String *) const
 
304
String *Field_decimal::val_str(String *val_buffer,
 
305
                               String *)
300
306
{
301
307
  type::Decimal decimal_value;
302
308
 
303
309
  ASSERT_COLUMN_MARKED_FOR_READ;
304
310
 
305
 
  class_decimal2string(val_decimal(&decimal_value),
306
 
                       dec, val_buffer);
 
311
  uint32_t fixed_precision= decimal_precision ? precision : 0;
 
312
  class_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
 
313
                    fixed_precision, dec, '0', val_buffer);
307
314
  return val_buffer;
308
315
}
309
316