~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/decimal.cc

  • Committer: Brian Aker
  • Date: 2009-03-05 07:54:39 UTC
  • mto: This revision was merged to the branch mainline in revision 911.
  • Revision ID: brian@tangent.org-20090305075439-ubkvoauwj5er551l
Remove some dead bits of string (and fix the semi_join test).

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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <drizzled/charset_info.h>
23
 
#include <drizzled/field.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
24
22
#include <drizzled/item/decimal.h>
25
23
 
26
 
namespace drizzled
27
 
{
28
 
 
29
24
Item_decimal::Item_decimal(const char *str_arg, uint32_t length,
30
25
                           const CHARSET_INFO * const charset)
31
26
{
32
 
  decimal_value.store(E_DEC_FATAL_ERROR, str_arg, length, charset);
 
27
  str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
33
28
  name= (char*) str_arg;
34
29
  decimals= (uint8_t) decimal_value.frac;
35
30
  fixed= 1;
36
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
31
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
37
32
                                             decimals, unsigned_flag);
38
33
}
39
34
 
40
35
Item_decimal::Item_decimal(int64_t val, bool unsig)
41
36
{
42
 
  int2_class_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
 
37
  int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
43
38
  decimals= (uint8_t) decimal_value.frac;
44
39
  fixed= 1;
45
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
40
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
46
41
                                             decimals, unsigned_flag);
47
42
}
48
43
 
49
44
 
50
45
Item_decimal::Item_decimal(double val, int, int)
51
46
{
52
 
  double2_class_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
 
47
  double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
53
48
  decimals= (uint8_t) decimal_value.frac;
54
49
  fixed= 1;
55
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
50
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
56
51
                                             decimals, unsigned_flag);
57
52
}
58
53
 
59
 
Item_decimal::Item_decimal(const char *str, const type::Decimal *val_arg,
 
54
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
60
55
                           uint32_t decimal_par, uint32_t length)
61
56
{
62
 
  class_decimal2decimal(val_arg, &decimal_value);
 
57
  my_decimal2decimal(val_arg, &decimal_value);
63
58
  name= (char*) str;
64
59
  decimals= (uint8_t) decimal_par;
65
60
  max_length= length;
67
62
}
68
63
 
69
64
 
70
 
Item_decimal::Item_decimal(type::Decimal *value_par)
 
65
Item_decimal::Item_decimal(my_decimal *value_par)
71
66
{
72
 
  class_decimal2decimal(value_par, &decimal_value);
 
67
  my_decimal2decimal(value_par, &decimal_value);
73
68
  decimals= (uint8_t) decimal_value.frac;
74
69
  fixed= 1;
75
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
70
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
76
71
                                             decimals, unsigned_flag);
77
72
}
78
73
 
79
74
 
80
75
Item_decimal::Item_decimal(const unsigned char *bin, int precision, int scale)
81
76
{
82
 
  binary2_class_decimal(E_DEC_FATAL_ERROR, bin,
 
77
  binary2my_decimal(E_DEC_FATAL_ERROR, bin,
83
78
                    &decimal_value, precision, scale);
84
79
  decimals= (uint8_t) decimal_value.frac;
85
80
  fixed= 1;
86
 
  max_length= class_decimal_precision_to_length(precision, decimals,
 
81
  max_length= my_decimal_precision_to_length(precision, decimals,
87
82
                                             unsigned_flag);
88
83
}
89
84
 
90
85
int64_t Item_decimal::val_int()
91
86
{
92
87
  int64_t result;
93
 
  decimal_value.val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
 
88
  my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
94
89
  return result;
95
90
}
96
91
 
97
92
double Item_decimal::val_real()
98
93
{
99
94
  double result;
100
 
  class_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
 
95
  my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
101
96
  return result;
102
97
}
103
98
 
104
99
String *Item_decimal::val_str(String *result)
105
100
{
106
101
  result->set_charset(&my_charset_bin);
107
 
  class_decimal2string(&decimal_value, 0, result);
 
102
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
108
103
  return result;
109
104
}
110
105
 
111
106
void Item_decimal::print(String *str, enum_query_type)
112
107
{
113
 
  class_decimal2string(&decimal_value, 0, &str_value);
 
108
  my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
114
109
  str->append(str_value);
115
110
}
116
111
 
125
120
      storage and ignore the argument.
126
121
    */
127
122
    Item *arg= (Item*) item;
128
 
    type::Decimal *value= arg->val_decimal(0);
129
 
    return !class_decimal_cmp(&decimal_value, value);
 
123
    my_decimal *value= arg->val_decimal(0);
 
124
    return !my_decimal_cmp(&decimal_value, value);
130
125
  }
131
126
  return 0;
132
127
}
133
128
 
134
129
 
135
 
void Item_decimal::set_decimal_value(type::Decimal *value_par)
 
130
void Item_decimal::set_decimal_value(my_decimal *value_par)
136
131
{
137
 
  class_decimal2decimal(value_par, &decimal_value);
 
132
  my_decimal2decimal(value_par, &decimal_value);
138
133
  decimals= (uint8_t) decimal_value.frac;
139
134
  unsigned_flag= !decimal_value.sign();
140
 
  max_length= class_decimal_precision_to_length(decimal_value.intg + decimals,
 
135
  max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
141
136
                                             decimals, unsigned_flag);
142
137
}
143
138
 
147
142
  return field->store_decimal(&decimal_value);
148
143
}
149
144
 
150
 
 
151
 
} /* namespace drizzled */