~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int64_t.cc

  • Committer: Brian Aker
  • Date: 2009-11-11 15:49:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1212.
  • Revision ID: brian@gaz-20091111154959-jqu64e48gp9ig3tp
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
for protobuf to correctly store DECIMAL

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