~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Monty Taylor
  • Date: 2010-06-02 22:35:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: mordred@inaugust.com-20100602223545-q8ekf9b40a85nwuf
Rearragned unittests into a single exe because of how we need to link it
(thanks lifeless)
Link with server symbols without needing to build a library.
Added an additional atomics test which tests whatever version of the atomics
lib the running platform would actually use.

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 &&
 
56
  else if (table->in_use->count_cuted_fields &&
60
57
           check_int(cs, from, len, end, error))
61
58
    error= 1;
62
59
  else
63
60
    error= 0;
64
61
#ifdef WORDS_BIGENDIAN
65
 
  if (getTable()->getShare()->db_low_byte_first)
 
62
  if (table->s->db_low_byte_first)
66
63
  {
67
64
    int8store(ptr,tmp);
68
65
  }
73
70
}
74
71
 
75
72
 
76
 
int Int64::store(double nr)
 
73
int Field_int64_t::store(double nr)
77
74
{
78
75
  int error= 0;
79
76
  int64_t res;
99
96
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
100
97
 
101
98
#ifdef WORDS_BIGENDIAN
102
 
  if (getTable()->getShare()->db_low_byte_first)
 
99
  if (table->s->db_low_byte_first)
103
100
  {
104
101
    int8store(ptr,res);
105
102
  }
110
107
}
111
108
 
112
109
 
113
 
int Int64::store(int64_t nr, bool )
 
110
int Field_int64_t::store(int64_t nr, bool )
114
111
{
115
112
  int error= 0;
116
113
 
117
114
  ASSERT_COLUMN_MARKED_FOR_WRITE;
118
115
 
119
116
#ifdef WORDS_BIGENDIAN
120
 
  if (getTable()->getShare()->db_low_byte_first)
 
117
  if (table->s->db_low_byte_first)
121
118
  {
122
119
    int8store(ptr,nr);
123
120
  }
128
125
}
129
126
 
130
127
 
131
 
double Int64::val_real(void)
 
128
double Field_int64_t::val_real(void)
132
129
{
133
130
  int64_t j;
134
131
 
135
132
  ASSERT_COLUMN_MARKED_FOR_READ;
136
133
 
137
134
#ifdef WORDS_BIGENDIAN
138
 
  if (getTable()->getShare()->db_low_byte_first)
 
135
  if (table->s->db_low_byte_first)
139
136
  {
140
137
    j=sint8korr(ptr);
141
138
  }
147
144
}
148
145
 
149
146
 
150
 
int64_t Int64::val_int(void)
 
147
int64_t Field_int64_t::val_int(void)
151
148
{
152
149
  int64_t j;
153
150
 
154
151
  ASSERT_COLUMN_MARKED_FOR_READ;
155
152
 
156
153
#ifdef WORDS_BIGENDIAN
157
 
  if (getTable()->getShare()->db_low_byte_first)
 
154
  if (table->s->db_low_byte_first)
158
155
    j=sint8korr(ptr);
159
156
  else
160
157
#endif
163
160
}
164
161
 
165
162
 
166
 
String *Int64::val_str(String *val_buffer,
167
 
                       String *)
 
163
String *Field_int64_t::val_str(String *val_buffer,
 
164
                                String *)
168
165
{
169
166
  const CHARSET_INFO * const cs= &my_charset_bin;
170
167
  uint32_t length;
176
173
  ASSERT_COLUMN_MARKED_FOR_READ;
177
174
 
178
175
#ifdef WORDS_BIGENDIAN
179
 
  if (getTable()->getShare()->db_low_byte_first)
 
176
  if (table->s->db_low_byte_first)
180
177
    j=sint8korr(ptr);
181
178
  else
182
179
#endif
188
185
  return val_buffer;
189
186
}
190
187
 
191
 
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)
192
189
{
193
190
  int64_t a,b;
194
191
#ifdef WORDS_BIGENDIAN
195
 
  if (getTable()->getShare()->db_low_byte_first)
 
192
  if (table->s->db_low_byte_first)
196
193
  {
197
194
    a=sint8korr(a_ptr);
198
195
    b=sint8korr(b_ptr);
206
203
  return (a < b) ? -1 : (a > b) ? 1 : 0;
207
204
}
208
205
 
209
 
void Int64::sort_string(unsigned char *to,uint32_t )
 
206
void Field_int64_t::sort_string(unsigned char *to,uint32_t )
210
207
{
211
208
#ifdef WORDS_BIGENDIAN
212
 
  if (!getTable()->getShare()->db_low_byte_first)
 
209
  if (!table->s->db_low_byte_first)
213
210
  {
214
211
    to[0] = (char) (ptr[0] ^ 128);              /* Revers signbit */
215
212
    to[1]   = ptr[1];
235
232
}
236
233
 
237
234
 
238
 
void Int64::sql_type(String &res) const
 
235
void Field_int64_t::sql_type(String &res) const
239
236
{
240
237
  const CHARSET_INFO * const cs=res.charset();
241
238
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
242
239
}
243
240
 
244
241
 
245
 
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from,
246
 
                           uint32_t,
 
242
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
 
243
                                         uint32_t,
247
244
#ifdef WORDS_BIGENDIAN
248
 
                           bool low_byte_first
 
245
                                         bool low_byte_first
249
246
#else
250
 
                           bool
 
247
                                         bool
251
248
#endif
252
 
                          )
 
249
)
253
250
{
254
251
  int64_t val;
255
252
#ifdef WORDS_BIGENDIAN
256
 
  if (getTable()->getShare()->db_low_byte_first)
257
 
    val = sint8korr(from);
 
253
  if (table->s->db_low_byte_first)
 
254
     val = sint8korr(from);
258
255
  else
259
256
#endif
260
257
    int64_tget(val, from);
269
266
}
270
267
 
271
268
 
272
 
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t,
 
269
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
273
270
#ifdef WORDS_BIGENDIAN
274
 
                                   bool low_byte_first
 
271
                                           bool low_byte_first
275
272
#else
276
 
                                   bool
 
273
                                           bool
277
274
#endif
278
 
                                  )
 
275
)
279
276
{
280
277
  int64_t val;
281
278
#ifdef WORDS_BIGENDIAN
286
283
    int64_tget(val, from);
287
284
 
288
285
#ifdef WORDS_BIGENDIAN
289
 
  if (getTable()->getShare()->db_low_byte_first)
 
286
  if (table->s->db_low_byte_first)
290
287
    int8store(to, val);
291
288
  else
292
289
#endif
294
291
  return from + sizeof(val);
295
292
}
296
293
 
297
 
} /* namespace field */
298
294
} /* namespace drizzled */