~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Patrick Crews
  • Date: 2010-09-14 20:21:03 UTC
  • mto: (1771.1.1 pcrews)
  • mto: This revision was merged to the branch mainline in revision 1772.
  • Revision ID: gleebix@gmail.com-20100914202103-1db2n0bshzafep19
Moved transaction_log tests into updated non-publisher-based tree

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