~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/int32.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 10:14:05 UTC
  • mfrom: (2008.1.3 clean)
  • Revision ID: brian@tangent.org-20101218101405-qjbse29shi9coklg
Merge of user identifier work

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/int32.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
51
51
 
52
52
    error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
53
53
    store_tmp= (long) rnd;
54
 
    longstore(ptr, store_tmp);
55
 
 
 
54
#ifdef WORDS_BIGENDIAN
 
55
    if (getTable()->getShare()->db_low_byte_first)
 
56
    {
 
57
      int4store(ptr, store_tmp);
 
58
    }
 
59
    else
 
60
#endif
 
61
      longstore(ptr, store_tmp);
56
62
    return error;
57
63
  }
58
64
 
81
87
    if (error)
82
88
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
83
89
 
84
 
    longstore(ptr,res);
85
 
 
 
90
#ifdef WORDS_BIGENDIAN
 
91
    if (getTable()->getShare()->db_low_byte_first)
 
92
    {
 
93
      int4store(ptr,res);
 
94
    }
 
95
    else
 
96
#endif
 
97
      longstore(ptr,res);
86
98
    return error;
87
99
  }
88
100
 
96
108
 
97
109
    if (nr < 0 && unsigned_val)
98
110
      nr= ((int64_t) INT32_MAX) + 1;           // Generate overflow
99
 
 
100
111
    if (nr < (int64_t) INT32_MIN)
101
112
    {
102
113
      res=(int32_t) INT32_MIN;
108
119
      error= 1;
109
120
    }
110
121
    else
111
 
    {
112
122
      res=(int32_t) nr;
113
 
    }
114
123
 
115
124
    if (error)
116
125
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
117
126
 
118
 
    longstore(ptr,res);
119
 
 
 
127
#ifdef WORDS_BIGENDIAN
 
128
    if (getTable()->getShare()->db_low_byte_first)
 
129
    {
 
130
      int4store(ptr,res);
 
131
    }
 
132
    else
 
133
#endif
 
134
      longstore(ptr,res);
120
135
    return error;
121
136
  }
122
137
 
123
138
 
124
 
  double Int32::val_real(void) const
 
139
  double Int32::val_real(void)
125
140
  {
126
141
    int32_t j;
127
142
 
128
143
    ASSERT_COLUMN_MARKED_FOR_READ;
129
144
 
130
 
    longget(j,ptr);
131
 
 
 
145
#ifdef WORDS_BIGENDIAN
 
146
    if (getTable()->getShare()->db_low_byte_first)
 
147
      j=sint4korr(ptr);
 
148
    else
 
149
#endif
 
150
      longget(j,ptr);
132
151
    return (double) j;
133
152
  }
134
153
 
135
 
  int64_t Int32::val_int(void) const
 
154
  int64_t Int32::val_int(void)
136
155
  {
137
156
    int32_t j;
138
157
 
139
158
    ASSERT_COLUMN_MARKED_FOR_READ;
140
159
 
141
 
    longget(j,ptr);
142
 
 
 
160
    /* See the comment in Int32::store(int64_t) */
 
161
#ifdef WORDS_BIGENDIAN
 
162
    if (getTable()->getShare()->db_low_byte_first)
 
163
      j=sint4korr(ptr);
 
164
    else
 
165
#endif
 
166
      longget(j,ptr);
143
167
    return (int64_t) j;
144
168
  }
145
169
 
146
 
  String *Int32::val_str(String *val_buffer, String *) const
 
170
  String *Int32::val_str(String *val_buffer,
 
171
                         String *)
147
172
  {
148
173
    const CHARSET_INFO * const cs= &my_charset_bin;
149
174
    uint32_t length;
154
179
 
155
180
    ASSERT_COLUMN_MARKED_FOR_READ;
156
181
 
157
 
    longget(j,ptr);
 
182
#ifdef WORDS_BIGENDIAN
 
183
    if (getTable()->getShare()->db_low_byte_first)
 
184
      j=sint4korr(ptr);
 
185
    else
 
186
#endif
 
187
      longget(j,ptr);
158
188
 
159
189
    length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
160
190
    val_buffer->length(length);
165
195
  int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
166
196
  {
167
197
    int32_t a,b;
168
 
 
169
 
    longget(a,a_ptr);
170
 
    longget(b,b_ptr);
 
198
#ifdef WORDS_BIGENDIAN
 
199
    if (getTable()->getShare()->db_low_byte_first)
 
200
    {
 
201
      a=sint4korr(a_ptr);
 
202
      b=sint4korr(b_ptr);
 
203
    }
 
204
    else
 
205
#endif
 
206
    {
 
207
      longget(a,a_ptr);
 
208
      longget(b,b_ptr);
 
209
    }
171
210
 
172
211
    return (a < b) ? -1 : (a > b) ? 1 : 0;
173
212
  }
175
214
  void Int32::sort_string(unsigned char *to,uint32_t )
176
215
  {
177
216
#ifdef WORDS_BIGENDIAN
 
217
    if (!getTable()->getShare()->db_low_byte_first)
178
218
    {
179
219
      to[0] = (char) (ptr[0] ^ 128);            /* Revers signbit */
180
220
      to[1]   = ptr[1];
181
221
      to[2]   = ptr[2];
182
222
      to[3]   = ptr[3];
183
223
    }
184
 
#else
 
224
    else
 
225
#endif
185
226
    {
186
227
      to[0] = (char) (ptr[3] ^ 128);            /* Revers signbit */
187
228
      to[1]   = ptr[2];
188
229
      to[2]   = ptr[1];
189
230
      to[3]   = ptr[0];
190
231
    }
191
 
#endif
192
232
  }
193
233
 
194
234
 
198
238
    res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
199
239
  }
200
240
 
201
 
  unsigned char *Int32::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
 
241
  unsigned char *Int32::pack(unsigned char* to, const unsigned char *from,
 
242
                             uint32_t,
 
243
#ifdef WORDS_BIGENDIAN
 
244
                             bool low_byte_first
 
245
#else
 
246
                             bool
 
247
#endif
 
248
                            )
202
249
  {
203
250
    int32_t val;
204
 
    longget(val, from);
 
251
#ifdef WORDS_BIGENDIAN
 
252
    if (getTable()->getShare()->db_low_byte_first)
 
253
      val = sint4korr(from);
 
254
    else
 
255
#endif
 
256
      longget(val, from);
205
257
 
206
 
    longstore(to, val);
 
258
#ifdef WORDS_BIGENDIAN
 
259
    if (low_byte_first)
 
260
      int4store(to, val);
 
261
    else
 
262
#endif
 
263
      longstore(to, val);
207
264
    return to + sizeof(val);
208
265
  }
209
266
 
210
267
 
211
 
  const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
 
268
  const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t,
 
269
#ifdef WORDS_BIGENDIAN
 
270
                                     bool low_byte_first
 
271
#else
 
272
                                     bool
 
273
#endif
 
274
                                    )
212
275
  {
213
276
    int32_t val;
214
 
    longget(val, from);
215
 
 
216
 
    longstore(to, val);
217
 
 
 
277
#ifdef WORDS_BIGENDIAN
 
278
    if (low_byte_first)
 
279
      val = sint4korr(from);
 
280
    else
 
281
#endif
 
282
      longget(val, from);
 
283
 
 
284
#ifdef WORDS_BIGENDIAN
 
285
    if (getTable()->getShare()->db_low_byte_first)
 
286
      int4store(to, val);
 
287
    else
 
288
#endif
 
289
      longstore(to, val);
218
290
    return from + sizeof(val);
219
291
  }
220
292