~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <drizzled/field/real.h>
48
48
#include <drizzled/field/str.h>
49
49
#include <drizzled/field/varstring.h>
 
50
#include <drizzled/util/test.h>
 
51
#include <drizzled/system_variables.h>
50
52
 
51
 
namespace drizzled
52
 
{
 
53
namespace drizzled {
53
54
 
54
55
static void do_field_eq(CopyField *copy)
55
56
{
344
345
  char buff[MAX_FIELD_WIDTH];
345
346
  copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
346
347
  copy->from_field->val_str_internal(&copy->tmp);
347
 
  copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),
348
 
                        copy->tmp.charset());
 
348
  copy->to_field->store(copy->tmp.data(),copy->tmp.length(), copy->tmp.charset());
349
349
}
350
350
 
351
351
 
386
386
 
387
387
static void do_cut_string(CopyField *copy)
388
388
{
389
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
389
  const charset_info_st * const cs= copy->from_field->charset();
390
390
  memcpy(copy->to_ptr, copy->from_ptr, copy->to_length);
391
391
 
392
392
  /* Check if we loosed any important characters */
409
409
static void do_cut_string_complex(CopyField *copy)
410
410
{                                               // Shorter string field
411
411
  int well_formed_error;
412
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
412
  const charset_info_st * const cs= copy->from_field->charset();
413
413
  const unsigned char *from_end= copy->from_ptr + copy->from_length;
414
 
  uint32_t copy_length= cs->cset->well_formed_len(cs,
415
 
                                              (char*) copy->from_ptr,
416
 
                                              (char*) from_end,
417
 
                                              copy->to_length / cs->mbmaxlen,
418
 
                                              &well_formed_error);
 
414
  uint32_t copy_length= cs->cset->well_formed_len(*cs, str_ref(copy->from_ptr, from_end), copy->to_length / cs->mbmaxlen, &well_formed_error);
419
415
  if (copy->to_length < copy_length)
420
416
    copy_length= copy->to_length;
421
417
  memcpy(copy->to_ptr, copy->from_ptr, copy_length);
440
436
 
441
437
static void do_expand_binary(CopyField *copy)
442
438
{
443
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
439
  const charset_info_st * const cs= copy->from_field->charset();
444
440
  memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
445
441
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
446
442
                 copy->to_length-copy->from_length, '\0');
450
446
 
451
447
static void do_expand_string(CopyField *copy)
452
448
{
453
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
449
  const charset_info_st * const cs= copy->from_field->charset();
454
450
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
455
451
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
456
452
                 copy->to_length-copy->from_length, ' ');
477
473
static void do_varstring1_mb(CopyField *copy)
478
474
{
479
475
  int well_formed_error;
480
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
476
  const charset_info_st * const cs= copy->from_field->charset();
481
477
  uint32_t from_length= (uint32_t) *(unsigned char*) copy->from_ptr;
482
478
  const unsigned char *from_ptr= copy->from_ptr + 1;
483
479
  uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
484
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
485
 
                                         (char*) from_ptr + from_length,
486
 
                                         to_char_length, &well_formed_error);
 
480
  uint32_t length= cs->cset->well_formed_len(*cs, str_ref(from_ptr, from_length), to_char_length, &well_formed_error);
487
481
  if (length < from_length)
488
482
  {
489
483
    if (current_session->count_cuted_fields)
490
484
    {
491
 
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
492
 
                                  ER_WARN_DATA_TRUNCATED, 1);
 
485
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
493
486
    }
494
487
  }
495
488
  *copy->to_ptr= (unsigned char) length;
518
511
static void do_varstring2_mb(CopyField *copy)
519
512
{
520
513
  int well_formed_error;
521
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
514
  const charset_info_st * const cs= copy->from_field->charset();
522
515
  uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
523
516
  uint32_t from_length= uint2korr(copy->from_ptr);
524
517
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
525
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
526
 
                                             (char*) from_beg + from_length,
527
 
                                             char_length, &well_formed_error);
 
518
  uint32_t length= cs->cset->well_formed_len(*cs, str_ref(from_beg, from_length), char_length, &well_formed_error);
528
519
  if (length < from_length)
529
520
  {
530
521
    if (current_session->count_cuted_fields)
856
847
      end with \0. Can be replaced with .ptr() when we have our own
857
848
      string->double conversion.
858
849
    */
859
 
    return to->store(result.c_ptr_quick(),result.length(),from->charset());
 
850
    return to->store(result.c_str(),result.length(),from->charset());
860
851
  }
861
852
  else if (from->result_type() == REAL_RESULT)
862
853
  {