bool Item_func_int_val::fix_length_and_dec()
{
  DBUG_ENTER("Item_func_int_val::fix_length_and_dec");
  DBUG_PRINT("info", ("name %s", func_name()));

  ulonglong tmp_max_length= (ulonglong ) args[0]->max_length - 
    (args[0]->decimals ? args[0]->decimals + 1 : 0) + 2;
  max_length= tmp_max_length > (ulonglong) 4294967295U ?
    (uint32) 4294967295U : (uint32) tmp_max_length;
  uint tmp= float_length(decimals);
  set_if_smaller(max_length,tmp);
  decimals= 0;

  // Note, cast_to_int_type() can return TIME_RESULT
  switch (args[0]->cast_to_int_type())
  {
  case STRING_RESULT:
  case REAL_RESULT:
    set_handler_by_result_type(REAL_RESULT);
    max_length= float_length(decimals);
    break;
  case INT_RESULT:
  case TIME_RESULT:
  case DECIMAL_RESULT:
    /*
      -2 because in most high position can't be used any digit for longlong
      and one position for increasing value during operation
    */
    if ((args[0]->max_length - args[0]->decimals) >=
        (DECIMAL_LONGLONG_DIGITS - 2))
    {
      fix_char_length(
        my_decimal_precision_to_length_no_truncation(
          args[0]->decimal_int_part(), 0, false));
      set_handler_by_result_type(DECIMAL_RESULT);
    }
    else
    {
      unsigned_flag= args[0]->unsigned_flag;
      set_handler_by_result_type(INT_RESULT);
    }
    break;
  case ROW_RESULT:
    DBUG_ASSERT(0);
  }
  DBUG_PRINT("info", ("Type: %s",
                      (result_type() == REAL_RESULT ? "REAL_RESULT" :
                       result_type() == DECIMAL_RESULT ? "DECIMAL_RESULT" :
                       result_type() == INT_RESULT ? "INT_RESULT" :
                       "--ILLEGAL!!!--")));

  DBUG_RETURN(FALSE);
}
bool Item_func_int_val::fix_length_and_dec()
{
  DBUG_ENTER("Item_func_int_val::fix_length_and_dec");
  DBUG_PRINT("info", ("name %s", func_name()));

  ulonglong tmp_max_length= (ulonglong ) args[0]->max_length - 
    (args[0]->decimals ? args[0]->decimals + 1 : 0) + 2;
  max_length= tmp_max_length > (ulonglong) 4294967295U ?
    (uint32) 4294967295U : (uint32) tmp_max_length;
  uint tmp= float_length(decimals);
  set_if_smaller(max_length,tmp);
  decimals= 0;

   
  switch (args[0]->cast_to_int_type())
  {
  case STRING_RESULT:
  case REAL_RESULT:
    set_handler_by_result_type(REAL_RESULT);
    max_length= float_length(decimals);
    break;
  case INT_RESULT:
  case TIME_RESULT:
  case DECIMAL_RESULT:
     
    if ((args[0]->max_length - args[0]->decimals) >=
        (DECIMAL_LONGLONG_DIGITS - 2))
    {
      fix_char_length(
        my_decimal_precision_to_length_no_truncation(
          args[0]->decimal_int_part(), 0, false));
      set_handler_by_result_type(DECIMAL_RESULT);
    }
    else
    {
      unsigned_flag= args[0]->unsigned_flag;
      set_handler_by_result_type(INT_RESULT);
    }
    break;
  case ROW_RESULT:
    DBUG_ASSERT(0);
  }
  DBUG_PRINT("info", ("Type: %s",
                      (result_type() == REAL_RESULT ? "REAL_RESULT" :
                       result_type() == DECIMAL_RESULT ? "DECIMAL_RESULT" :
                       result_type() == INT_RESULT ? "INT_RESULT" :
                       "--ILLEGAL!!!--")));

  DBUG_RETURN(FALSE);
}