~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Monty Taylor
  • Date: 2010-11-25 01:53:19 UTC
  • mto: (1953.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: mordred@inaugust.com-20101125015319-ia85msn25uemopgc
Re-enabled -Wformat and then cleaned up the carnage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <drizzled/field/decimal.h>
39
39
#include <drizzled/field/real.h>
40
40
#include <drizzled/field/double.h>
41
 
#include <drizzled/field/int32.h>
42
 
#include <drizzled/field/int64.h>
 
41
#include <drizzled/field/long.h>
 
42
#include <drizzled/field/int64_t.h>
43
43
#include <drizzled/field/num.h>
44
44
#include <drizzled/field/timestamp.h>
45
45
#include <drizzled/field/datetime.h>
248
248
 
249
249
static void do_copy_not_null(CopyField *copy)
250
250
{
251
 
  if (copy->to_field->hasDefault() and *copy->from_null_ptr & copy->from_bit)
252
 
  {
253
 
    copy->to_field->set_default();
254
 
  }
255
 
  else if (*copy->from_null_ptr & copy->from_bit)
 
251
  if (*copy->from_null_ptr & copy->from_bit)
256
252
  {
257
253
    copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
258
254
                                ER_WARN_DATA_TRUNCATED, 1);
259
255
    copy->to_field->reset();
260
256
  }
261
257
  else
262
 
  {
263
258
    (copy->do_copy2)(copy);
264
 
  }
265
259
}
266
260
 
267
261
 
307
301
 
308
302
static void do_conv_blob(CopyField *copy)
309
303
{
310
 
  copy->from_field->val_str_internal(&copy->tmp);
 
304
  copy->from_field->val_str(&copy->tmp);
311
305
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
312
306
                                         copy->tmp.length(),
313
307
                                         copy->tmp.charset());
319
313
{
320
314
  char buff[MAX_FIELD_WIDTH];
321
315
  String res(buff, sizeof(buff), copy->tmp.charset());
322
 
  copy->from_field->val_str_internal(&res);
 
316
  copy->from_field->val_str(&res);
323
317
  copy->tmp.copy(res);
324
318
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
325
319
                                         copy->tmp.length(),
331
325
{
332
326
  char buff[MAX_FIELD_WIDTH];
333
327
  copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
334
 
  copy->from_field->val_str_internal(&copy->tmp);
 
328
  copy->from_field->val_str(&copy->tmp);
335
329
  copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),
336
330
                        copy->tmp.charset());
337
331
}
600
594
      to_null_ptr= to->null_ptr;
601
595
      to_bit= to->null_bit;
602
596
      if (from_null_ptr)
603
 
      {
604
597
        do_copy= do_copy_null;
605
 
      }
606
598
      else
607
599
      {
608
600
        null_row= &from->getTable()->null_row;
612
604
    else
613
605
    {
614
606
      if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
615
 
      {
616
607
        do_copy= do_copy_timestamp;               // Automatic timestamp
617
 
      }
618
608
      else if (to_field == to_field->getTable()->next_number_field)
619
 
      {
620
609
        do_copy= do_copy_next_number;
621
 
      }
622
610
      else
623
 
      {
624
611
        do_copy= do_copy_not_null;
625
 
      }
626
612
    }
627
613
  }
628
614
  else if (to_field->real_maybe_null())
682
668
          {
683
669
            return do_field_int;  // Convert SET to number
684
670
          }
685
 
 
 
671
          
686
672
          return do_field_string;
687
673
        }
688
674
      }
689
 
 
 
675
      
690
676
      if (to->real_type() == DRIZZLE_TYPE_ENUM)
691
677
      {
692
678
        if (!to->eq_def(from))
703
689
      else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
704
690
      {
705
691
        /* Field_blob is not part of the Field_varstring hierarchy,
706
 
          and casting to varstring for calling pack_length_no_ptr()
707
 
          is always incorrect. Previously the below comparison has
708
 
          always evaluated to false as pack_length_no_ptr() for BLOB
709
 
          will return 4 and varstring can only be <= 2.
710
 
          If your brain slightly bleeds as to why this worked for
711
 
          so many years, you are in no way alone.
 
692
           and casting to varstring for calling pack_length_no_ptr()
 
693
           is always incorrect. Previously the below comparison has
 
694
           always evaluated to false as pack_length_no_ptr() for BLOB
 
695
           will return 4 and varstring can only be <= 2.
 
696
           If your brain slightly bleeds as to why this worked for
 
697
           so many years, you are in no way alone.
712
698
        */
713
699
        if (from->flags & BLOB_FLAG)
714
700
          return do_field_string;
718
704
        {
719
705
          return do_field_string;
720
706
        }
721
 
 
 
707
        
722
708
        if (to_length != from_length)
723
709
        {
724
710
          return (((Field_varstring*) to)->pack_length_no_ptr() == 1 ?
725
711
                  (from->charset()->mbmaxlen == 1 ? do_varstring1 :
726
 
                   do_varstring1_mb) :
 
712
                                                    do_varstring1_mb) :
727
713
                  (from->charset()->mbmaxlen == 1 ? do_varstring2 :
728
 
                   do_varstring2_mb));
 
714
                                                    do_varstring2_mb));
729
715
        }
730
716
      }
731
717
      else if (to_length < from_length)
805
791
  if (to->type() == DRIZZLE_TYPE_BLOB)
806
792
  {                                             // Be sure the value is stored
807
793
    Field_blob *blob=(Field_blob*) to;
808
 
    from->val_str_internal(&blob->value);
 
794
    from->val_str(&blob->value);
809
795
    /*
810
796
      Copy value if copy_blobs is set, or source is not a string and
811
797
      we have a pointer to its internal string conversion buffer.
829
815
  {
830
816
    char buff[MAX_FIELD_WIDTH];
831
817
    String result(buff,sizeof(buff),from->charset());
832
 
    from->val_str_internal(&result);
 
818
    from->val_str(&result);
833
819
    /*
834
820
      We use c_ptr_quick() here to make it easier if to is a float/double
835
821
      as the conversion routines will do a copy of the result doesn't