~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/num.cc

  • Committer: Monty Taylor
  • Date: 2008-10-08 01:10:45 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: monty@inaugust.com-20081008011045-zqozbc81f8qhmxok
Get rid of pragma interface/pragma implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <config.h>
 
22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/num.h>
24
 
#include <drizzled/error.h>
25
 
#include <drizzled/table.h>
26
 
#include <drizzled/session.h>
27
 
#include <drizzled/internal/my_sys.h>
28
 
 
29
 
namespace drizzled
30
 
{
 
24
#include <drizzled/drizzled_error_messages.h>
31
25
 
32
26
/**
33
27
  Numeric fields base class constructor.
34
28
*/
35
 
Field_num::Field_num(unsigned char *ptr_arg,
36
 
                     uint32_t len_arg,
37
 
                     unsigned char *null_ptr_arg,
38
 
                     unsigned char null_bit_arg,
39
 
                     utype unireg_check_arg,
 
29
Field_num::Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
 
30
                     unsigned char null_bit_arg, utype unireg_check_arg,
40
31
                     const char *field_name_arg,
41
 
                     uint8_t dec_arg,
42
 
                     bool zero_arg,
43
 
                     bool unsigned_arg) :
44
 
  Field(ptr_arg,
45
 
        len_arg,
46
 
        null_ptr_arg,
47
 
        null_bit_arg,
48
 
        unireg_check_arg,
49
 
        field_name_arg),
50
 
  dec(dec_arg),
51
 
  decimal_precision(zero_arg),
52
 
  unsigned_flag(unsigned_arg)
53
 
  {
 
32
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
 
33
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
34
         unireg_check_arg, field_name_arg),
 
35
  dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
 
36
{
 
37
  if (unsigned_flag)
 
38
    flags|=UNSIGNED_FLAG;
54
39
}
55
40
 
56
41
 
85
70
    char buff[128];
86
71
    String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
87
72
    tmp.copy(str, length, system_charset_info);
88
 
    push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
73
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
89
74
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
90
75
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
91
76
                        "integer", tmp.c_ptr(), field_name,
92
 
                        (uint32_t) getTable()->in_use->row_count);
 
77
                        (uint32_t) table->in_use->row_count);
93
78
    return 1;
94
79
  }
95
80
  /* Test if we have garbage at the end of the given string. */
125
110
*/
126
111
 
127
112
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
128
 
                        int64_t *rnd, uint64_t ,
 
113
                        int64_t *rnd, uint64_t unsigned_max,
129
114
                        int64_t signed_min, int64_t signed_max)
130
115
{
131
116
  char *end;
132
117
  int error;
133
118
 
134
 
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len, false, &end, &error);
135
 
  if (*rnd < signed_min)
136
 
  {
137
 
    *rnd= signed_min;
138
 
    goto out_of_range;
139
 
  }
140
 
  else if (*rnd > signed_max)
141
 
  {
142
 
    *rnd= signed_max;
143
 
    goto out_of_range;
144
 
  }
 
119
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
 
120
                                            unsigned_flag, &end,
 
121
                                            &error);
 
122
  if (unsigned_flag)
 
123
  {
145
124
 
146
 
  if (getTable()->in_use->count_cuted_fields &&
 
125
    if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
 
126
        error == MY_ERRNO_ERANGE)
 
127
    {
 
128
      goto out_of_range;
 
129
    }
 
130
  }
 
131
  else
 
132
  {
 
133
    if (*rnd < signed_min)
 
134
    {
 
135
      *rnd= signed_min;
 
136
      goto out_of_range;
 
137
    }
 
138
    else if (*rnd > signed_max)
 
139
    {
 
140
      *rnd= signed_max;
 
141
      goto out_of_range;
 
142
    }
 
143
  }
 
144
  if (table->in_use->count_cuted_fields &&
147
145
      check_int(cs, from, len, end, error))
148
146
    return 1;
149
 
 
150
147
  return 0;
151
148
 
152
149
out_of_range:
154
151
  return 1;
155
152
}
156
153
 
 
154
void Field_num::add_unsigned(String &res) const
 
155
{
 
156
  if (unsigned_flag)
 
157
    res.append(STRING_WITH_LEN(" unsigned"));
 
158
}
 
159
 
157
160
/**
158
161
  Storing decimal in integer fields.
159
162
 
168
171
    !=0  error
169
172
*/
170
173
 
171
 
int Field_num::store_decimal(const type::Decimal *val)
 
174
int Field_num::store_decimal(const my_decimal *val)
172
175
{
173
176
  int err= 0;
174
 
  int64_t i= convert_decimal2int64_t(val, false, &err);
175
 
  return test(err | store(i, false));
 
177
  int64_t i= convert_decimal2int64_t(val, unsigned_flag, &err);
 
178
  return test(err | store(i, unsigned_flag));
176
179
}
177
180
 
178
181
/**
189
192
    pointer to decimal buffer with value of field
190
193
*/
191
194
 
192
 
type::Decimal* Field_num::val_decimal(type::Decimal *decimal_value) const
 
195
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
193
196
{
194
197
  assert(result_type() == INT_RESULT);
195
 
 
196
198
  int64_t nr= val_int();
197
 
  int2_class_decimal(E_DEC_FATAL_ERROR, nr, false, decimal_value);
 
199
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
198
200
  return decimal_value;
199
201
}
200
202
 
201
203
 
202
 
void Field_num::make_field(SendField *field)
 
204
void Field_num::make_field(Send_field *field)
203
205
{
204
206
  Field::make_field(field);
205
207
  field->decimals= dec;
215
217
    return 0;
216
218
  Field_num *from_num= (Field_num*) field;
217
219
 
218
 
  if (dec != from_num->dec)
 
220
  if (unsigned_flag != from_num->unsigned_flag ||
 
221
      dec != from_num->dec)
219
222
    return 0;
220
223
  return 1;
221
224
}
222
225
 
223
 
uint32_t Field_num::is_equal(CreateField *new_field_ptr)
 
226
uint32_t Field_num::is_equal(Create_field *new_field)
224
227
{
225
 
  return ((new_field_ptr->sql_type == real_type()) &&
226
 
          ((new_field_ptr->flags & UNSIGNED_FLAG) ==
227
 
           (uint32_t) (flags & UNSIGNED_FLAG)) &&
228
 
          ((new_field_ptr->flags & AUTO_INCREMENT_FLAG) ==
 
228
  return ((new_field->sql_type == real_type()) &&
 
229
          ((new_field->flags & UNSIGNED_FLAG) == (uint32_t) (flags &
 
230
                                                         UNSIGNED_FLAG)) &&
 
231
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
229
232
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
230
 
          (new_field_ptr->length <= max_display_length()));
 
233
          (new_field->length <= max_display_length()));
231
234
}
232
235
 
233
236
 
234
 
} /* namespace drizzled */