~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Monty Taylor
  • Date: 2009-03-22 07:55:08 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: mordred@inaugust.com-20090322075508-1h34cksq2knhaxc3
Removed global.h from a header.

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