~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64.cc

merged with up to date trunk

Show diffs side-by-side

added added

removed removed

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