~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Monty Taylor
  • Date: 2010-12-26 03:15:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226031544-1cf3raipu53fnmyj
Through page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
#include "config.h"
28
 
 
29
28
#include <drizzled/error.h>
30
29
#include <drizzled/table.h>
31
30
#include <drizzled/session.h>
32
31
 
33
 
#include <drizzled/copy_field.h>
 
32
#include <drizzled/field/str.h>
 
33
#include <drizzled/field/num.h>
34
34
#include <drizzled/field/blob.h>
 
35
#include <drizzled/field/enum.h>
 
36
#include <drizzled/field/null.h>
35
37
#include <drizzled/field/date.h>
36
 
#include <drizzled/field/datetime.h>
37
38
#include <drizzled/field/decimal.h>
 
39
#include <drizzled/field/real.h>
38
40
#include <drizzled/field/double.h>
39
 
#include <drizzled/field/enum.h>
40
 
#include <drizzled/field/epoch.h>
41
41
#include <drizzled/field/int32.h>
42
42
#include <drizzled/field/int64.h>
43
 
#include <drizzled/field/null.h>
44
 
#include <drizzled/field/num.h>
45
 
#include <drizzled/field/num.h>
46
 
#include <drizzled/field/real.h>
47
 
#include <drizzled/field/str.h>
 
43
#include <drizzled/field/num.h>
 
44
#include <drizzled/field/epoch.h>
 
45
#include <drizzled/field/datetime.h>
48
46
#include <drizzled/field/varstring.h>
49
47
 
50
48
namespace drizzled
191
189
    when set to NULL (TIMESTAMP fields which allow setting to NULL
192
190
    are handled by first check).
193
191
  */
194
 
  if (field->is_timestamp())
 
192
  if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
195
193
  {
196
194
    ((field::Epoch::pointer) field)->set_time();
197
195
    return 0;                                   // Ok to set time to NULL
373
371
 
374
372
static void do_field_decimal(CopyField *copy)
375
373
{
376
 
  type::Decimal value;
 
374
  my_decimal value;
377
375
  copy->to_field->store_decimal(copy->from_field->val_decimal(&value));
378
376
}
379
377
 
386
384
static void do_cut_string(CopyField *copy)
387
385
{
388
386
  const CHARSET_INFO * const cs= copy->from_field->charset();
389
 
  memcpy(copy->to_ptr, copy->from_ptr, copy->to_length);
 
387
  memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
390
388
 
391
389
  /* Check if we loosed any important characters */
392
390
  if (cs->cset->scan(cs,
463
461
  {
464
462
    length= copy->to_length - 1;
465
463
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
466
 
    {
467
464
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
468
465
                                  ER_WARN_DATA_TRUNCATED, 1);
469
 
    }
470
466
  }
471
467
  *(unsigned char*) copy->to_ptr= (unsigned char) length;
472
468
  memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
486
482
  if (length < from_length)
487
483
  {
488
484
    if (current_session->count_cuted_fields)
489
 
    {
490
485
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
491
486
                                  ER_WARN_DATA_TRUNCATED, 1);
492
 
    }
493
487
  }
494
488
  *copy->to_ptr= (unsigned char) length;
495
489
  memcpy(copy->to_ptr + 1, from_ptr, length);
503
497
  {
504
498
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
505
499
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
506
 
    {
507
500
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
501
                                  ER_WARN_DATA_TRUNCATED, 1);
509
 
    }
510
502
  }
511
503
  int2store(copy->to_ptr,length);
512
504
  memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, copy->from_ptr + HA_KEY_BLOB_LENGTH,
527
519
  if (length < from_length)
528
520
  {
529
521
    if (current_session->count_cuted_fields)
530
 
    {
531
522
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
532
523
                                  ER_WARN_DATA_TRUNCATED, 1);
533
 
    }
534
524
  }
535
525
  int2store(copy->to_ptr, length);
536
526
  memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
630
620
    }
631
621
    else
632
622
    {
633
 
      if (to_field->is_timestamp())
 
623
      if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
634
624
      {
635
625
        do_copy= do_copy_timestamp;               // Automatic timestamp
636
626
      }
674
664
    if (from_length != to_length || !compatible_db_low_byte_first)
675
665
    {
676
666
      // Correct pointer to point at char pointer
677
 
      to_ptr+= to_length - to->getTable()->getShare()->sizeBlobPtr();
678
 
      from_ptr+= from_length- from->getTable()->getShare()->sizeBlobPtr();
 
667
      to_ptr+= to_length - to->getTable()->getShare()->blob_ptr_size;
 
668
      from_ptr+= from_length- from->getTable()->getShare()->blob_ptr_size;
679
669
      return do_copy_blob;
680
670
    }
681
671
  }
858
848
    return to->store(result.c_ptr_quick(),result.length(),from->charset());
859
849
  }
860
850
  else if (from->result_type() == REAL_RESULT)
861
 
  {
862
851
    return to->store(from->val_real());
863
 
  }
864
852
  else if (from->result_type() == DECIMAL_RESULT)
865
853
  {
866
 
    type::Decimal buff;
 
854
    my_decimal buff;
867
855
    return to->store_decimal(from->val_decimal(&buff));
868
856
  }
869
857
  else
870
 
  {
871
858
    return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
872
 
  }
873
859
}
874
860
 
875
861
} /* namespace drizzled */