~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 09:12:23 UTC
  • mto: (511.1.6 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016091223-17ngih0qu9vssjs3
We pass -Wunused-macros now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
 
22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/int64_t.h>
24
 
#include <drizzled/error.h>
25
 
#include <drizzled/table.h>
26
 
#include <drizzled/session.h>
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
 
{
37
24
 
38
25
/****************************************************************************
39
26
 Field type int64_t int (8 bytes)
45
32
  char *end;
46
33
  uint64_t tmp;
47
34
 
48
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
49
 
 
50
35
  tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
51
36
  if (error == MY_ERRNO_ERANGE)
52
37
  {
53
38
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
54
39
    error= 1;
55
40
  }
56
 
  else if (getTable()->in_use->count_cuted_fields &&
 
41
  else if (table->in_use->count_cuted_fields && 
57
42
           check_int(cs, from, len, end, error))
58
43
    error= 1;
59
44
  else
60
45
    error= 0;
61
46
#ifdef WORDS_BIGENDIAN
62
 
  if (getTable()->s->db_low_byte_first)
 
47
  if (table->s->db_low_byte_first)
63
48
  {
64
49
    int8store(ptr,tmp);
65
50
  }
75
60
  int error= 0;
76
61
  int64_t res;
77
62
 
78
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
79
 
 
80
63
  nr= rint(nr);
81
64
 
82
65
  if (nr <= (double) INT64_MIN)
96
79
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
97
80
 
98
81
#ifdef WORDS_BIGENDIAN
99
 
  if (getTable()->s->db_low_byte_first)
 
82
  if (table->s->db_low_byte_first)
100
83
  {
101
84
    int8store(ptr,res);
102
85
  }
107
90
}
108
91
 
109
92
 
110
 
int Field_int64_t::store(int64_t nr, bool )
 
93
int Field_int64_t::store(int64_t nr, bool unsigned_val __attribute__((unused)))
111
94
{
112
95
  int error= 0;
113
96
 
114
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
115
 
 
116
97
#ifdef WORDS_BIGENDIAN
117
 
  if (getTable()->s->db_low_byte_first)
 
98
  if (table->s->db_low_byte_first)
118
99
  {
119
100
    int8store(ptr,nr);
120
101
  }
128
109
double Field_int64_t::val_real(void)
129
110
{
130
111
  int64_t j;
131
 
 
132
 
  ASSERT_COLUMN_MARKED_FOR_READ;
133
 
 
134
112
#ifdef WORDS_BIGENDIAN
135
 
  if (getTable()->s->db_low_byte_first)
 
113
  if (table->s->db_low_byte_first)
136
114
  {
137
115
    j=sint8korr(ptr);
138
116
  }
147
125
int64_t Field_int64_t::val_int(void)
148
126
{
149
127
  int64_t j;
150
 
 
151
 
  ASSERT_COLUMN_MARKED_FOR_READ;
152
 
 
153
128
#ifdef WORDS_BIGENDIAN
154
 
  if (getTable()->s->db_low_byte_first)
 
129
  if (table->s->db_low_byte_first)
155
130
    j=sint8korr(ptr);
156
131
  else
157
132
#endif
161
136
 
162
137
 
163
138
String *Field_int64_t::val_str(String *val_buffer,
164
 
                                String *)
 
139
                                String *val_ptr __attribute__((unused)))
165
140
{
166
141
  const CHARSET_INFO * const cs= &my_charset_bin;
167
142
  uint32_t length;
168
 
  uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
 
143
  uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
169
144
  val_buffer->alloc(mlength);
170
145
  char *to=(char*) val_buffer->ptr();
171
146
  int64_t j;
172
 
 
173
 
  ASSERT_COLUMN_MARKED_FOR_READ;
174
 
 
175
147
#ifdef WORDS_BIGENDIAN
176
 
  if (getTable()->s->db_low_byte_first)
 
148
  if (table->s->db_low_byte_first)
177
149
    j=sint8korr(ptr);
178
150
  else
179
151
#endif
180
152
    int64_tget(j,ptr);
181
153
 
182
 
  length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
 
154
  length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
183
155
  val_buffer->length(length);
184
156
 
185
157
  return val_buffer;
186
158
}
187
159
 
 
160
 
 
161
bool Field_int64_t::send_binary(Protocol *protocol)
 
162
{
 
163
  return protocol->store_int64_t(Field_int64_t::val_int(), false);
 
164
}
 
165
 
 
166
 
188
167
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
189
168
{
190
169
  int64_t a,b;
191
170
#ifdef WORDS_BIGENDIAN
192
 
  if (getTable()->s->db_low_byte_first)
 
171
  if (table->s->db_low_byte_first)
193
172
  {
194
173
    a=sint8korr(a_ptr);
195
174
    b=sint8korr(b_ptr);
203
182
  return (a < b) ? -1 : (a > b) ? 1 : 0;
204
183
}
205
184
 
206
 
void Field_int64_t::sort_string(unsigned char *to,uint32_t )
 
185
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
207
186
{
208
187
#ifdef WORDS_BIGENDIAN
209
 
  if (!getTable()->s->db_low_byte_first)
 
188
  if (!table->s->db_low_byte_first)
210
189
  {
211
190
    to[0] = (char) (ptr[0] ^ 128);              /* Revers signbit */
212
191
    to[1]   = ptr[1];
237
216
  const CHARSET_INFO * const cs=res.charset();
238
217
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
239
218
}
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
248
 
#endif
249
 
)
250
 
{
251
 
  int64_t val;
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);
265
 
  return to + sizeof(val);
266
 
}
267
 
 
268
 
 
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
 
)
276
 
{
277
 
  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()->s->db_low_byte_first)
287
 
    int8store(to, val);
288
 
  else
289
 
#endif
290
 
    int64_tstore(to, val);
291
 
  return from + sizeof(val);
292
 
}
293
 
 
294
 
} /* namespace drizzled */