~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Stewart Smith
  • Date: 2010-02-22 07:44:37 UTC
  • mfrom: (1283.17.4)
  • mto: (1283.19.1)
  • mto: This revision was merged to the branch mainline in revision 1449.
  • Revision ID: stewart@flamingspork.com-20100222074437-1a9x1n030tbtv1qv
Merged embeddded-innodb-store-table-proto into embedded-innodb-write-row.

Show diffs side-by-side

added added

removed removed

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