616
577
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
617
578
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
618
579
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
619
//MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
620
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
621
//MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
622
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
623
582
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
624
583
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
625
584
//MYSQL_TYPE_STRING
626
585
MYSQL_TYPE_STRING
628
/* MYSQL_TYPE_TINY_BLOB -> */
630
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
631
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
632
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
633
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
634
//MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
635
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
636
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
637
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
638
//MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
639
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
640
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
641
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
642
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
643
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
644
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
645
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
646
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
647
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
648
//MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
649
MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
650
//MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
651
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
652
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
653
MYSQL_TYPE_BLOB, MYSQL_TYPE_TINY_BLOB,
657
/* MYSQL_TYPE_MEDIUM_BLOB -> */
659
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
660
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
661
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
662
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
663
//MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
664
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
665
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
666
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
667
//MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
668
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
669
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
670
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
671
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
672
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
673
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
674
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
675
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
676
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
677
//MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
678
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
679
//MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
680
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
681
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
682
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
684
MYSQL_TYPE_MEDIUM_BLOB
686
/* MYSQL_TYPE_LONG_BLOB -> */
688
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
689
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
690
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
691
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
692
//MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
693
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
694
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
695
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
696
//MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
697
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
698
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
699
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
700
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
701
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
702
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
703
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
704
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
705
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
706
//MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
707
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
708
//MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
709
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
710
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
711
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
715
587
/* MYSQL_TYPE_BLOB -> */
717
589
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1799
1653
bool Field_new_decimal::store_value(const my_decimal *decimal_value)
1801
ASSERT_COLUMN_MARKED_FOR_WRITE;
1803
DBUG_ENTER("Field_new_decimal::store_value");
1806
char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
1807
DBUG_PRINT("enter", ("value: %s", dbug_decimal_as_string(dbug_buff, decimal_value)));
1811
1657
/* check that we do not try to write negative value in unsigned field */
1812
1658
if (unsigned_flag && decimal_value->sign())
1814
DBUG_PRINT("info", ("unsigned overflow"));
1815
1660
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1817
1662
decimal_value= &decimal_zero;
1821
char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
1822
DBUG_PRINT("info", ("saving with precision %d scale: %d value %s",
1823
(int)precision, (int)dec,
1824
dbug_decimal_as_string(dbug_buff, decimal_value)));
1828
1665
if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1829
1666
decimal_value, ptr, precision, dec)))
1831
1668
my_decimal buff;
1832
DBUG_PRINT("info", ("overflow"));
1833
1669
set_value_on_overflow(&buff, decimal_value->sign());
1834
1670
my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
1837
DBUG_EXECUTE("info", print_decimal_buff(decimal_value, (uchar *) ptr,
1843
1677
int Field_new_decimal::store(const char *from, uint length,
1844
1678
CHARSET_INFO *charset_arg)
1846
ASSERT_COLUMN_MARKED_FOR_WRITE;
1848
1681
my_decimal decimal_value;
1849
DBUG_ENTER("Field_new_decimal::store(char*)");
1851
1683
if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
1852
1684
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
2596
2400
/****************************************************************************
2597
Field type medium int (3 byte)
2598
****************************************************************************/
2600
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
2602
ASSERT_COLUMN_MARKED_FOR_WRITE;
2607
error= get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24);
2608
store_tmp= unsigned_flag ? (int) (uint64_t) rnd : (int) rnd;
2609
int3store(ptr, store_tmp);
2614
int Field_medium::store(double nr)
2616
ASSERT_COLUMN_MARKED_FOR_WRITE;
2624
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2627
else if (nr >= (double) (long) (1L << 24))
2629
uint32 tmp=(uint32) (1L << 24)-1L;
2631
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2635
int3store(ptr,(uint32) nr);
2639
if (nr < (double) INT_MIN24)
2641
long tmp=(long) INT_MIN24;
2643
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2646
else if (nr > (double) INT_MAX24)
2648
long tmp=(long) INT_MAX24;
2650
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2654
int3store(ptr,(long) nr);
2660
int Field_medium::store(longlong nr, bool unsigned_val)
2662
ASSERT_COLUMN_MARKED_FOR_WRITE;
2667
if (nr < 0 && !unsigned_val)
2670
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2673
else if ((uint64_t) nr >= (uint64_t) (long) (1L << 24))
2675
long tmp= (long) (1L << 24)-1L;
2677
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2681
int3store(ptr,(uint32) nr);
2685
if (nr < 0 && unsigned_val)
2686
nr= (uint64_t) (long) (1L << 24); // Generate overflow
2688
if (nr < (longlong) INT_MIN24)
2690
long tmp= (long) INT_MIN24;
2692
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2695
else if (nr > (longlong) INT_MAX24)
2697
long tmp=(long) INT_MAX24;
2699
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2703
int3store(ptr,(long) nr);
2709
double Field_medium::val_real(void)
2711
ASSERT_COLUMN_MARKED_FOR_READ;
2712
long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
2717
longlong Field_medium::val_int(void)
2719
ASSERT_COLUMN_MARKED_FOR_READ;
2720
long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
2721
return (longlong) j;
2725
String *Field_medium::val_str(String *val_buffer,
2726
String *val_ptr __attribute__((unused)))
2728
ASSERT_COLUMN_MARKED_FOR_READ;
2729
CHARSET_INFO *cs= &my_charset_bin;
2731
uint mlength=max(field_length+1,10*cs->mbmaxlen);
2732
val_buffer->alloc(mlength);
2733
char *to=(char*) val_buffer->ptr();
2734
long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
2736
length=(uint) cs->cset->long10_to_str(cs,to,mlength,-10,j);
2737
val_buffer->length(length);
2739
prepend_zeros(val_buffer); /* purecov: inspected */
2744
bool Field_medium::send_binary(Protocol *protocol)
2746
ASSERT_COLUMN_MARKED_FOR_READ;
2747
return protocol->store_long(Field_medium::val_int());
2751
int Field_medium::cmp(const uchar *a_ptr, const uchar *b_ptr)
2764
return (a < b) ? -1 : (a > b) ? 1 : 0;
2767
void Field_medium::sort_string(uchar *to,uint length __attribute__((unused)))
2772
to[0] = (uchar) (ptr[2] ^ 128); /* Revers signbit */
2778
void Field_medium::sql_type(String &res) const
2780
CHARSET_INFO *cs=res.charset();
2781
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2782
"mediumint(%d)",(int) field_length));
2783
add_zerofill_and_unsigned(res);
2786
/****************************************************************************
2788
2402
****************************************************************************/
2790
2404
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
2792
ASSERT_COLUMN_MARKED_FOR_WRITE;
2793
2406
long store_tmp;
3288
2889
Field_real::pack(uchar *to, const uchar *from,
3289
2890
uint max_length, bool low_byte_first)
3291
DBUG_ENTER("Field_real::pack");
3292
DBUG_ASSERT(max_length >= pack_length());
3293
DBUG_PRINT("debug", ("pack_length(): %u", pack_length()));
2892
assert(max_length >= pack_length());
3294
2893
#ifdef WORDS_BIGENDIAN
3295
2894
if (low_byte_first != table->s->db_low_byte_first)
3297
2896
const uchar *dptr= from + pack_length();
3298
2897
while (dptr-- > from)
3304
DBUG_RETURN(Field::pack(to, from, max_length, low_byte_first));
2903
return(Field::pack(to, from, max_length, low_byte_first));
3308
2907
Field_real::unpack(uchar *to, const uchar *from,
3309
2908
uint param_data, bool low_byte_first)
3311
DBUG_ENTER("Field_real::unpack");
3312
DBUG_PRINT("debug", ("pack_length(): %u", pack_length()));
3313
2910
#ifdef WORDS_BIGENDIAN
3314
2911
if (low_byte_first != table->s->db_low_byte_first)
3316
2913
const uchar *dptr= from + pack_length();
3317
2914
while (dptr-- > from)
3319
DBUG_RETURN(from + pack_length());
2916
return(from + pack_length());
3323
DBUG_RETURN(Field::unpack(to, from, param_data, low_byte_first));
2920
return(Field::unpack(to, from, param_data, low_byte_first));
3326
2923
/****************************************************************************