bool Item_param::set_from_item(THD *thd, Item *item)
{
  DBUG_ENTER("Item_param::set_from_item");
  m_is_settable_routine_parameter= item->get_settable_routine_parameter();
  if (limit_clause_param)
  {
    longlong val= item->val_int();
    if (item->null_value)
    {
      set_null();
      DBUG_RETURN(false);
    }
    else
    {
      unsigned_flag= item->unsigned_flag;
      set_int(val, MY_INT64_NUM_DECIMAL_DIGITS);
      set_handler_by_result_type(item->result_type());
      DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
    }
  }
  struct st_value tmp;
  if (!item->store(&tmp, 0))
  {
    unsigned_flag= item->unsigned_flag;
    switch (item->cmp_type()) {
    case REAL_RESULT:
      set_double(tmp.value.m_double);
      set_handler_by_field_type(MYSQL_TYPE_DOUBLE);
      break;
    case INT_RESULT:
      set_int(tmp.value.m_longlong, MY_INT64_NUM_DECIMAL_DIGITS);
      set_handler_by_field_type(MYSQL_TYPE_LONGLONG);
      break;
    case STRING_RESULT:
    {
      value.cs_info.set(thd, item->collation.collation);
      /*
        Exact value of max_length is not known unless data is converted to
        charset of connection, so we have to set it later.
      */
      set_handler_by_field_type(MYSQL_TYPE_VARCHAR);

      if (set_str(tmp.m_string.ptr(), tmp.m_string.length()))
        DBUG_RETURN(1);
      break;
    }
    case DECIMAL_RESULT:
    {
      set_decimal(&tmp.m_decimal, unsigned_flag);
      set_handler_by_field_type(MYSQL_TYPE_NEWDECIMAL);
      break;
    }
    case TIME_RESULT:
    {
      set_time(&tmp.value.m_time, item->max_length, item->decimals);
      set_handler(item->type_handler());
      break;
    }
    case ROW_RESULT:
      DBUG_ASSERT(0);
      set_null();
    }
  }
  else
    set_null();

  DBUG_RETURN(0);
}
bool Item_param::set_from_item(THD *thd, Item *item)
{
  DBUG_ENTER("Item_param::set_from_item");
  m_is_settable_routine_parameter= item->get_settable_routine_parameter();
  if (limit_clause_param)
  {
    longlong val= item->val_int();
    if (item->null_value)
    {
      set_null();
      DBUG_RETURN(false);
    }
    else
    {
      unsigned_flag= item->unsigned_flag;
      set_int(val, MY_INT64_NUM_DECIMAL_DIGITS);
      set_handler_by_result_type(item->result_type());
      DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
    }
  }
  struct st_value tmp;
  if (!item->store(&tmp, 0))
  {
    unsigned_flag= item->unsigned_flag;
    switch (item->cmp_type()) {
    case REAL_RESULT:
      set_double(tmp.value.m_double);
      set_handler_by_field_type(MYSQL_TYPE_DOUBLE);
      break;
    case INT_RESULT:
      set_int(tmp.value.m_longlong, MY_INT64_NUM_DECIMAL_DIGITS);
      set_handler_by_field_type(MYSQL_TYPE_LONGLONG);
      break;
    case STRING_RESULT:
    {
      value.cs_info.set(thd, item->collation.collation);
       
      set_handler_by_field_type(MYSQL_TYPE_VARCHAR);

      if (set_str(tmp.m_string.ptr(), tmp.m_string.length()))
        DBUG_RETURN(1);
      break;
    }
    case DECIMAL_RESULT:
    {
      set_decimal(&tmp.m_decimal, unsigned_flag);
      set_handler_by_field_type(MYSQL_TYPE_NEWDECIMAL);
      break;
    }
    case TIME_RESULT:
    {
      set_time(&tmp.value.m_time, item->max_length, item->decimals);
      set_handler(item->type_handler());
      break;
    }
    case ROW_RESULT:
      DBUG_ASSERT(0);
      set_null();
    }
  }
  else
    set_null();

  DBUG_RETURN(0);
}