~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Brian Aker
  • Date: 2009-01-07 21:26:58 UTC
  • Revision ID: brian@tangent.org-20090107212658-2fh0s2uwh10w68y2
Committing fix lock_multi

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