~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64.cc

  • Committer: Mark Atwood
  • Date: 2011-12-28 02:50:31 UTC
  • Revision ID: me@mark.atwood.name-20111228025031-eh4h1zwv4ig88g0i
fix tests/r/basic.result

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <drizzled/server_includes.h>
23
 
#include <drizzled/field/int64_t.h>
 
22
#include <config.h>
 
23
#include <drizzled/field/int64.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
27
 
 
28
 
#include CMATH_H
29
 
 
30
 
#if defined(CMATH_NAMESPACE)
31
 
using namespace CMATH_NAMESPACE;
32
 
#endif
 
27
#include <drizzled/internal/my_sys.h>
 
28
 
 
29
#include <math.h>
 
30
 
 
31
#include <algorithm>
 
32
 
 
33
using namespace std;
 
34
 
 
35
namespace drizzled {
 
36
namespace field {
33
37
 
34
38
/****************************************************************************
35
 
 Field type int64_t int (8 bytes)
36
 
****************************************************************************/
 
39
  Field type Int64 int (8 bytes)
 
40
 ****************************************************************************/
37
41
 
38
 
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
 
42
int Int64::store(const char *from,uint32_t len, const charset_info_st * const cs)
39
43
{
40
44
  int error= 0;
41
45
  char *end;
42
 
  uint64_t tmp;
43
 
 
44
 
  tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
45
 
  if (error == MY_ERRNO_ERANGE)
 
46
 
 
47
  ASSERT_COLUMN_MARKED_FOR_WRITE;
 
48
 
 
49
  uint64_t tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
 
50
  if (error == ERANGE)
46
51
  {
47
52
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
48
53
    error= 1;
49
54
  }
50
 
  else if (table->in_use->count_cuted_fields && 
51
 
           check_int(cs, from, len, end, error))
 
55
  else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
 
56
  {
52
57
    error= 1;
 
58
  }
53
59
  else
 
60
  {
54
61
    error= 0;
55
 
#ifdef WORDS_BIGENDIAN
56
 
  if (table->s->db_low_byte_first)
57
 
  {
58
 
    int8store(ptr,tmp);
59
62
  }
60
 
  else
61
 
#endif
62
 
    int64_tstore(ptr,tmp);
 
63
 
 
64
  int64_tstore(ptr,tmp);
 
65
 
63
66
  return error;
64
67
}
65
68
 
66
69
 
67
 
int Field_int64_t::store(double nr)
 
70
int Int64::store(double nr)
68
71
{
69
72
  int error= 0;
70
73
  int64_t res;
71
74
 
 
75
  ASSERT_COLUMN_MARKED_FOR_WRITE;
 
76
 
72
77
  nr= rint(nr);
73
78
 
74
79
  if (nr <= (double) INT64_MIN)
82
87
    error= (nr > (double) INT64_MAX);
83
88
  }
84
89
  else
 
90
  {
85
91
    res=(int64_t) nr;
 
92
  }
86
93
 
87
94
  if (error)
88
95
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
89
96
 
90
 
#ifdef WORDS_BIGENDIAN
91
 
  if (table->s->db_low_byte_first)
92
 
  {
93
 
    int8store(ptr,res);
94
 
  }
95
 
  else
96
 
#endif
97
 
    int64_tstore(ptr,res);
 
97
  int64_tstore(ptr, res);
 
98
 
98
99
  return error;
99
100
}
100
101
 
101
102
 
102
 
int Field_int64_t::store(int64_t nr, bool unsigned_val __attribute__((unused)))
 
103
int Int64::store(int64_t nr, bool arg)
103
104
{
104
105
  int error= 0;
105
106
 
106
 
#ifdef WORDS_BIGENDIAN
107
 
  if (table->s->db_low_byte_first)
 
107
  ASSERT_COLUMN_MARKED_FOR_WRITE;
 
108
  if (arg && nr < 0) // Only a partial fix for overflow
108
109
  {
109
 
    int8store(ptr,nr);
 
110
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
111
    error= 1;
110
112
  }
111
 
  else
112
 
#endif
113
 
    int64_tstore(ptr,nr);
 
113
 
 
114
  int64_tstore(ptr,nr);
 
115
 
114
116
  return error;
115
117
}
116
118
 
117
119
 
118
 
double Field_int64_t::val_real(void)
 
120
double Int64::val_real() const
119
121
{
120
122
  int64_t j;
121
 
#ifdef WORDS_BIGENDIAN
122
 
  if (table->s->db_low_byte_first)
123
 
  {
124
 
    j=sint8korr(ptr);
125
 
  }
126
 
  else
127
 
#endif
128
 
    int64_tget(j,ptr);
 
123
 
 
124
  ASSERT_COLUMN_MARKED_FOR_READ;
 
125
 
 
126
  int64_tget(j,ptr);
129
127
  /* The following is open coded to avoid a bug in gcc 3.3 */
 
128
 
130
129
  return (double) j;
131
130
}
132
131
 
133
132
 
134
 
int64_t Field_int64_t::val_int(void)
 
133
int64_t Int64::val_int() const
135
134
{
136
135
  int64_t j;
137
 
#ifdef WORDS_BIGENDIAN
138
 
  if (table->s->db_low_byte_first)
139
 
    j=sint8korr(ptr);
140
 
  else
141
 
#endif
142
 
    int64_tget(j,ptr);
 
136
 
 
137
  ASSERT_COLUMN_MARKED_FOR_READ;
 
138
 
 
139
  int64_tget(j,ptr);
 
140
 
143
141
  return j;
144
142
}
145
143
 
146
144
 
147
 
String *Field_int64_t::val_str(String *val_buffer,
148
 
                                String *val_ptr __attribute__((unused)))
 
145
String *Int64::val_str(String *val_buffer, String *) const
149
146
{
150
 
  const CHARSET_INFO * const cs= &my_charset_bin;
 
147
  const charset_info_st * const cs= &my_charset_bin;
151
148
  uint32_t length;
152
 
  uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
 
149
  uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
153
150
  val_buffer->alloc(mlength);
154
151
  char *to=(char*) val_buffer->ptr();
155
152
  int64_t j;
156
 
#ifdef WORDS_BIGENDIAN
157
 
  if (table->s->db_low_byte_first)
158
 
    j=sint8korr(ptr);
159
 
  else
160
 
#endif
161
 
    int64_tget(j,ptr);
162
 
 
163
 
  length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
 
153
 
 
154
  ASSERT_COLUMN_MARKED_FOR_READ;
 
155
 
 
156
  int64_tget(j,ptr);
 
157
 
 
158
  length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
164
159
  val_buffer->length(length);
165
160
 
166
161
  return val_buffer;
167
162
}
168
163
 
169
 
 
170
 
bool Field_int64_t::send_binary(Protocol *protocol)
171
 
{
172
 
  return protocol->store_int64_t(Field_int64_t::val_int(), false);
173
 
}
174
 
 
175
 
 
176
 
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
 
164
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
177
165
{
178
166
  int64_t a,b;
179
 
#ifdef WORDS_BIGENDIAN
180
 
  if (table->s->db_low_byte_first)
181
 
  {
182
 
    a=sint8korr(a_ptr);
183
 
    b=sint8korr(b_ptr);
184
 
  }
185
 
  else
186
 
#endif
187
 
  {
188
 
    int64_tget(a,a_ptr);
189
 
    int64_tget(b,b_ptr);
190
 
  }
 
167
 
 
168
  int64_tget(a,a_ptr);
 
169
  int64_tget(b,b_ptr);
 
170
 
191
171
  return (a < b) ? -1 : (a > b) ? 1 : 0;
192
172
}
193
173
 
194
 
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
 
174
void Int64::sort_string(unsigned char *to,uint32_t )
195
175
{
196
176
#ifdef WORDS_BIGENDIAN
197
 
  if (!table->s->db_low_byte_first)
198
177
  {
199
178
    to[0] = (char) (ptr[0] ^ 128);              /* Revers signbit */
200
179
    to[1]   = ptr[1];
205
184
    to[6]   = ptr[6];
206
185
    to[7]   = ptr[7];
207
186
  }
208
 
  else
209
 
#endif
 
187
#else
210
188
  {
211
189
    to[0] = (char) (ptr[7] ^ 128);              /* Revers signbit */
212
190
    to[1]   = ptr[6];
217
195
    to[6]   = ptr[1];
218
196
    to[7]   = ptr[0];
219
197
  }
220
 
}
221
 
 
222
 
 
223
 
void Field_int64_t::sql_type(String &res) const
224
 
{
225
 
  const CHARSET_INFO * const cs=res.charset();
226
 
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
227
 
}
228
 
 
229
 
 
230
 
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
231
 
                                         uint32_t,
232
 
#ifdef WORDS_BIGENDIAN
233
 
                                         bool low_byte_first
234
 
#else
235
 
                                         bool
236
198
#endif
237
 
)
 
199
}
 
200
 
 
201
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
238
202
{
239
203
  int64_t val;
240
 
#ifdef WORDS_BIGENDIAN
241
 
  if (table->s->db_low_byte_first)
242
 
     val = sint8korr(from);
243
 
  else
244
 
#endif
245
 
    int64_tget(val, from);
246
 
 
247
 
#ifdef WORDS_BIGENDIAN
248
 
  if (low_byte_first)
249
 
    int8store(to, val);
250
 
  else
251
 
#endif
252
 
    int64_tstore(to, val);
 
204
 
 
205
  int64_tget(val, from);
 
206
  int64_tstore(to, val);
 
207
 
253
208
  return to + sizeof(val);
254
209
}
255
210
 
256
211
 
257
 
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
258
 
#ifdef WORDS_BIGENDIAN
259
 
                                           bool low_byte_first
260
 
#else
261
 
                                           bool
262
 
#endif
263
 
)
 
212
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
264
213
{
265
214
  int64_t val;
266
 
#ifdef WORDS_BIGENDIAN
267
 
  if (low_byte_first)
268
 
    val = sint8korr(from);
269
 
  else
270
 
#endif
271
 
    int64_tget(val, from);
272
 
 
273
 
#ifdef WORDS_BIGENDIAN
274
 
  if (table->s->db_low_byte_first)
275
 
    int8store(to, val);
276
 
  else
277
 
#endif
278
 
    int64_tstore(to, val);
 
215
 
 
216
  int64_tget(val, from);
 
217
  int64_tstore(to, val);
 
218
 
279
219
  return from + sizeof(val);
280
220
}
281
221
 
 
222
} /* namespace field */
 
223
} /* namespace drizzled */