~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

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/blob.h>
24
24
#include <drizzled/table.h>
25
25
#include <drizzled/session.h>
26
 
#include "plugin/myisam/myisam.h"
 
26
#include <plugin/myisam/myisam.h>
 
27
#include <drizzled/system_variables.h>
27
28
 
28
29
#include <string>
29
30
#include <algorithm>
30
31
 
31
32
using namespace std;
32
33
 
33
 
namespace drizzled
34
 
{
 
34
namespace drizzled {
35
35
 
36
36
static uint32_t blob_pack_length_to_max_length(uint32_t arg)
37
37
{
51
51
                       unsigned char null_bit_arg,
52
52
                                   const char *field_name_arg,
53
53
                       TableShare *share,
54
 
                       const CHARSET_INFO * const cs)
 
54
                       const charset_info_st * const cs)
55
55
  :Field_str(ptr_arg,
56
56
             blob_pack_length_to_max_length(sizeof(uint32_t)),
57
57
             null_ptr_arg,
90
90
 
91
91
 
92
92
uint32_t Field_blob::get_length(const unsigned char *pos,
93
 
                                bool low_byte_first)
 
93
                                bool low_byte_first) const
94
94
{
95
95
#ifndef WORDS_BIGENDIAN
96
96
  (void)low_byte_first;
113
113
}
114
114
 
115
115
 
116
 
uint32_t Field_blob::get_length(uint32_t row_offset)
 
116
uint32_t Field_blob::get_length(uint32_t row_offset) const
117
117
{
118
118
  return get_length(ptr+row_offset,
119
119
                    getTable()->getShare()->db_low_byte_first);
120
120
}
121
121
 
122
122
 
123
 
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
 
123
uint32_t Field_blob::get_length(const unsigned char *ptr_arg) const
124
124
{
125
125
  return get_length(ptr_arg, getTable()->getShare()->db_low_byte_first);
126
126
}
141
141
}
142
142
 
143
143
 
144
 
int Field_blob::store(const char *from,uint32_t length, const CHARSET_INFO * const cs)
 
144
int Field_blob::store(const char *from,uint32_t length, const charset_info_st * const cs)
145
145
{
146
146
  uint32_t copy_length, new_length;
147
147
  const char *well_formed_error_pos;
167
167
      memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
168
168
      return 0;
169
169
    }
170
 
    if (tmpstr.copy(from, length, cs))
171
 
      goto oom_error;
 
170
    tmpstr.copy(from, length, cs);
172
171
    from= tmpstr.ptr();
173
172
  }
174
173
 
175
174
  new_length= min(max_data_length(), field_charset->mbmaxlen * length);
176
 
  if (value.alloc(new_length))
177
 
    goto oom_error;
 
175
  value.alloc(new_length);
178
176
 
179
177
  /*
180
178
    "length" is OK as "nchars" argument to well_formed_copy_nchars as this
198
196
    return 2;
199
197
 
200
198
  return report_if_important_data(from_end_pos, from + length);
201
 
 
202
 
oom_error:
203
 
  /* Fatal OOM error */
204
 
  memset(ptr, 0, Field_blob::pack_length());
205
 
  return -1;
206
199
}
207
200
 
208
 
 
209
201
int Field_blob::store(double nr)
210
202
{
211
 
  const CHARSET_INFO * const cs=charset();
 
203
  const charset_info_st * const cs=charset();
212
204
  ASSERT_COLUMN_MARKED_FOR_WRITE;
213
205
  value.set_real(nr, NOT_FIXED_DEC, cs);
214
206
  return Field_blob::store(value.ptr(),(uint32_t) value.length(), cs);
215
207
}
216
208
 
217
 
 
218
209
int Field_blob::store(int64_t nr, bool unsigned_val)
219
210
{
220
 
  const CHARSET_INFO * const cs=charset();
 
211
  const charset_info_st * const cs=charset();
221
212
  ASSERT_COLUMN_MARKED_FOR_WRITE;
222
213
  value.set_int(nr, unsigned_val, cs);
223
214
  return Field_blob::store(value.ptr(), (uint32_t) value.length(), cs);
224
215
}
225
216
 
226
217
 
227
 
double Field_blob::val_real(void)
 
218
double Field_blob::val_real(void) const
228
219
{
229
220
  int not_used;
230
221
  char *end_not_used, *blob;
231
222
  uint32_t length;
232
 
  const CHARSET_INFO *cs;
 
223
  const charset_info_st *cs;
233
224
 
234
225
  ASSERT_COLUMN_MARKED_FOR_READ;
235
226
 
242
233
}
243
234
 
244
235
 
245
 
int64_t Field_blob::val_int(void)
 
236
int64_t Field_blob::val_int(void) const
246
237
{
247
238
  int not_used;
248
239
  char *blob;
252
243
  memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
253
244
  if (!blob)
254
245
    return 0;
255
 
  uint32_t length=get_length(ptr);
 
246
  uint32_t length= get_length(ptr);
256
247
  return my_strntoll(charset(),blob,length,10,NULL,&not_used);
257
248
}
258
249
 
259
 
String *Field_blob::val_str(String *,
260
 
                            String *val_ptr)
 
250
String *Field_blob::val_str(String *, String *val_ptr) const
261
251
{
262
252
  char *blob;
263
253
 
272
262
}
273
263
 
274
264
 
275
 
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value)
 
265
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value) const
276
266
{
277
267
  const char *blob;
278
268
  size_t length;
408
398
  unsigned char *blob1;
409
399
  uint32_t blob_length=get_length(ptr);
410
400
  memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
411
 
  const CHARSET_INFO * const cs= charset();
 
401
  const charset_info_st * const cs= charset();
412
402
  uint32_t local_char_length= max_key_length / cs->mbmaxlen;
413
403
  local_char_length= my_charpos(cs, blob1, blob1+blob_length,
414
404
                                local_char_length);