~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/decimal.cc

  • Committer: lbieber
  • Date: 2010-10-01 13:06:31 UTC
  • mfrom: (1802.2.2 drizzle-bug-651948)
  • mto: This revision was merged to the branch mainline in revision 1805.
  • Revision ID: lbieber@orisndriz08-20101001130631-xubscnhmj7r5dn6g
Merge Andrew - Fix bug 651948 - Index lengths not retrieved using drizzledump

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
19
19
 
20
20
#include "config.h"
21
21
 
22
 
#include <drizzled/charset_info.h>
23
 
#include <drizzled/field.h>
24
22
#include <drizzled/item/decimal.h>
25
23
 
26
24
namespace drizzled
29
27
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
30
28
                           const CHARSET_INFO * const charset)
31
29
{
32
 
  decimal_value.store(E_DEC_FATAL_ERROR, str_arg, length, charset);
 
30
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
33
31
  name= (char*) str_arg;
34
32
  decimals= (uint8_t) decimal_value.frac;
35
33
  fixed= 1;
36
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
34
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
37
35
                                             decimals, unsigned_flag);
38
36
}
39
37
 
40
38
Item_decimal::Item_decimal(int64_t val, bool unsig)
41
39
{
42
 
  int2_class_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
 
40
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
43
41
  decimals= (uint8_t) decimal_value.frac;
44
42
  fixed= 1;
45
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
43
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
46
44
                                             decimals, unsigned_flag);
47
45
}
48
46
 
49
47
 
50
48
Item_decimal::Item_decimal(double val, int, int)
51
49
{
52
 
  double2_class_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
 
50
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
53
51
  decimals= (uint8_t) decimal_value.frac;
54
52
  fixed= 1;
55
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
53
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
56
54
                                             decimals, unsigned_flag);
57
55
}
58
56
 
59
 
Item_decimal::Item_decimal(const char *str, const type::Decimal *val_arg,
 
57
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
60
58
                           uint32_t decimal_par, uint32_t length)
61
59
{
62
 
  class_decimal2decimal(val_arg, &decimal_value);
 
60
  my_decimal2decimal(val_arg, &decimal_value);
63
61
  name= (char*) str;
64
62
  decimals= (uint8_t) decimal_par;
65
63
  max_length= length;
67
65
}
68
66
 
69
67
 
70
 
Item_decimal::Item_decimal(type::Decimal *value_par)
 
68
Item_decimal::Item_decimal(my_decimal *value_par)
71
69
{
72
 
  class_decimal2decimal(value_par, &decimal_value);
 
70
  my_decimal2decimal(value_par, &decimal_value);
73
71
  decimals= (uint8_t) decimal_value.frac;
74
72
  fixed= 1;
75
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
73
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
76
74
                                             decimals, unsigned_flag);
77
75
}
78
76
 
79
77
 
80
78
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
81
79
{
82
 
  binary2_class_decimal(E_DEC_FATAL_ERROR, bin,
 
80
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
83
81
                    &decimal_value, precision, scale);
84
82
  decimals= (uint8_t) decimal_value.frac;
85
83
  fixed= 1;
86
 
  max_length= class_decimal_precision_to_length(precision, decimals,
 
84
  max_length= my_decimal_precision_to_length(precision, decimals,
87
85
                                             unsigned_flag);
88
86
}
89
87
 
90
88
int64_t Item_decimal::val_int()
91
89
{
92
90
  int64_t result;
93
 
  decimal_value.val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
 
91
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
94
92
  return result;
95
93
}
96
94
 
97
95
double Item_decimal::val_real()
98
96
{
99
97
  double result;
100
 
  class_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
 
98
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
101
99
  return result;
102
100
}
103
101
 
104
102
String *Item_decimal::val_str(String *result)
105
103
{
106
104
  result->set_charset(&my_charset_bin);
107
 
  class_decimal2string(&decimal_value, 0, result);
 
105
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
108
106
  return result;
109
107
}
110
108
 
111
109
void Item_decimal::print(String *str, enum_query_type)
112
110
{
113
 
  class_decimal2string(&decimal_value, 0, &str_value);
 
111
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
114
112
  str->append(str_value);
115
113
}
116
114
 
125
123
      storage and ignore the argument.
126
124
    */
127
125
    Item *arg= (Item*) item;
128
 
    type::Decimal *value= arg->val_decimal(0);
129
 
    return !class_decimal_cmp(&decimal_value, value);
 
126
    my_decimal *value= arg->val_decimal(0);
 
127
    return !my_decimal_cmp(&decimal_value, value);
130
128
  }
131
129
  return 0;
132
130
}
133
131
 
134
132
 
135
 
void Item_decimal::set_decimal_value(type::Decimal *value_par)
 
133
void Item_decimal::set_decimal_value(my_decimal *value_par)
136
134
{
137
 
  class_decimal2decimal(value_par, &decimal_value);
 
135
  my_decimal2decimal(value_par, &decimal_value);
138
136
  decimals= (uint8_t) decimal_value.frac;
139
137
  unsigned_flag= !decimal_value.sign();
140
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
138
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
141
139
                                             decimals, unsigned_flag);
142
140
}
143
141