~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/decimal.cc

merged with up to date trunk

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
27
27
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
28
28
                           const CHARSET_INFO * const charset)
29
29
{
30
 
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
 
30
  decimal_value.store(E_DEC_FATAL_ERROR, str_arg, length, charset);
31
31
  name= (char*) str_arg;
32
32
  decimals= (uint8_t) decimal_value.frac;
33
33
  fixed= 1;
34
 
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
 
34
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
35
35
                                             decimals, unsigned_flag);
36
36
}
37
37
 
38
38
Item_decimal::Item_decimal(int64_t val, bool unsig)
39
39
{
40
 
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
 
40
  int2_class_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
41
41
  decimals= (uint8_t) decimal_value.frac;
42
42
  fixed= 1;
43
 
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
 
43
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
44
44
                                             decimals, unsigned_flag);
45
45
}
46
46
 
47
47
 
48
48
Item_decimal::Item_decimal(double val, int, int)
49
49
{
50
 
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
 
50
  double2_class_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
51
51
  decimals= (uint8_t) decimal_value.frac;
52
52
  fixed= 1;
53
 
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
 
53
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
54
54
                                             decimals, unsigned_flag);
55
55
}
56
56
 
57
 
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
 
57
Item_decimal::Item_decimal(const char *str, const type::Decimal *val_arg,
58
58
                           uint32_t decimal_par, uint32_t length)
59
59
{
60
 
  my_decimal2decimal(val_arg, &decimal_value);
 
60
  class_decimal2decimal(val_arg, &decimal_value);
61
61
  name= (char*) str;
62
62
  decimals= (uint8_t) decimal_par;
63
63
  max_length= length;
65
65
}
66
66
 
67
67
 
68
 
Item_decimal::Item_decimal(my_decimal *value_par)
 
68
Item_decimal::Item_decimal(type::Decimal *value_par)
69
69
{
70
 
  my_decimal2decimal(value_par, &decimal_value);
 
70
  class_decimal2decimal(value_par, &decimal_value);
71
71
  decimals= (uint8_t) decimal_value.frac;
72
72
  fixed= 1;
73
 
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
 
73
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
74
74
                                             decimals, unsigned_flag);
75
75
}
76
76
 
77
77
 
78
78
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
79
79
{
80
 
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
 
80
  binary2_class_decimal(E_DEC_FATAL_ERROR, bin,
81
81
                    &decimal_value, precision, scale);
82
82
  decimals= (uint8_t) decimal_value.frac;
83
83
  fixed= 1;
84
 
  max_length= my_decimal_precision_to_length(precision, decimals,
 
84
  max_length= class_decimal_precision_to_length(precision, decimals,
85
85
                                             unsigned_flag);
86
86
}
87
87
 
88
88
int64_t Item_decimal::val_int()
89
89
{
90
90
  int64_t result;
91
 
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
 
91
  decimal_value.val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
92
92
  return result;
93
93
}
94
94
 
95
95
double Item_decimal::val_real()
96
96
{
97
97
  double result;
98
 
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
 
98
  class_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
99
99
  return result;
100
100
}
101
101
 
102
102
String *Item_decimal::val_str(String *result)
103
103
{
104
104
  result->set_charset(&my_charset_bin);
105
 
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
 
105
  class_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
106
106
  return result;
107
107
}
108
108
 
109
109
void Item_decimal::print(String *str, enum_query_type)
110
110
{
111
 
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
 
111
  class_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
112
112
  str->append(str_value);
113
113
}
114
114
 
123
123
      storage and ignore the argument.
124
124
    */
125
125
    Item *arg= (Item*) item;
126
 
    my_decimal *value= arg->val_decimal(0);
127
 
    return !my_decimal_cmp(&decimal_value, value);
 
126
    type::Decimal *value= arg->val_decimal(0);
 
127
    return !class_decimal_cmp(&decimal_value, value);
128
128
  }
129
129
  return 0;
130
130
}
131
131
 
132
132
 
133
 
void Item_decimal::set_decimal_value(my_decimal *value_par)
 
133
void Item_decimal::set_decimal_value(type::Decimal *value_par)
134
134
{
135
 
  my_decimal2decimal(value_par, &decimal_value);
 
135
  class_decimal2decimal(value_par, &decimal_value);
136
136
  decimals= (uint8_t) decimal_value.frac;
137
137
  unsigned_flag= !decimal_value.sign();
138
 
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
 
138
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
139
139
                                             decimals, unsigned_flag);
140
140
}
141
141