~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Monty Taylor
  • Date: 2008-08-04 22:01:39 UTC
  • mto: (261.1.4 drizzle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804220139-fy862jc9lykayvka
Moved libdrizzle.ver.in to libdrizzle.ver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    gives much more speed.
25
25
*/
26
26
 
27
 
#include <drizzled/server_includes.h>
 
27
#include "mysql_priv.h"
28
28
 
29
29
static void do_field_eq(Copy_field *copy)
30
30
{
123
123
  field->reset();
124
124
  if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
125
125
  {
126
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
126
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
127
127
    return 0;
128
128
  }
129
129
  if (!field->table->in_use->no_errors)
179
179
  }
180
180
  if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
181
181
  {
182
 
    field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
 
182
    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
183
183
    return 0;
184
184
  }
185
185
  if (!field->table->in_use->no_errors)
228
228
{
229
229
  if (*copy->from_null_ptr & copy->from_bit)
230
230
  {
231
 
    copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
231
    copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
232
232
                                ER_WARN_DATA_TRUNCATED, 1);
233
233
    copy->to_field->reset();
234
234
  }
346
346
 
347
347
static void do_cut_string(Copy_field *copy)
348
348
{
349
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
349
  CHARSET_INFO *cs= copy->from_field->charset();
350
350
  memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
351
351
 
352
352
  /* Check if we loosed any important characters */
355
355
                     (char*) copy->from_ptr + copy->from_length,
356
356
                     MY_SEQ_SPACES) < copy->from_length - copy->to_length)
357
357
  {
358
 
    copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
358
    copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
359
359
                                ER_WARN_DATA_TRUNCATED, 1);
360
360
  }
361
361
}
369
369
static void do_cut_string_complex(Copy_field *copy)
370
370
{                                               // Shorter string field
371
371
  int well_formed_error;
372
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
373
 
  const unsigned char *from_end= copy->from_ptr + copy->from_length;
374
 
  uint32_t copy_length= cs->cset->well_formed_len(cs,
 
372
  CHARSET_INFO *cs= copy->from_field->charset();
 
373
  const uchar *from_end= copy->from_ptr + copy->from_length;
 
374
  uint copy_length= cs->cset->well_formed_len(cs,
375
375
                                              (char*) copy->from_ptr,
376
376
                                              (char*) from_end, 
377
377
                                              copy->to_length / cs->mbmaxlen,
386
386
                     (char*) from_end,
387
387
                     MY_SEQ_SPACES) < (copy->from_length - copy_length))
388
388
  {
389
 
    copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
389
    copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
390
390
                                ER_WARN_DATA_TRUNCATED, 1);
391
391
  }
392
392
 
400
400
 
401
401
static void do_expand_binary(Copy_field *copy)
402
402
{
403
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
403
  CHARSET_INFO *cs= copy->from_field->charset();
404
404
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
405
405
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
406
406
                     copy->to_length-copy->from_length, '\0');
410
410
 
411
411
static void do_expand_string(Copy_field *copy)
412
412
{
413
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
413
  CHARSET_INFO *cs= copy->from_field->charset();
414
414
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
415
415
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
416
416
                     copy->to_length-copy->from_length, ' ');
419
419
 
420
420
static void do_varstring1(Copy_field *copy)
421
421
{
422
 
  uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
 
422
  uint length= (uint) *(uchar*) copy->from_ptr;
423
423
  if (length > copy->to_length- 1)
424
424
  {
425
425
    length=copy->to_length - 1;
426
426
    if (copy->from_field->table->in_use->count_cuted_fields)
427
 
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
427
      copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
428
428
                                  ER_WARN_DATA_TRUNCATED, 1);
429
429
  }
430
 
  *(unsigned char*) copy->to_ptr= (unsigned char) length;
 
430
  *(uchar*) copy->to_ptr= (uchar) length;
431
431
  memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
432
432
}
433
433
 
435
435
static void do_varstring1_mb(Copy_field *copy)
436
436
{
437
437
  int well_formed_error;
438
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
439
 
  uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
440
 
  const unsigned char *from_ptr= copy->from_ptr + 1;
441
 
  uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
442
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
 
438
  CHARSET_INFO *cs= copy->from_field->charset();
 
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,
443
443
                                         (char*) from_ptr + from_length,
444
444
                                         to_char_length, &well_formed_error);
445
445
  if (length < from_length)
446
446
  {
447
447
    if (current_thd->count_cuted_fields)
448
 
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
448
      copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
449
449
                                  ER_WARN_DATA_TRUNCATED, 1);
450
450
  }
451
 
  *copy->to_ptr= (unsigned char) length;
 
451
  *copy->to_ptr= (uchar) length;
452
452
  memcpy(copy->to_ptr + 1, from_ptr, length);
453
453
}
454
454
 
455
455
 
456
456
static void do_varstring2(Copy_field *copy)
457
457
{
458
 
  uint32_t length=uint2korr(copy->from_ptr);
 
458
  uint length=uint2korr(copy->from_ptr);
459
459
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
460
460
  {
461
461
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
462
462
    if (copy->from_field->table->in_use->count_cuted_fields)
463
 
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
463
      copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
464
464
                                  ER_WARN_DATA_TRUNCATED, 1);
465
465
  }
466
466
  int2store(copy->to_ptr,length);
472
472
static void do_varstring2_mb(Copy_field *copy)
473
473
{
474
474
  int well_formed_error;
475
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
476
 
  uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
477
 
  uint32_t from_length= uint2korr(copy->from_ptr);
478
 
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
479
 
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
 
475
  CHARSET_INFO *cs= copy->from_field->charset();
 
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,
480
480
                                         (char*) from_beg + from_length,
481
481
                                         char_length, &well_formed_error);
482
482
  if (length < from_length)
483
483
  {
484
484
    if (current_thd->count_cuted_fields)
485
 
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
485
      copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
486
486
                                  ER_WARN_DATA_TRUNCATED, 1);
487
487
  }  
488
488
  int2store(copy->to_ptr, length);
502
502
  The 'to' buffer should have a size of field->pack_length()+1
503
503
*/
504
504
 
505
 
void Copy_field::set(unsigned char *to,Field *from)
 
505
void Copy_field::set(uchar *to,Field *from)
506
506
{
507
507
  from_ptr=from->ptr;
508
508
  to_ptr=to;
512
512
    from_null_ptr=from->null_ptr;
513
513
    from_bit=     from->null_bit;
514
514
    to_ptr[0]=    1;                            // Null as default value
515
 
    to_null_ptr=  (unsigned char*) to_ptr++;
 
515
    to_null_ptr=  (uchar*) to_ptr++;
516
516
    to_bit=       1;
517
517
    if (from->table->maybe_null)
518
518
    {
637
637
      */
638
638
      if (to->real_type() != from->real_type() ||
639
639
          !compatible_db_low_byte_first ||
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))
 
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))
641
641
      {
642
 
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
 
642
        if (from->real_type() == DRIZZLE_TYPE_ENUM ||
 
643
            from->real_type() == DRIZZLE_TYPE_SET)
643
644
          if (to->result_type() != STRING_RESULT)
644
645
            return do_field_int;                // Convert SET to number
645
646
        return do_field_string;
646
647
      }
647
 
      if (to->real_type() == DRIZZLE_TYPE_ENUM)
 
648
      if (to->real_type() == DRIZZLE_TYPE_ENUM ||
 
649
          to->real_type() == DRIZZLE_TYPE_SET)
648
650
      {
649
651
        if (!to->eq_def(from))
650
652
        {
726
728
    if (to->pack_length() == from->pack_length() && 
727
729
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && 
728
730
        to->real_type() != DRIZZLE_TYPE_ENUM && 
 
731
        to->real_type() != DRIZZLE_TYPE_SET &&
729
732
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
730
733
        from->charset() == to->charset() &&
731
734
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
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)) && 
 
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)) && 
733
736
        (from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
734
737
    {                                           // Identical fields
735
738
#ifdef HAVE_purify
763
766
  }
764
767
  else if ((from->result_type() == STRING_RESULT &&
765
768
            (to->result_type() == STRING_RESULT ||
766
 
             (from->real_type() != DRIZZLE_TYPE_ENUM))))
 
769
             (from->real_type() != DRIZZLE_TYPE_ENUM &&
 
770
              from->real_type() != DRIZZLE_TYPE_SET))))
767
771
  {
768
772
    char buff[MAX_FIELD_WIDTH];
769
773
    String result(buff,sizeof(buff),from->charset());