~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
#include <drizzled/server_includes.h>
28
 
#include <drizzled/error.h>
29
 
#include <drizzled/table.h>
30
 
#include <drizzled/session.h>
31
 
 
32
 
#include <drizzled/field/str.h>
33
 
#include <drizzled/field/longstr.h>
34
 
#include <drizzled/field/num.h>
35
 
#include <drizzled/field/blob.h>
36
 
#include <drizzled/field/enum.h>
37
 
#include <drizzled/field/null.h>
38
 
#include <drizzled/field/date.h>
39
 
#include <drizzled/field/decimal.h>
40
 
#include <drizzled/field/real.h>
41
 
#include <drizzled/field/double.h>
42
 
#include <drizzled/field/long.h>
43
 
#include <drizzled/field/int64_t.h>
44
 
#include <drizzled/field/num.h>
45
 
#include <drizzled/field/timetype.h>
46
 
#include <drizzled/field/timestamp.h>
47
 
#include <drizzled/field/datetime.h>
48
 
#include <drizzled/field/varstring.h>
49
 
 
50
28
 
51
29
static void do_field_eq(Copy_field *copy)
52
30
{
210
188
}
211
189
 
212
190
 
213
 
static void do_skip(Copy_field *)
 
191
static void do_skip(Copy_field *copy __attribute__((unused)))
214
192
{
215
193
}
216
194
 
395
373
  const unsigned char *from_end= copy->from_ptr + copy->from_length;
396
374
  uint32_t copy_length= cs->cset->well_formed_len(cs,
397
375
                                              (char*) copy->from_ptr,
398
 
                                              (char*) from_end,
 
376
                                              (char*) from_end, 
399
377
                                              copy->to_length / cs->mbmaxlen,
400
378
                                              &well_formed_error);
401
379
  if (copy->to_length < copy_length)
466
444
                                         to_char_length, &well_formed_error);
467
445
  if (length < from_length)
468
446
  {
469
 
    if (current_session->count_cuted_fields)
 
447
    if (current_thd->count_cuted_fields)
470
448
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
471
449
                                  ER_WARN_DATA_TRUNCATED, 1);
472
450
  }
503
481
                                         char_length, &well_formed_error);
504
482
  if (length < from_length)
505
483
  {
506
 
    if (current_session->count_cuted_fields)
 
484
    if (current_thd->count_cuted_fields)
507
485
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
486
                                  ER_WARN_DATA_TRUNCATED, 1);
509
 
  }
 
487
  }  
510
488
  int2store(copy->to_ptr, length);
511
489
  memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
512
490
}
513
 
 
 
491
 
514
492
 
515
493
/***************************************************************************
516
494
** The different functions that fills in a Copy_field class
553
531
 
554
532
 
555
533
/*
556
 
  To do:
 
534
  To do: 
557
535
 
558
536
  If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
559
537
  do_save_blob rather than do_conv_blob.  The only differences between them
560
538
  appears to be:
561
539
 
562
 
  - do_save_blob allocates and uses an intermediate buffer before calling
563
 
    Field_blob::store. Is this in order to trigger the call to
 
540
  - do_save_blob allocates and uses an intermediate buffer before calling 
 
541
    Field_blob::store. Is this in order to trigger the call to 
564
542
    well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
565
543
    That call will take place anyway in all known cases.
566
544
 
567
 
  - The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
 
545
  - The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended 
568
546
    effect? Truncation is handled by well_formed_copy_nchars anyway.
569
547
 */
570
548
void Copy_field::set(Field *to,Field *from,bool save)
659
637
      */
660
638
      if (to->real_type() != from->real_type() ||
661
639
          !compatible_db_low_byte_first ||
662
 
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_DATE) || to->type() == DRIZZLE_TYPE_DATETIME))
 
640
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_NEWDATE) || to->type() == DRIZZLE_TYPE_DATETIME))
663
641
      {
664
642
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
665
643
          if (to->result_type() != STRING_RESULT)
745
723
      !(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
746
724
  {
747
725
    /* Please god, will someone rewrite this to be readable :( */
748
 
    if (to->pack_length() == from->pack_length() &&
749
 
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
750
 
        to->real_type() != DRIZZLE_TYPE_ENUM &&
 
726
    if (to->pack_length() == from->pack_length() && 
 
727
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && 
 
728
        to->real_type() != DRIZZLE_TYPE_ENUM && 
751
729
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
752
730
        from->charset() == to->charset() &&
753
731
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
754
 
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
 
732
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_NEWDATE && to->type() != DRIZZLE_TYPE_DATETIME)) && 
755
733
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
756
734
    {                                           // Identical fields
 
735
#ifdef HAVE_purify
757
736
      /* This may happen if one does 'UPDATE ... SET x=x' */
758
737
      if (to->ptr != from->ptr)
 
738
#endif
759
739
        memcpy(to->ptr,from->ptr,to->pack_length());
760
740
      return 0;
761
741
    }