~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Eric Herman
  • Date: 2008-12-07 15:29:44 UTC
  • mto: (656.1.14 devel)
  • mto: This revision was merged to the branch mainline in revision 670.
  • Revision ID: eric@mysql.com-20081207152944-cq1nx1cyi0huqj0f
Added pointer to online version of the FAQ

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    gives much more speed.
25
25
*/
26
26
 
27
 
#include "config.h"
 
27
#include <drizzled/server_includes.h>
28
28
#include <drizzled/error.h>
29
29
#include <drizzled/table.h>
30
30
#include <drizzled/session.h>
31
31
 
32
32
#include <drizzled/field/str.h>
 
33
#include <drizzled/field/longstr.h>
33
34
#include <drizzled/field/num.h>
34
35
#include <drizzled/field/blob.h>
35
36
#include <drizzled/field/enum.h>
36
37
#include <drizzled/field/null.h>
37
38
#include <drizzled/field/date.h>
38
 
#include <drizzled/field/decimal.h>
 
39
#include <drizzled/field/fdecimal.h>
39
40
#include <drizzled/field/real.h>
40
41
#include <drizzled/field/double.h>
41
42
#include <drizzled/field/long.h>
42
43
#include <drizzled/field/int64_t.h>
43
44
#include <drizzled/field/num.h>
 
45
#include <drizzled/field/timetype.h>
44
46
#include <drizzled/field/timestamp.h>
45
47
#include <drizzled/field/datetime.h>
46
48
#include <drizzled/field/varstring.h>
47
49
 
48
 
namespace drizzled
49
 
{
50
 
 
51
 
static void do_field_eq(CopyField *copy)
52
 
{
53
 
  memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
54
 
}
55
 
 
56
 
static void do_field_1(CopyField *copy)
57
 
{
58
 
  copy->to_ptr[0]= copy->from_ptr[0];
59
 
}
60
 
 
61
 
static void do_field_2(CopyField *copy)
62
 
{
63
 
  copy->to_ptr[0]= copy->from_ptr[0];
64
 
  copy->to_ptr[1]= copy->from_ptr[1];
65
 
}
66
 
 
67
 
static void do_field_3(CopyField *copy)
68
 
{
69
 
  copy->to_ptr[0]= copy->from_ptr[0];
70
 
  copy->to_ptr[1]= copy->from_ptr[1];
71
 
  copy->to_ptr[2]= copy->from_ptr[2];
72
 
}
73
 
 
74
 
static void do_field_4(CopyField *copy)
75
 
{
76
 
  copy->to_ptr[0]= copy->from_ptr[0];
77
 
  copy->to_ptr[1]= copy->from_ptr[1];
78
 
  copy->to_ptr[2]= copy->from_ptr[2];
79
 
  copy->to_ptr[3]= copy->from_ptr[3];
80
 
}
81
 
 
82
 
static void do_field_6(CopyField *copy)
83
 
{                  // For blob field
84
 
  copy->to_ptr[0]= copy->from_ptr[0];
85
 
  copy->to_ptr[1]= copy->from_ptr[1];
86
 
  copy->to_ptr[2]= copy->from_ptr[2];
87
 
  copy->to_ptr[3]= copy->from_ptr[3];
88
 
  copy->to_ptr[4]= copy->from_ptr[4];
89
 
  copy->to_ptr[5]= copy->from_ptr[5];
90
 
}
91
 
 
92
 
static void do_field_8(CopyField *copy)
93
 
{
94
 
  copy->to_ptr[0]= copy->from_ptr[0];
95
 
  copy->to_ptr[1]= copy->from_ptr[1];
96
 
  copy->to_ptr[2]= copy->from_ptr[2];
97
 
  copy->to_ptr[3]= copy->from_ptr[3];
98
 
  copy->to_ptr[4]= copy->from_ptr[4];
99
 
  copy->to_ptr[5]= copy->from_ptr[5];
100
 
  copy->to_ptr[6]= copy->from_ptr[6];
101
 
  copy->to_ptr[7]= copy->from_ptr[7];
102
 
}
103
 
 
104
 
 
105
 
static void do_field_to_null_str(CopyField *copy)
 
50
 
 
51
static void do_field_eq(Copy_field *copy)
 
52
{
 
53
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
54
}
 
55
 
 
56
static void do_field_1(Copy_field *copy)
 
57
{
 
58
  copy->to_ptr[0]=copy->from_ptr[0];
 
59
}
 
60
 
 
61
static void do_field_2(Copy_field *copy)
 
62
{
 
63
  copy->to_ptr[0]=copy->from_ptr[0];
 
64
  copy->to_ptr[1]=copy->from_ptr[1];
 
65
}
 
66
 
 
67
static void do_field_3(Copy_field *copy)
 
68
{
 
69
  copy->to_ptr[0]=copy->from_ptr[0];
 
70
  copy->to_ptr[1]=copy->from_ptr[1];
 
71
  copy->to_ptr[2]=copy->from_ptr[2];
 
72
}
 
73
 
 
74
static void do_field_4(Copy_field *copy)
 
75
{
 
76
  copy->to_ptr[0]=copy->from_ptr[0];
 
77
  copy->to_ptr[1]=copy->from_ptr[1];
 
78
  copy->to_ptr[2]=copy->from_ptr[2];
 
79
  copy->to_ptr[3]=copy->from_ptr[3];
 
80
}
 
81
 
 
82
static void do_field_6(Copy_field *copy)
 
83
{                                               // For blob field
 
84
  copy->to_ptr[0]=copy->from_ptr[0];
 
85
  copy->to_ptr[1]=copy->from_ptr[1];
 
86
  copy->to_ptr[2]=copy->from_ptr[2];
 
87
  copy->to_ptr[3]=copy->from_ptr[3];
 
88
  copy->to_ptr[4]=copy->from_ptr[4];
 
89
  copy->to_ptr[5]=copy->from_ptr[5];
 
90
}
 
91
 
 
92
static void do_field_8(Copy_field *copy)
 
93
{
 
94
  copy->to_ptr[0]=copy->from_ptr[0];
 
95
  copy->to_ptr[1]=copy->from_ptr[1];
 
96
  copy->to_ptr[2]=copy->from_ptr[2];
 
97
  copy->to_ptr[3]=copy->from_ptr[3];
 
98
  copy->to_ptr[4]=copy->from_ptr[4];
 
99
  copy->to_ptr[5]=copy->from_ptr[5];
 
100
  copy->to_ptr[6]=copy->from_ptr[6];
 
101
  copy->to_ptr[7]=copy->from_ptr[7];
 
102
}
 
103
 
 
104
 
 
105
static void do_field_to_null_str(Copy_field *copy)
106
106
{
107
107
  if (*copy->from_null_ptr & copy->from_bit)
108
108
  {
109
109
    memset(copy->to_ptr, 0, copy->from_length);
110
 
    copy->to_null_ptr[0]= 1;  // Always bit 1
 
110
    copy->to_null_ptr[0]=1;                     // Always bit 1
111
111
  }
112
112
  else
113
113
  {
114
 
    copy->to_null_ptr[0]= 0;
115
 
    memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
 
114
    copy->to_null_ptr[0]=0;
 
115
    memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
116
116
  }
117
117
}
118
118
 
119
119
 
120
 
static void do_outer_field_to_null_str(CopyField *copy)
 
120
static void do_outer_field_to_null_str(Copy_field *copy)
121
121
{
122
122
  if (*copy->null_row ||
123
123
      (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
124
124
  {
125
125
    memset(copy->to_ptr, 0, copy->from_length);
126
 
    copy->to_null_ptr[0]= 1;  // Always bit 1
 
126
    copy->to_null_ptr[0]=1;                     // Always bit 1
127
127
  }
128
128
  else
129
129
  {
130
 
    copy->to_null_ptr[0]= 0;
131
 
    memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
 
130
    copy->to_null_ptr[0]=0;
 
131
    memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
132
132
  }
133
133
}
134
134
 
210
210
}
211
211
 
212
212
 
213
 
static void do_skip(CopyField *)
 
213
static void do_skip(Copy_field *copy __attribute__((unused)))
214
214
{
215
215
}
216
216
 
217
217
 
218
 
static void do_copy_null(CopyField *copy)
 
218
static void do_copy_null(Copy_field *copy)
219
219
{
220
220
  if (*copy->from_null_ptr & copy->from_bit)
221
221
  {
222
 
    *copy->to_null_ptr|= copy->to_bit;
 
222
    *copy->to_null_ptr|=copy->to_bit;
223
223
    copy->to_field->reset();
224
224
  }
225
225
  else
230
230
}
231
231
 
232
232
 
233
 
static void do_outer_field_null(CopyField *copy)
 
233
static void do_outer_field_null(Copy_field *copy)
234
234
{
235
235
  if (*copy->null_row ||
236
236
      (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
246
246
}
247
247
 
248
248
 
249
 
static void do_copy_not_null(CopyField *copy)
 
249
static void do_copy_not_null(Copy_field *copy)
250
250
{
251
251
  if (*copy->from_null_ptr & copy->from_bit)
252
252
  {
259
259
}
260
260
 
261
261
 
262
 
static void do_copy_maybe_null(CopyField *copy)
 
262
static void do_copy_maybe_null(Copy_field *copy)
263
263
{
264
264
  *copy->to_null_ptr&= ~copy->to_bit;
265
265
  (copy->do_copy2)(copy);
267
267
 
268
268
/* timestamp and next_number has special handling in case of NULL values */
269
269
 
270
 
static void do_copy_timestamp(CopyField *copy)
 
270
static void do_copy_timestamp(Copy_field *copy)
271
271
{
272
272
  if (*copy->from_null_ptr & copy->from_bit)
273
273
  {
279
279
}
280
280
 
281
281
 
282
 
static void do_copy_next_number(CopyField *copy)
 
282
static void do_copy_next_number(Copy_field *copy)
283
283
{
284
284
  if (*copy->from_null_ptr & copy->from_bit)
285
285
  {
292
292
}
293
293
 
294
294
 
295
 
static void do_copy_blob(CopyField *copy)
 
295
static void do_copy_blob(Copy_field *copy)
296
296
{
297
 
  ulong length= ((Field_blob*) copy->from_field)->get_length();
 
297
  ulong length=((Field_blob*) copy->from_field)->get_length();
298
298
  ((Field_blob*) copy->to_field)->store_length(length);
299
 
  memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
 
299
  memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
300
300
}
301
301
 
302
 
static void do_conv_blob(CopyField *copy)
 
302
static void do_conv_blob(Copy_field *copy)
303
303
{
304
304
  copy->from_field->val_str(&copy->tmp);
305
305
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
306
 
                                         copy->tmp.length(),
307
 
                                         copy->tmp.charset());
 
306
                                         copy->tmp.length(),
 
307
                                         copy->tmp.charset());
308
308
}
309
309
 
310
310
/** Save blob in copy->tmp for GROUP BY. */
311
311
 
312
 
static void do_save_blob(CopyField *copy)
 
312
static void do_save_blob(Copy_field *copy)
313
313
{
314
314
  char buff[MAX_FIELD_WIDTH];
315
 
  String res(buff, sizeof(buff), copy->tmp.charset());
 
315
  String res(buff,sizeof(buff),copy->tmp.charset());
316
316
  copy->from_field->val_str(&res);
317
317
  copy->tmp.copy(res);
318
318
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
319
 
                                         copy->tmp.length(),
320
 
                                         copy->tmp.charset());
 
319
                                         copy->tmp.length(),
 
320
                                         copy->tmp.charset());
321
321
}
322
322
 
323
323
 
324
 
static void do_field_string(CopyField *copy)
 
324
static void do_field_string(Copy_field *copy)
325
325
{
326
326
  char buff[MAX_FIELD_WIDTH];
327
327
  copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
331
331
}
332
332
 
333
333
 
334
 
static void do_field_enum(CopyField *copy)
 
334
static void do_field_enum(Copy_field *copy)
335
335
{
336
336
  if (copy->from_field->val_int() == 0)
337
337
    ((Field_enum *) copy->to_field)->store_type((uint64_t) 0);
340
340
}
341
341
 
342
342
 
343
 
static void do_field_int(CopyField *copy)
 
343
static void do_field_int(Copy_field *copy)
344
344
{
345
345
  int64_t value= copy->from_field->val_int();
346
346
  copy->to_field->store(value,
347
347
                        test(copy->from_field->flags & UNSIGNED_FLAG));
348
348
}
349
349
 
350
 
static void do_field_real(CopyField *copy)
 
350
static void do_field_real(Copy_field *copy)
351
351
{
352
352
  double value=copy->from_field->val_real();
353
353
  copy->to_field->store(value);
354
354
}
355
355
 
356
356
 
357
 
static void do_field_decimal(CopyField *copy)
 
357
static void do_field_decimal(Copy_field *copy)
358
358
{
359
359
  my_decimal value;
360
360
  copy->to_field->store_decimal(copy->from_field->val_decimal(&value));
366
366
  from string.
367
367
*/
368
368
 
369
 
static void do_cut_string(CopyField *copy)
 
369
static void do_cut_string(Copy_field *copy)
370
370
{
371
371
  const CHARSET_INFO * const cs= copy->from_field->charset();
372
372
  memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
388
388
  from string.
389
389
*/
390
390
 
391
 
static void do_cut_string_complex(CopyField *copy)
 
391
static void do_cut_string_complex(Copy_field *copy)
392
392
{                                               // Shorter string field
393
393
  int well_formed_error;
394
394
  const CHARSET_INFO * const cs= copy->from_field->charset();
420
420
 
421
421
 
422
422
 
423
 
static void do_expand_binary(CopyField *copy)
424
 
{
425
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
426
 
  memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
427
 
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
428
 
                 copy->to_length-copy->from_length, '\0');
429
 
}
430
 
 
431
 
 
432
 
 
433
 
static void do_expand_string(CopyField *copy)
434
 
{
435
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
436
 
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
437
 
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
438
 
                 copy->to_length-copy->from_length, ' ');
439
 
}
440
 
 
441
 
 
442
 
static void do_varstring1(CopyField *copy)
443
 
{
444
 
  uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr;
 
423
static void do_expand_binary(Copy_field *copy)
 
424
{
 
425
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
426
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
427
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
 
428
                     copy->to_length-copy->from_length, '\0');
 
429
}
 
430
 
 
431
 
 
432
 
 
433
static void do_expand_string(Copy_field *copy)
 
434
{
 
435
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
436
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
437
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
 
438
                     copy->to_length-copy->from_length, ' ');
 
439
}
 
440
 
 
441
 
 
442
static void do_varstring1(Copy_field *copy)
 
443
{
 
444
  uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
445
445
  if (length > copy->to_length- 1)
446
446
  {
447
 
    length= copy->to_length - 1;
 
447
    length=copy->to_length - 1;
448
448
    if (copy->from_field->table->in_use->count_cuted_fields)
449
449
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
450
                                  ER_WARN_DATA_TRUNCATED, 1);
454
454
}
455
455
 
456
456
 
457
 
static void do_varstring1_mb(CopyField *copy)
 
457
static void do_varstring1_mb(Copy_field *copy)
458
458
{
459
459
  int well_formed_error;
460
460
  const CHARSET_INFO * const cs= copy->from_field->charset();
461
 
  uint32_t from_length= (uint32_t) *(unsigned char*) copy->from_ptr;
 
461
  uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
462
462
  const unsigned char *from_ptr= copy->from_ptr + 1;
463
463
  uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
464
464
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
475
475
}
476
476
 
477
477
 
478
 
static void do_varstring2(CopyField *copy)
 
478
static void do_varstring2(Copy_field *copy)
479
479
{
480
 
  uint32_t length= uint2korr(copy->from_ptr);
 
480
  uint32_t length=uint2korr(copy->from_ptr);
481
481
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
482
482
  {
483
483
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
491
491
}
492
492
 
493
493
 
494
 
static void do_varstring2_mb(CopyField *copy)
 
494
static void do_varstring2_mb(Copy_field *copy)
495
495
{
496
496
  int well_formed_error;
497
497
  const CHARSET_INFO * const cs= copy->from_field->charset();
499
499
  uint32_t from_length= uint2korr(copy->from_ptr);
500
500
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
501
501
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
502
 
                                             (char*) from_beg + from_length,
503
 
                                             char_length, &well_formed_error);
 
502
                                         (char*) from_beg + from_length,
 
503
                                         char_length, &well_formed_error);
504
504
  if (length < from_length)
505
505
  {
506
506
    if (current_session->count_cuted_fields)
513
513
 
514
514
 
515
515
/***************************************************************************
516
 
** The different functions that fills in a CopyField class
 
516
** The different functions that fills in a Copy_field class
517
517
***************************************************************************/
518
518
 
519
519
/**
524
524
  The 'to' buffer should have a size of field->pack_length()+1
525
525
*/
526
526
 
527
 
void CopyField::set(unsigned char *to,Field *from)
 
527
void Copy_field::set(unsigned char *to,Field *from)
528
528
{
529
 
  from_ptr= from->ptr;
530
 
  to_ptr= to;
531
 
  from_length= from->pack_length();
 
529
  from_ptr=from->ptr;
 
530
  to_ptr=to;
 
531
  from_length=from->pack_length();
532
532
  if (from->maybe_null())
533
533
  {
534
 
    from_null_ptr= from->null_ptr;
535
 
    from_bit= from->null_bit;
536
 
    to_ptr[0]= 1;                             // Null as default value
537
 
    to_null_ptr= (unsigned char*) to_ptr++;
538
 
    to_bit= 1;
 
534
    from_null_ptr=from->null_ptr;
 
535
    from_bit=     from->null_bit;
 
536
    to_ptr[0]=    1;                            // Null as default value
 
537
    to_null_ptr=  (unsigned char*) to_ptr++;
 
538
    to_bit=       1;
539
539
    if (from->table->maybe_null)
540
540
    {
541
 
      null_row= &from->table->null_row;
542
 
      do_copy= do_outer_field_to_null_str;
 
541
      null_row=   &from->table->null_row;
 
542
      do_copy=    do_outer_field_to_null_str;
543
543
    }
544
544
    else
545
 
      do_copy= do_field_to_null_str;
 
545
      do_copy=    do_field_to_null_str;
546
546
  }
547
547
  else
548
548
  {
549
 
    to_null_ptr= 0;                           // For easy debugging
550
 
    do_copy= do_field_eq;
 
549
    to_null_ptr=  0;                            // For easy debugging
 
550
    do_copy=      do_field_eq;
551
551
  }
552
552
}
553
553
 
567
567
  - The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
568
568
    effect? Truncation is handled by well_formed_copy_nchars anyway.
569
569
 */
570
 
void CopyField::set(Field *to,Field *from,bool save)
 
570
void Copy_field::set(Field *to,Field *from,bool save)
571
571
{
572
572
  if (to->type() == DRIZZLE_TYPE_NULL)
573
573
  {
574
 
    to_null_ptr= 0;           // For easy debugging
575
 
    to_ptr= 0;
576
 
    do_copy= do_skip;
 
574
    to_null_ptr=0;                              // For easy debugging
 
575
    to_ptr=0;
 
576
    do_copy=do_skip;
577
577
    return;
578
578
  }
579
 
  from_field= from;
580
 
  to_field= to;
581
 
  from_ptr= from->ptr;
582
 
  from_length= from->pack_length();
583
 
  to_ptr= to->ptr;
584
 
  to_length= to_field->pack_length();
 
579
  from_field=from;
 
580
  to_field=to;
 
581
  from_ptr=from->ptr;
 
582
  from_length=from->pack_length();
 
583
  to_ptr=  to->ptr;
 
584
  to_length=to_field->pack_length();
585
585
 
586
586
  // set up null handling
587
 
  from_null_ptr= to_null_ptr= 0;
 
587
  from_null_ptr=to_null_ptr=0;
588
588
  if (from->maybe_null())
589
589
  {
590
 
    from_null_ptr= from->null_ptr;
591
 
    from_bit= from->null_bit;
 
590
    from_null_ptr=      from->null_ptr;
 
591
    from_bit=           from->null_bit;
592
592
    if (to_field->real_maybe_null())
593
593
    {
594
 
      to_null_ptr= to->null_ptr;
595
 
      to_bit= to->null_bit;
 
594
      to_null_ptr=      to->null_ptr;
 
595
      to_bit=           to->null_bit;
596
596
      if (from_null_ptr)
597
 
        do_copy= do_copy_null;
 
597
        do_copy=        do_copy_null;
598
598
      else
599
599
      {
600
 
        null_row= &from->table->null_row;
601
 
        do_copy= do_outer_field_null;
 
600
        null_row=       &from->table->null_row;
 
601
        do_copy=        do_outer_field_null;
602
602
      }
603
603
    }
604
604
    else
613
613
  }
614
614
  else if (to_field->real_maybe_null())
615
615
  {
616
 
    to_null_ptr= to->null_ptr;
617
 
    to_bit= to->null_bit;
 
616
    to_null_ptr=        to->null_ptr;
 
617
    to_bit=             to->null_bit;
618
618
    do_copy= do_copy_maybe_null;
619
619
  }
620
620
  else
621
 
   do_copy= 0;
 
621
   do_copy=0;
622
622
 
623
623
  if ((to->flags & BLOB_FLAG) && save)
624
624
    do_copy2= do_save_blob;
625
625
  else
626
626
    do_copy2= get_copy_func(to,from);
627
 
  if (!do_copy)         // Not null
628
 
    do_copy= do_copy2;
 
627
  if (!do_copy)                                 // Not null
 
628
    do_copy=do_copy2;
629
629
}
630
630
 
631
631
 
632
 
CopyField::Copy_func *
633
 
CopyField::get_copy_func(Field *to,Field *from)
 
632
Copy_field::Copy_func *
 
633
Copy_field::get_copy_func(Field *to,Field *from)
634
634
{
635
635
  bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
636
636
                                     from->table->s->db_low_byte_first);
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;
 
644
      to_ptr+=   to_length - to->table->s->blob_ptr_size;
645
645
      from_ptr+= from_length- from->table->s->blob_ptr_size;
646
646
      return do_copy_blob;
647
647
    }
650
650
  {
651
651
    if (to->result_type() == DECIMAL_RESULT)
652
652
      return do_field_decimal;
653
 
      
654
653
    // Check if identical fields
655
654
    if (from->result_type() == STRING_RESULT)
656
655
    {
662
661
          !compatible_db_low_byte_first ||
663
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))
664
663
      {
665
 
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
666
 
        {
667
 
          if (to->result_type() != STRING_RESULT)
668
 
          {
669
 
            return do_field_int;  // Convert SET to number
670
 
          }
671
 
          
672
 
          return do_field_string;
673
 
        }
 
664
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
 
665
          if (to->result_type() != STRING_RESULT)
 
666
            return do_field_int;                // Convert SET to number
 
667
        return do_field_string;
674
668
      }
675
 
      
676
669
      if (to->real_type() == DRIZZLE_TYPE_ENUM)
677
670
      {
678
 
        if (!to->eq_def(from))
 
671
        if (!to->eq_def(from))
679
672
        {
680
673
          if (from->real_type() == DRIZZLE_TYPE_ENUM &&
681
674
              to->real_type() == DRIZZLE_TYPE_ENUM)
685
678
        }
686
679
      }
687
680
      else if (to->charset() != from->charset())
688
 
        return do_field_string;
 
681
        return do_field_string;
689
682
      else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
690
683
      {
691
684
        if (((Field_varstring*) to)->length_bytes !=
692
685
            ((Field_varstring*) from)->length_bytes)
693
 
        {
694
686
          return do_field_string;
695
 
        }
696
 
        
697
687
        if (to_length != from_length)
698
 
        {
699
688
          return (((Field_varstring*) to)->length_bytes == 1 ?
700
689
                  (from->charset()->mbmaxlen == 1 ? do_varstring1 :
701
690
                                                    do_varstring1_mb) :
702
691
                  (from->charset()->mbmaxlen == 1 ? do_varstring2 :
703
692
                                                    do_varstring2_mb));
704
 
        }
705
693
      }
706
694
      else if (to_length < from_length)
707
 
      {
708
 
        return (from->charset()->mbmaxlen == 1 ?
 
695
        return (from->charset()->mbmaxlen == 1 ?
709
696
                do_cut_string : do_cut_string_complex);
710
 
      }
711
697
      else if (to_length > from_length)
712
698
      {
713
699
        if (to->charset() == &my_charset_bin)
715
701
        else
716
702
          return do_expand_string;
717
703
      }
 
704
 
718
705
    }
719
706
    else if (to->real_type() != from->real_type() ||
720
 
             to_length != from_length ||
 
707
             to_length != from_length ||
721
708
             !compatible_db_low_byte_first)
722
709
    {
723
710
      if (to->result_type() == STRING_RESULT)
724
 
        return do_field_string;
 
711
        return do_field_string;
725
712
      if (to->result_type() == INT_RESULT)
726
 
        return do_field_int;
727
 
 
 
713
        return do_field_int;
728
714
      return do_field_real;
729
715
    }
730
716
    else
731
717
    {
732
718
      if (!to->eq_def(from) || !compatible_db_low_byte_first)
733
719
      {
734
 
        if (to->result_type() == INT_RESULT)
735
 
          return do_field_int;
736
 
        else
737
 
          return do_field_real;
 
720
        if (to->result_type() == INT_RESULT)
 
721
          return do_field_int;
 
722
        else
 
723
          return do_field_real;
738
724
      }
739
725
    }
740
726
  }
741
 
  
742
727
    /* Eq fields */
743
 
  switch (to_length)
744
 
  {
 
728
  switch (to_length) {
745
729
  case 1: return do_field_1;
746
730
  case 2: return do_field_2;
747
731
  case 3: return do_field_3;
749
733
  case 6: return do_field_6;
750
734
  case 8: return do_field_8;
751
735
  }
752
 
  
753
736
  return do_field_eq;
754
737
}
755
738
 
765
748
    if (to->pack_length() == from->pack_length() &&
766
749
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
767
750
        to->real_type() != DRIZZLE_TYPE_ENUM &&
768
 
        (to->real_type() != DRIZZLE_TYPE_DECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
 
751
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
769
752
        from->charset() == to->charset() &&
770
753
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
771
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)) &&
823
806
  else
824
807
    return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
825
808
}
826
 
 
827
 
} /* namespace drizzled */