~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Andrew Hutchings
  • Date: 2010-11-01 22:14:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1907.
  • Revision ID: andrew@linuxjedi.co.uk-20101101221418-9n9gmm4ms7fl8vo5
Fix copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
 
17
17
/**
143
143
    return 0;
144
144
  }
145
145
  field->reset();
146
 
  if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
 
146
  if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN)
147
147
  {
148
148
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
149
149
    return 0;
150
150
  }
151
 
  if (!field->table->in_use->no_errors)
 
151
  if (!field->getTable()->in_use->no_errors)
152
152
    my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
153
153
  return -1;
154
154
}
194
194
    return 0;                                   // Ok to set time to NULL
195
195
  }
196
196
  field->reset();
197
 
  if (field == field->table->next_number_field)
 
197
  if (field == field->getTable()->next_number_field)
198
198
  {
199
 
    field->table->auto_increment_field_not_null= false;
 
199
    field->getTable()->auto_increment_field_not_null= false;
200
200
    return 0;                             // field is set in fill_record()
201
201
  }
202
 
  if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
 
202
  if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN)
203
203
  {
204
204
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
205
205
    return 0;
206
206
  }
207
 
  if (!field->table->in_use->no_errors)
 
207
  if (!field->getTable()->in_use->no_errors)
208
208
    my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
209
209
  return -1;
210
210
}
284
284
  if (*copy->from_null_ptr & copy->from_bit)
285
285
  {
286
286
    /* Same as in set_field_to_null_with_conversions() */
287
 
    copy->to_field->table->auto_increment_field_not_null= false;
 
287
    copy->to_field->getTable()->auto_increment_field_not_null= false;
288
288
    copy->to_field->reset();
289
289
  }
290
290
  else
445
445
  if (length > copy->to_length- 1)
446
446
  {
447
447
    length= copy->to_length - 1;
448
 
    if (copy->from_field->table->in_use->count_cuted_fields)
 
448
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
449
449
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
450
                                  ER_WARN_DATA_TRUNCATED, 1);
451
451
  }
481
481
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
482
482
  {
483
483
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
484
 
    if (copy->from_field->table->in_use->count_cuted_fields)
 
484
    if (copy->from_field->getTable()->in_use->count_cuted_fields)
485
485
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
486
486
                                  ER_WARN_DATA_TRUNCATED, 1);
487
487
  }
536
536
    to_ptr[0]= 1;                             // Null as default value
537
537
    to_null_ptr= (unsigned char*) to_ptr++;
538
538
    to_bit= 1;
539
 
    if (from->table->maybe_null)
 
539
    if (from->getTable()->maybe_null)
540
540
    {
541
 
      null_row= &from->table->null_row;
 
541
      null_row= &from->getTable()->null_row;
542
542
      do_copy= do_outer_field_to_null_str;
543
543
    }
544
544
    else
597
597
        do_copy= do_copy_null;
598
598
      else
599
599
      {
600
 
        null_row= &from->table->null_row;
 
600
        null_row= &from->getTable()->null_row;
601
601
        do_copy= do_outer_field_null;
602
602
      }
603
603
    }
605
605
    {
606
606
      if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
607
607
        do_copy= do_copy_timestamp;               // Automatic timestamp
608
 
      else if (to_field == to_field->table->next_number_field)
 
608
      else if (to_field == to_field->getTable()->next_number_field)
609
609
        do_copy= do_copy_next_number;
610
610
      else
611
611
        do_copy= do_copy_not_null;
632
632
CopyField::Copy_func *
633
633
CopyField::get_copy_func(Field *to,Field *from)
634
634
{
635
 
  bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
636
 
                                     from->table->s->db_low_byte_first);
 
635
  bool compatible_db_low_byte_first= (to->getTable()->getShare()->db_low_byte_first ==
 
636
                                     from->getTable()->getShare()->db_low_byte_first);
637
637
  if (to->flags & BLOB_FLAG)
638
638
  {
639
639
    if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset())
641
641
    if (from_length != to_length || !compatible_db_low_byte_first)
642
642
    {
643
643
      // Correct pointer to point at char pointer
644
 
      to_ptr+= to_length - to->table->s->blob_ptr_size;
645
 
      from_ptr+= from_length- from->table->s->blob_ptr_size;
 
644
      to_ptr+= to_length - to->getTable()->getShare()->blob_ptr_size;
 
645
      from_ptr+= from_length- from->getTable()->getShare()->blob_ptr_size;
646
646
      return do_copy_blob;
647
647
    }
648
648
  }
660
660
      */
661
661
      if (to->real_type() != from->real_type() ||
662
662
          !compatible_db_low_byte_first ||
663
 
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_DATE) || to->type() == DRIZZLE_TYPE_DATETIME))
 
663
          (((to->getTable()->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_DATE) || to->type() == DRIZZLE_TYPE_DATETIME))
664
664
      {
665
665
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
666
666
        {
688
688
        return do_field_string;
689
689
      else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
690
690
      {
691
 
        if (((Field_varstring*) to)->length_bytes !=
692
 
            ((Field_varstring*) from)->length_bytes)
 
691
        if (((Field_varstring*) to)->pack_length_no_ptr() !=
 
692
            ((Field_varstring*) from)->pack_length_no_ptr())
693
693
        {
694
694
          return do_field_string;
695
695
        }
696
696
        
697
697
        if (to_length != from_length)
698
698
        {
699
 
          return (((Field_varstring*) to)->length_bytes == 1 ?
 
699
          return (((Field_varstring*) to)->pack_length_no_ptr() == 1 ?
700
700
                  (from->charset()->mbmaxlen == 1 ? do_varstring1 :
701
701
                                                    do_varstring1_mb) :
702
702
                  (from->charset()->mbmaxlen == 1 ? do_varstring2 :
759
759
int field_conv(Field *to,Field *from)
760
760
{
761
761
  if (to->real_type() == from->real_type() &&
762
 
      !(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
 
762
      !(to->type() == DRIZZLE_TYPE_BLOB && to->getTable()->copy_blobs))
763
763
  {
764
764
    /* Please god, will someone rewrite this to be readable :( */
765
765
    if (to->pack_length() == from->pack_length() &&
767
767
        to->real_type() != DRIZZLE_TYPE_ENUM &&
768
768
        (to->real_type() != DRIZZLE_TYPE_DECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
769
769
        from->charset() == to->charset() &&
770
 
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
771
 
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
772
 
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
 
770
        to->getTable()->getShare()->db_low_byte_first == from->getTable()->getShare()->db_low_byte_first &&
 
771
        (!(to->getTable()->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
 
772
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->pack_length_no_ptr() == ((Field_varstring*)to)->pack_length_no_ptr()))
773
773
    {                                           // Identical fields
774
774
      /* This may happen if one does 'UPDATE ... SET x=x' */
775
775
      if (to->ptr != from->ptr)
785
785
      Copy value if copy_blobs is set, or source is not a string and
786
786
      we have a pointer to its internal string conversion buffer.
787
787
    */
788
 
    if (to->table->copy_blobs ||
 
788
    if (to->getTable()->copy_blobs ||
789
789
        (!blob->value.is_alloced() &&
790
790
         from->real_type() != DRIZZLE_TYPE_VARCHAR))
791
791
      blob->value.copy();