~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

Merged from jay.

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
28
 
30
29
static void do_field_eq(Copy_field *copy)
31
30
{
371
370
{                                               // Shorter string field
372
371
  int well_formed_error;
373
372
  const CHARSET_INFO * const cs= copy->from_field->charset();
374
 
  const unsigned char *from_end= copy->from_ptr + copy->from_length;
375
 
  uint32_t copy_length= cs->cset->well_formed_len(cs,
 
373
  const uchar *from_end= copy->from_ptr + copy->from_length;
 
374
  uint copy_length= cs->cset->well_formed_len(cs,
376
375
                                              (char*) copy->from_ptr,
377
376
                                              (char*) from_end, 
378
377
                                              copy->to_length / cs->mbmaxlen,
420
419
 
421
420
static void do_varstring1(Copy_field *copy)
422
421
{
423
 
  uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
 
422
  uint length= (uint) *(uchar*) copy->from_ptr;
424
423
  if (length > copy->to_length- 1)
425
424
  {
426
425
    length=copy->to_length - 1;
428
427
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
429
428
                                  ER_WARN_DATA_TRUNCATED, 1);
430
429
  }
431
 
  *(unsigned char*) copy->to_ptr= (unsigned char) length;
 
430
  *(uchar*) copy->to_ptr= (uchar) length;
432
431
  memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
433
432
}
434
433
 
437
436
{
438
437
  int well_formed_error;
439
438
  const CHARSET_INFO * const cs= copy->from_field->charset();
440
 
  uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
441
 
  const unsigned char *from_ptr= copy->from_ptr + 1;
442
 
  uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
443
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
 
439
  uint from_length= (uint) *(uchar*) copy->from_ptr;
 
440
  const uchar *from_ptr= copy->from_ptr + 1;
 
441
  uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
 
442
  uint length= cs->cset->well_formed_len(cs, (char*) from_ptr,
444
443
                                         (char*) from_ptr + from_length,
445
444
                                         to_char_length, &well_formed_error);
446
445
  if (length < from_length)
447
446
  {
448
 
    if (current_session->count_cuted_fields)
 
447
    if (current_thd->count_cuted_fields)
449
448
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
449
                                  ER_WARN_DATA_TRUNCATED, 1);
451
450
  }
452
 
  *copy->to_ptr= (unsigned char) length;
 
451
  *copy->to_ptr= (uchar) length;
453
452
  memcpy(copy->to_ptr + 1, from_ptr, length);
454
453
}
455
454
 
456
455
 
457
456
static void do_varstring2(Copy_field *copy)
458
457
{
459
 
  uint32_t length=uint2korr(copy->from_ptr);
 
458
  uint length=uint2korr(copy->from_ptr);
460
459
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
461
460
  {
462
461
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
474
473
{
475
474
  int well_formed_error;
476
475
  const CHARSET_INFO * const cs= copy->from_field->charset();
477
 
  uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
478
 
  uint32_t from_length= uint2korr(copy->from_ptr);
479
 
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
480
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
 
476
  uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
 
477
  uint from_length= uint2korr(copy->from_ptr);
 
478
  const uchar *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
 
479
  uint length= cs->cset->well_formed_len(cs, (char*) from_beg,
481
480
                                         (char*) from_beg + from_length,
482
481
                                         char_length, &well_formed_error);
483
482
  if (length < from_length)
484
483
  {
485
 
    if (current_session->count_cuted_fields)
 
484
    if (current_thd->count_cuted_fields)
486
485
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
487
486
                                  ER_WARN_DATA_TRUNCATED, 1);
488
487
  }  
503
502
  The 'to' buffer should have a size of field->pack_length()+1
504
503
*/
505
504
 
506
 
void Copy_field::set(unsigned char *to,Field *from)
 
505
void Copy_field::set(uchar *to,Field *from)
507
506
{
508
507
  from_ptr=from->ptr;
509
508
  to_ptr=to;
513
512
    from_null_ptr=from->null_ptr;
514
513
    from_bit=     from->null_bit;
515
514
    to_ptr[0]=    1;                            // Null as default value
516
 
    to_null_ptr=  (unsigned char*) to_ptr++;
 
515
    to_null_ptr=  (uchar*) to_ptr++;
517
516
    to_bit=       1;
518
517
    if (from->table->maybe_null)
519
518
    {
638
637
      */
639
638
      if (to->real_type() != from->real_type() ||
640
639
          !compatible_db_low_byte_first ||
641
 
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_NEWDATE) || to->type() == DRIZZLE_TYPE_DATETIME))
 
640
          (((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))
642
641
      {
643
 
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
 
642
        if (from->real_type() == DRIZZLE_TYPE_ENUM ||
 
643
            from->real_type() == DRIZZLE_TYPE_SET)
644
644
          if (to->result_type() != STRING_RESULT)
645
645
            return do_field_int;                // Convert SET to number
646
646
        return do_field_string;
647
647
      }
648
 
      if (to->real_type() == DRIZZLE_TYPE_ENUM)
 
648
      if (to->real_type() == DRIZZLE_TYPE_ENUM ||
 
649
          to->real_type() == DRIZZLE_TYPE_SET)
649
650
      {
650
651
        if (!to->eq_def(from))
651
652
        {
727
728
    if (to->pack_length() == from->pack_length() && 
728
729
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && 
729
730
        to->real_type() != DRIZZLE_TYPE_ENUM && 
 
731
        to->real_type() != DRIZZLE_TYPE_SET &&
730
732
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
731
733
        from->charset() == to->charset() &&
732
734
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
733
 
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_NEWDATE && to->type() != DRIZZLE_TYPE_DATETIME)) && 
 
735
        (!(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)) && 
734
736
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
735
737
    {                                           // Identical fields
736
738
#ifdef HAVE_purify
764
766
  }
765
767
  else if ((from->result_type() == STRING_RESULT &&
766
768
            (to->result_type() == STRING_RESULT ||
767
 
             (from->real_type() != DRIZZLE_TYPE_ENUM))))
 
769
             (from->real_type() != DRIZZLE_TYPE_ENUM &&
 
770
              from->real_type() != DRIZZLE_TYPE_SET))))
768
771
  {
769
772
    char buff[MAX_FIELD_WIDTH];
770
773
    String result(buff,sizeof(buff),from->charset());