~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/num.cc

  • Committer: Mark Atwood
  • Date: 2011-10-27 05:08:12 UTC
  • mfrom: (2445.1.11 rf)
  • Revision ID: me@mark.atwood.name-20111027050812-1icvs72lb0u4xdc4
mergeĀ lp:~olafvdspek/drizzle/refactor8

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/num.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
27
 
#include "drizzled/internal/my_sys.h"
 
27
#include <drizzled/internal/my_sys.h>
 
28
#include <drizzled/util/test.h>
 
29
#include <drizzled/create_field.h>
28
30
 
29
 
namespace drizzled
30
 
{
 
31
namespace drizzled {
31
32
 
32
33
/**
33
34
  Numeric fields base class constructor.
34
35
*/
35
 
Field_num::Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
36
 
                     unsigned char null_bit_arg, utype unireg_check_arg,
 
36
Field_num::Field_num(unsigned char *ptr_arg,
 
37
                     uint32_t len_arg,
 
38
                     unsigned char *null_ptr_arg,
 
39
                     unsigned char null_bit_arg,
 
40
                     utype unireg_check_arg,
37
41
                     const char *field_name_arg,
38
 
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
39
 
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
40
 
         unireg_check_arg, field_name_arg),
41
 
  dec(dec_arg),decimal_precision(zero_arg), unsigned_flag(unsigned_arg)
42
 
{
 
42
                     uint8_t dec_arg,
 
43
                     bool zero_arg,
 
44
                     bool unsigned_arg) :
 
45
  Field(ptr_arg,
 
46
        len_arg,
 
47
        null_ptr_arg,
 
48
        null_bit_arg,
 
49
        unireg_check_arg,
 
50
        field_name_arg),
 
51
  dec(dec_arg),
 
52
  decimal_precision(zero_arg),
 
53
  unsigned_flag(unsigned_arg)
 
54
  {
43
55
}
44
56
 
45
57
 
65
77
    2   error: garbage at the end of string.
66
78
*/
67
79
 
68
 
int Field_num::check_int(const CHARSET_INFO * const cs, const char *str, int length,
 
80
int Field_num::check_int(const charset_info_st * const cs, const char *str, int length,
69
81
                         const char *int_end, int error)
70
82
{
71
83
  /* Test if we get an empty string or wrong integer */
72
 
  if (str == int_end || error == MY_ERRNO_EDOM)
 
84
  if (str == int_end || error == EDOM)
73
85
  {
74
86
    char buff[128];
75
87
    String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
113
125
    1   error
114
126
*/
115
127
 
116
 
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
 
128
bool Field_num::get_int(const charset_info_st * const cs, const char *from, uint32_t len,
117
129
                        int64_t *rnd, uint64_t ,
118
130
                        int64_t signed_min, int64_t signed_max)
119
131
{
135
147
  if (getTable()->in_use->count_cuted_fields &&
136
148
      check_int(cs, from, len, end, error))
137
149
    return 1;
 
150
 
138
151
  return 0;
139
152
 
140
153
out_of_range:
156
169
    !=0  error
157
170
*/
158
171
 
159
 
int Field_num::store_decimal(const my_decimal *val)
 
172
int Field_num::store_decimal(const type::Decimal *val)
160
173
{
161
174
  int err= 0;
162
175
  int64_t i= convert_decimal2int64_t(val, false, &err);
177
190
    pointer to decimal buffer with value of field
178
191
*/
179
192
 
180
 
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
 
193
type::Decimal* Field_num::val_decimal(type::Decimal *decimal_value) const
181
194
{
182
195
  assert(result_type() == INT_RESULT);
183
196
 
184
197
  int64_t nr= val_int();
185
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, false, decimal_value);
 
198
  int2_class_decimal(E_DEC_FATAL_ERROR, nr, false, decimal_value);
186
199
  return decimal_value;
187
200
}
188
201
 
211
224
uint32_t Field_num::is_equal(CreateField *new_field_ptr)
212
225
{
213
226
  return ((new_field_ptr->sql_type == real_type()) &&
214
 
          ((new_field_ptr->flags & UNSIGNED_FLAG) ==
215
 
           (uint32_t) (flags & UNSIGNED_FLAG)) &&
216
 
          ((new_field_ptr->flags & AUTO_INCREMENT_FLAG) ==
217
 
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
 
227
          ((new_field_ptr->flags & UNSIGNED_FLAG) == (uint32_t) (flags & UNSIGNED_FLAG)) &&
 
228
          ((new_field_ptr->flags & AUTO_INCREMENT_FLAG) == (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
218
229
          (new_field_ptr->length <= max_display_length()));
219
230
}
220
231