~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Brian Aker
  • Date: 2009-02-10 00:14:40 UTC
  • Revision ID: brian@tangent.org-20090210001440-qjg8eofh3h93064b
Adding Multi-threaded Scheduler into the system.

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