~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

Merging with main Drizzle tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
{
86
86
  if (*copy->from_null_ptr & copy->from_bit)
87
87
  {
88
 
    bzero(copy->to_ptr,copy->from_length);
 
88
    memset(copy->to_ptr, 0, copy->from_length);
89
89
    copy->to_null_ptr[0]=1;                     // Always bit 1
90
90
  }
91
91
  else
101
101
  if (*copy->null_row ||
102
102
      (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
103
103
  {
104
 
    bzero(copy->to_ptr,copy->from_length);
 
104
    memset(copy->to_ptr, 0, copy->from_length);
105
105
    copy->to_null_ptr[0]=1;                     // Always bit 1
106
106
  }
107
107
  else
167
167
    when set to NULL (TIMESTAMP fields which allow setting to NULL
168
168
    are handled by first check).
169
169
  */
170
 
  if (field->type() == MYSQL_TYPE_TIMESTAMP)
 
170
  if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
171
171
  {
172
172
    ((Field_timestamp*) field)->set_time();
173
173
    return 0;                                   // Ok to set time to NULL
275
275
{
276
276
  ulong length=((Field_blob*) copy->from_field)->get_length();
277
277
  ((Field_blob*) copy->to_field)->store_length(length);
278
 
  memcpy_fixed(copy->to_ptr,copy->from_ptr,sizeof(char*));
 
278
  memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
279
279
}
280
280
 
281
281
static void do_conv_blob(Copy_field *copy)
563
563
 */
564
564
void Copy_field::set(Field *to,Field *from,bool save)
565
565
{
566
 
  if (to->type() == MYSQL_TYPE_NULL)
 
566
  if (to->type() == DRIZZLE_TYPE_NULL)
567
567
  {
568
568
    to_null_ptr=0;                              // For easy debugging
569
569
    to_ptr=0;
597
597
    }
598
598
    else
599
599
    {
600
 
      if (to_field->type() == MYSQL_TYPE_TIMESTAMP)
 
600
      if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
601
601
        do_copy= do_copy_timestamp;               // Automatic timestamp
602
602
      else if (to_field == to_field->table->next_number_field)
603
603
        do_copy= do_copy_next_number;
652
652
        use special copy function that removes trailing spaces and thus
653
653
        repairs data.
654
654
      */
655
 
      if (from->type() == MYSQL_TYPE_VAR_STRING && !from->has_charset() &&
656
 
          to->type() == MYSQL_TYPE_VARCHAR && !to->has_charset())
 
655
      if (from->type() == DRIZZLE_TYPE_VAR_STRING && !from->has_charset() &&
 
656
          to->type() == DRIZZLE_TYPE_VARCHAR && !to->has_charset())
657
657
        return do_field_varbinary_pre50;
658
658
 
659
659
      /*
662
662
      */
663
663
      if (to->real_type() != from->real_type() ||
664
664
          !compatible_db_low_byte_first ||
665
 
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == MYSQL_TYPE_NEWDATE) || to->type() == MYSQL_TYPE_DATETIME))
 
665
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_NEWDATE) || to->type() == DRIZZLE_TYPE_DATETIME))
666
666
      {
667
 
        if (from->real_type() == MYSQL_TYPE_ENUM ||
668
 
            from->real_type() == MYSQL_TYPE_SET)
 
667
        if (from->real_type() == DRIZZLE_TYPE_ENUM ||
 
668
            from->real_type() == DRIZZLE_TYPE_SET)
669
669
          if (to->result_type() != STRING_RESULT)
670
670
            return do_field_int;                // Convert SET to number
671
671
        return do_field_string;
672
672
      }
673
 
      if (to->real_type() == MYSQL_TYPE_ENUM ||
674
 
          to->real_type() == MYSQL_TYPE_SET)
 
673
      if (to->real_type() == DRIZZLE_TYPE_ENUM ||
 
674
          to->real_type() == DRIZZLE_TYPE_SET)
675
675
      {
676
676
        if (!to->eq_def(from))
677
677
        {
678
 
          if (from->real_type() == MYSQL_TYPE_ENUM &&
679
 
              to->real_type() == MYSQL_TYPE_ENUM)
 
678
          if (from->real_type() == DRIZZLE_TYPE_ENUM &&
 
679
              to->real_type() == DRIZZLE_TYPE_ENUM)
680
680
            return do_field_enum;
681
681
          else
682
682
            return do_field_string;
684
684
      }
685
685
      else if (to->charset() != from->charset())
686
686
        return do_field_string;
687
 
      else if (to->real_type() == MYSQL_TYPE_VARCHAR)
 
687
      else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
688
688
      {
689
689
        if (((Field_varstring*) to)->length_bytes !=
690
690
            ((Field_varstring*) from)->length_bytes)
747
747
int field_conv(Field *to,Field *from)
748
748
{
749
749
  if (to->real_type() == from->real_type() &&
750
 
      !(to->type() == MYSQL_TYPE_BLOB && to->table->copy_blobs))
 
750
      !(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
751
751
  {
752
752
    /* Please god, will someone rewrite this to be readable :( */
753
753
    if (to->pack_length() == from->pack_length() && 
754
754
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && 
755
 
        to->real_type() != MYSQL_TYPE_ENUM && 
756
 
        to->real_type() != MYSQL_TYPE_SET &&
757
 
        (to->real_type() != MYSQL_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
 
755
        to->real_type() != DRIZZLE_TYPE_ENUM && 
 
756
        to->real_type() != DRIZZLE_TYPE_SET &&
 
757
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
758
758
        from->charset() == to->charset() &&
759
759
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
760
 
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != MYSQL_TYPE_NEWDATE && to->type() != MYSQL_TYPE_DATETIME)) && 
761
 
        (from->real_type() != MYSQL_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
 
760
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_NEWDATE && to->type() != DRIZZLE_TYPE_DATETIME)) && 
 
761
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
762
762
    {                                           // Identical fields
763
763
#ifdef HAVE_purify
764
764
      /* This may happen if one does 'UPDATE ... SET x=x' */
768
768
      return 0;
769
769
    }
770
770
  }
771
 
  if (to->type() == MYSQL_TYPE_BLOB)
 
771
  if (to->type() == DRIZZLE_TYPE_BLOB)
772
772
  {                                             // Be sure the value is stored
773
773
    Field_blob *blob=(Field_blob*) to;
774
774
    from->val_str(&blob->value);
778
778
    */
779
779
    if (to->table->copy_blobs ||
780
780
        (!blob->value.is_alloced() &&
781
 
         from->real_type() != MYSQL_TYPE_STRING &&
782
 
         from->real_type() != MYSQL_TYPE_VARCHAR))
 
781
         from->real_type() != DRIZZLE_TYPE_STRING &&
 
782
         from->real_type() != DRIZZLE_TYPE_VARCHAR))
783
783
      blob->value.copy();
784
784
    return blob->store(blob->value.ptr(),blob->value.length(),from->charset());
785
785
  }
786
 
  if (from->real_type() == MYSQL_TYPE_ENUM &&
787
 
      to->real_type() == MYSQL_TYPE_ENUM &&
 
786
  if (from->real_type() == DRIZZLE_TYPE_ENUM &&
 
787
      to->real_type() == DRIZZLE_TYPE_ENUM &&
788
788
      from->val_int() == 0)
789
789
  {
790
790
    ((Field_enum *)(to))->store_type(0);
792
792
  }
793
793
  else if ((from->result_type() == STRING_RESULT &&
794
794
            (to->result_type() == STRING_RESULT ||
795
 
             (from->real_type() != MYSQL_TYPE_ENUM &&
796
 
              from->real_type() != MYSQL_TYPE_SET))))
 
795
             (from->real_type() != DRIZZLE_TYPE_ENUM &&
 
796
              from->real_type() != DRIZZLE_TYPE_SET))))
797
797
  {
798
798
    char buff[MAX_FIELD_WIDTH];
799
799
    String result(buff,sizeof(buff),from->charset());