~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64.cc

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

Show diffs side-by-side

added added

removed removed

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