~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/decimal.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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