~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

Merge Monty - Updates to pandora-build to support features of gcc 4.5.

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>
27
 
#include <drizzled/system_variables.h>
 
26
#include "plugin/myisam/myisam.h"
28
27
 
29
28
#include <string>
30
29
#include <algorithm>
31
30
 
32
31
using namespace std;
33
32
 
34
 
namespace drizzled {
 
33
namespace drizzled
 
34
{
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_st * const cs)
 
54
                       const CHARSET_INFO * 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) const
 
93
                                bool low_byte_first)
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) const
 
116
uint32_t Field_blob::get_length(uint32_t row_offset)
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) const
 
123
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
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_st * const cs)
 
144
int Field_blob::store(const char *from,uint32_t length, const CHARSET_INFO * const cs)
145
145
{
146
146
  uint32_t copy_length, new_length;
147
147
  const char *well_formed_error_pos;
160
160
 
161
161
  if (from == value.ptr())
162
162
  {
163
 
    if (!String::needs_conversion(length, cs, field_charset))
 
163
    size_t dummy_offset;
 
164
    if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
164
165
    {
165
166
      Field_blob::store_length(length);
166
167
      memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
167
168
      return 0;
168
169
    }
169
 
    tmpstr.copy(from, length, cs);
 
170
    if (tmpstr.copy(from, length, cs))
 
171
      goto oom_error;
170
172
    from= tmpstr.ptr();
171
173
  }
172
174
 
173
175
  new_length= min(max_data_length(), field_charset->mbmaxlen * length);
174
 
  value.alloc(new_length);
 
176
  if (value.alloc(new_length))
 
177
    goto oom_error;
175
178
 
176
179
  /*
177
180
    "length" is OK as "nchars" argument to well_formed_copy_nchars as this
195
198
    return 2;
196
199
 
197
200
  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;
198
206
}
199
207
 
 
208
 
200
209
int Field_blob::store(double nr)
201
210
{
202
 
  const charset_info_st * const cs=charset();
 
211
  const CHARSET_INFO * const cs=charset();
203
212
  ASSERT_COLUMN_MARKED_FOR_WRITE;
204
213
  value.set_real(nr, NOT_FIXED_DEC, cs);
205
214
  return Field_blob::store(value.ptr(),(uint32_t) value.length(), cs);
206
215
}
207
216
 
 
217
 
208
218
int Field_blob::store(int64_t nr, bool unsigned_val)
209
219
{
210
 
  const charset_info_st * const cs=charset();
 
220
  const CHARSET_INFO * const cs=charset();
211
221
  ASSERT_COLUMN_MARKED_FOR_WRITE;
212
222
  value.set_int(nr, unsigned_val, cs);
213
223
  return Field_blob::store(value.ptr(), (uint32_t) value.length(), cs);
214
224
}
215
225
 
216
226
 
217
 
double Field_blob::val_real(void) const
 
227
double Field_blob::val_real(void)
218
228
{
219
229
  int not_used;
220
230
  char *end_not_used, *blob;
221
231
  uint32_t length;
222
 
  const charset_info_st *cs;
 
232
  const CHARSET_INFO *cs;
223
233
 
224
234
  ASSERT_COLUMN_MARKED_FOR_READ;
225
235
 
232
242
}
233
243
 
234
244
 
235
 
int64_t Field_blob::val_int(void) const
 
245
int64_t Field_blob::val_int(void)
236
246
{
237
247
  int not_used;
238
248
  char *blob;
242
252
  memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
243
253
  if (!blob)
244
254
    return 0;
245
 
  uint32_t length= get_length(ptr);
 
255
  uint32_t length=get_length(ptr);
246
256
  return my_strntoll(charset(),blob,length,10,NULL,&not_used);
247
257
}
248
258
 
249
 
String *Field_blob::val_str(String *, String *val_ptr) const
 
259
String *Field_blob::val_str(String *,
 
260
                            String *val_ptr)
250
261
{
251
262
  char *blob;
252
263
 
256
267
  if (!blob)
257
268
    val_ptr->set("",0,charset());       // A bit safer than ->length(0)
258
269
  else
259
 
    val_ptr->set(blob,get_length(ptr),charset());
 
270
    val_ptr->set((const char*) blob,get_length(ptr),charset());
260
271
  return val_ptr;
261
272
}
262
273
 
263
274
 
264
 
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value) const
 
275
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value)
265
276
{
266
277
  const char *blob;
267
278
  size_t length;
275
286
    length= 0;
276
287
  }
277
288
  else
278
 
  {
279
289
    length= get_length(ptr);
280
 
  }
281
 
 
282
 
  decimal_value->store(E_DEC_FATAL_ERROR, blob, length, charset());
283
 
 
 
290
 
 
291
  str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(),
 
292
                 decimal_value);
284
293
  return decimal_value;
285
294
}
286
295
 
335
344
uint32_t Field_blob::get_key_image(unsigned char *buff, uint32_t length)
336
345
{
337
346
  uint32_t blob_length= get_length(ptr);
338
 
  unsigned char *blob= get_ptr();
 
347
  unsigned char *blob;
 
348
 
 
349
  get_ptr(&blob);
339
350
  uint32_t local_char_length= length / field_charset->mbmaxlen;
340
351
  local_char_length= my_charpos(field_charset, blob, blob + blob_length,
341
352
                          local_char_length);
355
366
  return HA_KEY_BLOB_LENGTH+length;
356
367
}
357
368
 
 
369
 
358
370
uint32_t Field_blob::get_key_image(basic_string<unsigned char> &buff, uint32_t length)
359
371
{
360
372
  uint32_t blob_length= get_length(ptr);
361
 
  unsigned char* blob= get_ptr();
 
373
  unsigned char *blob;
 
374
 
 
375
  get_ptr(&blob);
362
376
  uint32_t local_char_length= length / field_charset->mbmaxlen;
363
377
  local_char_length= my_charpos(field_charset, blob, blob + blob_length,
364
378
                                local_char_length);
392
406
  unsigned char *blob1;
393
407
  uint32_t blob_length=get_length(ptr);
394
408
  memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
395
 
  const charset_info_st * const cs= charset();
 
409
  const CHARSET_INFO * const cs= charset();
396
410
  uint32_t local_char_length= max_key_length / cs->mbmaxlen;
397
411
  local_char_length= my_charpos(cs, blob1, blob1+blob_length,
398
412
                                local_char_length);
410
424
 
411
425
uint32_t Field_blob::sort_length() const
412
426
{
413
 
  return (uint32_t) (getTable()->getSession()->variables.max_sort_length +
 
427
  return (uint32_t) (current_session->variables.max_sort_length +
414
428
                     (field_charset == &my_charset_bin ? 0 : sizeof(uint32_t)));
415
429
}
416
430
 
437
451
    }
438
452
    memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
439
453
 
440
 
    blob_length= field_charset->strnxfrm(to, length, blob, blob_length);
 
454
    blob_length=my_strnxfrm(field_charset,
 
455
                            to, length, blob, blob_length);
441
456
    assert(blob_length == length);
442
457
  }
443
458
}
447
462
  return (uint32_t) (sizeof(uint32_t) + portable_sizeof_char_ptr);
448
463
}
449
464
 
 
465
void Field_blob::sql_type(String &res) const
 
466
{
 
467
  if (charset() == &my_charset_bin)
 
468
    res.set_ascii(STRING_WITH_LEN("blob"));
 
469
  else
 
470
    res.set_ascii(STRING_WITH_LEN("text"));
 
471
}
 
472
 
450
473
unsigned char *Field_blob::pack(unsigned char *to, const unsigned char *from,
451
474
                                uint32_t max_length, bool low_byte_first)
452
475
{
466
489
   */
467
490
  if (length > 0)
468
491
  {
469
 
    from= get_ptr();
 
492
    get_ptr((unsigned char**) &from);
470
493
    memcpy(to+sizeof(uint32_t), from,length);
471
494
  }
472
495
 
515
538
  uint32_t local_char_length= ((field_charset->mbmaxlen > 1) ?
516
539
                           max_length/field_charset->mbmaxlen : max_length);
517
540
  if (length)
518
 
    from= get_ptr();
 
541
    get_ptr((unsigned char**) &from);
519
542
  if (length > local_char_length)
520
543
    local_char_length= my_charpos(field_charset, from, from+length,
521
544
                                  local_char_length);