@@ -572,8 +572,7 @@ my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
572572{
573573 DBUG_ASSERT (result_type () == INT_RESULT);
574574 longlong nr= val_int ();
575- if (!is_null ())
576- int2my_decimal (E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
575+ int2my_decimal (E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
577576 return decimal_value;
578577}
579578
@@ -605,7 +604,7 @@ void Field_num::make_field(Send_field *field)
605604 d value for storing
606605
607606 NOTE
608- Field_str is the base class for fields like Field_date, and some
607+ Field_str is the base class for fields like Field_enum, Field_date and some
609608 similar. Some dates use fraction and also string value should be
610609 converted to floating point value according our rules, so we use double
611610 to store value of decimal in string
@@ -629,8 +628,7 @@ my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
629628{
630629 DBUG_ASSERT (result_type () == INT_RESULT);
631630 longlong nr= val_int ();
632- if (is_null ())
633- int2my_decimal (E_DEC_FATAL_ERROR, nr, 0 , decimal_value);
631+ int2my_decimal (E_DEC_FATAL_ERROR, nr, 0 , decimal_value);
634632 return decimal_value;
635633}
636634
@@ -733,6 +731,7 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
733731 return tmp;
734732}
735733
734+
736735/*
737736 SYNOPSIS
738737 Field::quote_data()
@@ -749,44 +748,35 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
749748 void Upon prepending/appending quotes on each side of variable
750749
751750*/
751+
752752bool Field::quote_data (String *unquoted_string)
753753{
754754 char escaped_string[IO_SIZE];
755755 char *unquoted_string_buffer= (char *)(unquoted_string->ptr ());
756756 uint need_quotes;
757-
758757 DBUG_ENTER (" Field::quote_data" );
758+
759759 // this is the same call that mysql_real_escape_string() calls
760760 escape_string_for_mysql (&my_charset_bin, (char *)escaped_string,
761761 unquoted_string->ptr (), unquoted_string->length ());
762762
763-
764- if (is_null ())
765- DBUG_RETURN (0 );
766-
767763 need_quotes= needs_quotes ();
768764
769765 if (need_quotes == 0 )
770- {
771766 DBUG_RETURN (0 );
772- }
773- else
774- {
775- // reset string, then re-append with quotes and escaped values
776- unquoted_string->length (0 );
777- if (unquoted_string->append (" '" ))
778- DBUG_RETURN (1 );
779- if (unquoted_string->append ((char *)escaped_string))
780- DBUG_RETURN (1 );
781- if (unquoted_string->append (" '" ))
782- DBUG_RETURN (1 );
783- }
784- // DBUG_PRINT("Field::quote_data",
785- // ("FINAL quote_flag %d unquoted_string %s escaped_string %s",
786- // needs_quotes, unquoted_string->c_ptr_quick(), escaped_string));
767+
768+ // reset string, then re-append with quotes and escaped values
769+ unquoted_string->length (0 );
770+ if (unquoted_string->append (' \' ' ))
771+ DBUG_RETURN (1 );
772+ if (unquoted_string->append ((char *)escaped_string))
773+ DBUG_RETURN (1 );
774+ if (unquoted_string->append (' \' ' ))
775+ DBUG_RETURN (1 );
787776 DBUG_RETURN (0 );
788777}
789778
779+
790780/*
791781 Quote a field type if needed
792782
@@ -802,6 +792,7 @@ bool Field::quote_data(String *unquoted_string)
802792 0 if value is of type NOT needing quotes
803793 1 if value is of type needing quotes
804794*/
795+
805796bool Field::needs_quotes (void )
806797{
807798 DBUG_ENTER (" Field::type_quote" );
@@ -840,9 +831,9 @@ bool Field::needs_quotes(void)
840831 default : DBUG_RETURN (0 );
841832 }
842833 DBUG_RETURN (0 );
843-
844834}
845835
836+
846837/* ***************************************************************************
847838 Field_null, a field that always return NULL
848839****************************************************************************/
@@ -4646,8 +4637,6 @@ String *Field_newdate::val_str(String *val_buffer,
46464637
46474638bool Field_newdate::get_date (TIME *ltime,uint fuzzydate)
46484639{
4649- if (is_null ())
4650- return 1 ;
46514640 uint32 tmp=(uint32) uint3korr (ptr);
46524641 ltime->day = tmp & 31 ;
46534642 ltime->month = (tmp >> 5 ) & 15 ;
@@ -5058,17 +5047,16 @@ int Field_string::store(longlong nr)
50585047 return Field_string::store (buff,(uint)l,cs);
50595048}
50605049
5050+
50615051int Field_longstr::store_decimal (const my_decimal *d)
50625052{
5063- uint buf_size= my_decimal_string_length (d);
5064- char *buff= (char *)my_alloca (buf_size);
5065- String str (buff, buf_size, &my_charset_bin);
5053+ char buff[DECIMAL_MAX_STR_LENGTH+1 ];
5054+ String str (buff, sizeof (buff), &my_charset_bin);
50665055 my_decimal2string (E_DEC_FATAL_ERROR, d, 0 , 0 , 0 , &str);
5067- int result= store (str.ptr (), str.length (), str.charset ());
5068- my_afree (buff);
5069- return result;
5056+ return store (str.ptr (), str.length (), str.charset ());
50705057}
50715058
5059+
50725060double Field_string::val_real (void )
50735061{
50745062 int not_used;
0 commit comments