~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/num.cc

code clean move Item_func_num1 and Item_func_connection_id to functions directory

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.
38
32
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
39
33
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
40
34
         unireg_check_arg, field_name_arg),
41
 
  dec(dec_arg),decimal_precision(zero_arg), unsigned_flag(unsigned_arg)
 
35
  dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
42
36
{
 
37
  if (unsigned_flag)
 
38
    flags|=UNSIGNED_FLAG;
43
39
}
44
40
 
45
41
 
74
70
    char buff[128];
75
71
    String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
76
72
    tmp.copy(str, length, system_charset_info);
77
 
    push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
73
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
78
74
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
79
75
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
80
76
                        "integer", tmp.c_ptr(), field_name,
81
 
                        (uint32_t) getTable()->in_use->row_count);
 
77
                        (uint32_t) table->in_use->row_count);
82
78
    return 1;
83
79
  }
84
80
  /* Test if we have garbage at the end of the given string. */
114
110
*/
115
111
 
116
112
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
117
 
                        int64_t *rnd, uint64_t ,
 
113
                        int64_t *rnd, uint64_t unsigned_max,
118
114
                        int64_t signed_min, int64_t signed_max)
119
115
{
120
116
  char *end;
121
117
  int error;
122
118
 
123
 
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len, false, &end, &error);
124
 
  if (*rnd < signed_min)
125
 
  {
126
 
    *rnd= signed_min;
127
 
    goto out_of_range;
128
 
  }
129
 
  else if (*rnd > signed_max)
130
 
  {
131
 
    *rnd= signed_max;
132
 
    goto out_of_range;
133
 
  }
 
119
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
 
120
                                            unsigned_flag, &end,
 
121
                                            &error);
 
122
  if (unsigned_flag)
 
123
  {
134
124
 
135
 
  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 &&
136
145
      check_int(cs, from, len, end, error))
137
146
    return 1;
138
147
  return 0;
142
151
  return 1;
143
152
}
144
153
 
 
154
void Field_num::add_unsigned(String &res) const
 
155
{
 
156
  if (unsigned_flag)
 
157
    res.append(STRING_WITH_LEN(" unsigned"));
 
158
}
 
159
 
145
160
/**
146
161
  Storing decimal in integer fields.
147
162
 
159
174
int Field_num::store_decimal(const my_decimal *val)
160
175
{
161
176
  int err= 0;
162
 
  int64_t i= convert_decimal2int64_t(val, false, &err);
163
 
  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));
164
179
}
165
180
 
166
181
/**
180
195
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
181
196
{
182
197
  assert(result_type() == INT_RESULT);
183
 
 
184
198
  int64_t nr= val_int();
185
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, false, decimal_value);
 
199
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
186
200
  return decimal_value;
187
201
}
188
202
 
189
203
 
190
 
void Field_num::make_field(SendField *field)
 
204
void Field_num::make_field(Send_field *field)
191
205
{
192
206
  Field::make_field(field);
193
207
  field->decimals= dec;
203
217
    return 0;
204
218
  Field_num *from_num= (Field_num*) field;
205
219
 
206
 
  if (dec != from_num->dec)
 
220
  if (unsigned_flag != from_num->unsigned_flag ||
 
221
      dec != from_num->dec)
207
222
    return 0;
208
223
  return 1;
209
224
}
210
225
 
211
 
uint32_t Field_num::is_equal(CreateField *new_field_ptr)
 
226
uint32_t Field_num::is_equal(Create_field *new_field)
212
227
{
213
 
  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) ==
 
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) ==
217
232
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
218
 
          (new_field_ptr->length <= max_display_length()));
 
233
          (new_field->length <= max_display_length()));
219
234
}
220
235
 
221
236
 
222
 
} /* namespace drizzled */