~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field/long.cc

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
 
21
#ifdef USE_PRAGMA_IMPLEMENTATION
 
22
#pragma implementation                          // gcc: Class implementation
 
23
#endif
21
24
 
22
 
#include <drizzled/server_includes.h>
23
 
#include <drizzled/field/long.h>
 
25
#include "long.h"
24
26
 
25
27
/****************************************************************************
26
28
** long int
27
29
****************************************************************************/
28
30
 
29
 
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
 
31
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
30
32
{
31
33
  long store_tmp;
32
34
  int error;
33
35
  int64_t rnd;
34
36
  
35
37
  error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
36
 
  store_tmp= (long) rnd;
 
38
  store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
37
39
#ifdef WORDS_BIGENDIAN
38
40
  if (table->s->db_low_byte_first)
39
41
  {
51
53
  int error= 0;
52
54
  int32_t res;
53
55
  nr=rint(nr);
54
 
 
55
 
  if (nr < (double) INT32_MIN)
56
 
  {
57
 
    res=(int32_t) INT32_MIN;
58
 
    error= 1;
59
 
  }
60
 
  else if (nr > (double) INT32_MAX)
61
 
  {
62
 
    res=(int32_t) INT32_MAX;
63
 
    error= 1;
 
56
  if (unsigned_flag)
 
57
  {
 
58
    if (nr < 0)
 
59
    {
 
60
      res=0;
 
61
      error= 1;
 
62
    }
 
63
    else if (nr > (double) UINT32_MAX)
 
64
    {
 
65
      res= INT32_MAX;
 
66
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
67
      error= 1;
 
68
    }
 
69
    else
 
70
      res=(int32_t) (ulong) nr;
64
71
  }
65
72
  else
66
 
    res=(int32_t) (int64_t) nr;
67
 
 
 
73
  {
 
74
    if (nr < (double) INT32_MIN)
 
75
    {
 
76
      res=(int32_t) INT32_MIN;
 
77
      error= 1;
 
78
    }
 
79
    else if (nr > (double) INT32_MAX)
 
80
    {
 
81
      res=(int32_t) INT32_MAX;
 
82
      error= 1;
 
83
    }
 
84
    else
 
85
      res=(int32_t) (int64_t) nr;
 
86
  }
68
87
  if (error)
69
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
88
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
70
89
 
71
90
#ifdef WORDS_BIGENDIAN
72
91
  if (table->s->db_low_byte_first)
85
104
  int error= 0;
86
105
  int32_t res;
87
106
 
88
 
  if (nr < 0 && unsigned_val)
89
 
    nr= ((int64_t) INT32_MAX) + 1;           // Generate overflow
90
 
  if (nr < (int64_t) INT32_MIN) 
91
 
  {
92
 
    res=(int32_t) INT32_MIN;
93
 
    error= 1;
94
 
  }
95
 
  else if (nr > (int64_t) INT32_MAX)
96
 
  {
97
 
    res=(int32_t) INT32_MAX;
98
 
    error= 1;
 
107
  if (unsigned_flag)
 
108
  {
 
109
    if (nr < 0 && !unsigned_val)
 
110
    {
 
111
      res=0;
 
112
      error= 1;
 
113
    }
 
114
    else if ((uint64_t) nr >= (1LL << 32))
 
115
    {
 
116
      res=(int32_t) (uint32_t) ~0L;
 
117
      error= 1;
 
118
    }
 
119
    else
 
120
      res=(int32_t) (uint32_t) nr;
99
121
  }
100
122
  else
101
 
    res=(int32_t) nr;
102
 
 
 
123
  {
 
124
    if (nr < 0 && unsigned_val)
 
125
      nr= ((int64_t) INT32_MAX) + 1;           // Generate overflow
 
126
    if (nr < (int64_t) INT32_MIN) 
 
127
    {
 
128
      res=(int32_t) INT32_MIN;
 
129
      error= 1;
 
130
    }
 
131
    else if (nr > (int64_t) INT32_MAX)
 
132
    {
 
133
      res=(int32_t) INT32_MAX;
 
134
      error= 1;
 
135
    }
 
136
    else
 
137
      res=(int32_t) nr;
 
138
  }
103
139
  if (error)
104
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
140
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
105
141
 
106
142
#ifdef WORDS_BIGENDIAN
107
143
  if (table->s->db_low_byte_first)
124
160
  else
125
161
#endif
126
162
    longget(j,ptr);
127
 
  return (double) j;
 
163
  return unsigned_flag ? (double) (uint32_t) j : (double) j;
128
164
}
129
165
 
130
166
int64_t Field_long::val_int(void)
131
167
{
132
168
  int32_t j;
133
 
  /* See the comment in Field_long::store(int64_t) */
 
169
  /* See the comment in Field_long::store(long long) */
134
170
  assert(table->in_use == current_thd);
135
171
#ifdef WORDS_BIGENDIAN
136
172
  if (table->s->db_low_byte_first)
138
174
  else
139
175
#endif
140
176
    longget(j,ptr);
141
 
  return (int64_t) j;
 
177
  return unsigned_flag ? (int64_t) (uint32_t) j : (int64_t) j;
142
178
}
143
179
 
144
180
String *Field_long::val_str(String *val_buffer,
145
181
                            String *val_ptr __attribute__((unused)))
146
182
{
147
 
  const CHARSET_INFO * const cs= &my_charset_bin;
148
 
  uint32_t length;
149
 
  uint32_t mlength=cmax(field_length+1,12*cs->mbmaxlen);
 
183
  CHARSET_INFO *cs= &my_charset_bin;
 
184
  uint length;
 
185
  uint mlength=max(field_length+1,12*cs->mbmaxlen);
150
186
  val_buffer->alloc(mlength);
151
187
  char *to=(char*) val_buffer->ptr();
152
188
  int32_t j;
157
193
#endif
158
194
    longget(j,ptr);
159
195
 
160
 
  length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
 
196
  if (unsigned_flag)
 
197
    length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32_t)j);
 
198
  else
 
199
    length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
161
200
  val_buffer->length(length);
162
 
 
 
201
  if (zerofill)
 
202
    prepend_zeros(val_buffer);
163
203
  return val_buffer;
164
204
}
165
205
 
169
209
  return protocol->store_long(Field_long::val_int());
170
210
}
171
211
 
172
 
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
 
212
int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr)
173
213
{
174
214
  int32_t a,b;
175
215
#ifdef WORDS_BIGENDIAN
184
224
    longget(a,a_ptr);
185
225
    longget(b,b_ptr);
186
226
  }
187
 
 
 
227
  if (unsigned_flag)
 
228
    return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
188
229
  return (a < b) ? -1 : (a > b) ? 1 : 0;
189
230
}
190
231
 
191
 
void Field_long::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
 
232
void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
192
233
{
193
234
#ifdef WORDS_BIGENDIAN
194
235
  if (!table->s->db_low_byte_first)
195
236
  {
196
 
    to[0] = (char) (ptr[0] ^ 128);              /* Revers signbit */
 
237
    if (unsigned_flag)
 
238
      to[0] = ptr[0];
 
239
    else
 
240
      to[0] = (char) (ptr[0] ^ 128);            /* Revers signbit */
197
241
    to[1]   = ptr[1];
198
242
    to[2]   = ptr[2];
199
243
    to[3]   = ptr[3];
201
245
  else
202
246
#endif
203
247
  {
204
 
    to[0] = (char) (ptr[3] ^ 128);              /* Revers signbit */
 
248
    if (unsigned_flag)
 
249
      to[0] = ptr[3];
 
250
    else
 
251
      to[0] = (char) (ptr[3] ^ 128);            /* Revers signbit */
205
252
    to[1]   = ptr[2];
206
253
    to[2]   = ptr[1];
207
254
    to[3]   = ptr[0];
211
258
 
212
259
void Field_long::sql_type(String &res) const
213
260
{
214
 
  const CHARSET_INFO * const cs=res.charset();
215
 
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
 
261
  CHARSET_INFO *cs=res.charset();
 
262
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
 
263
                          "int(%d)",(int) field_length));
 
264
  add_zerofill_and_unsigned(res);
216
265
}
217
266