Hi, Sanja!

On Mar 19, [email protected] wrote:
> At file:///home/bell/maria/bzr/work-maria-5.3-MDEV-4292/
> 
> ------------------------------------------------------------
> revno: 3639
> revision-id: [email protected]
> parent: [email protected]
> committer: [email protected]
> branch nick: work-maria-5.3-MDEV-4292
> timestamp: Tue 2013-03-19 12:51:39 +0200
> message:
>   MDEV-4292 fix.
>   
>   Fixed printing column_get finction.
> 
> === modified file 'sql/item_func.cc'
> --- a/sql/item_func.cc        2013-03-18 07:44:24 +0000
> +++ b/sql/item_func.cc        2013-03-19 10:51:39 +0000
> @@ -965,7 +965,11 @@ my_decimal *Item_func_numhybrid::val_dec
>  
>  void Item_func_signed::print(String *str, enum_query_type query_type)
>  {
> -  str->append(STRING_WITH_LEN("cast("));
> +  if (args[0]->type() == FUNC_ITEM &&
> +      ((Item_func *) args[0])->functype() == DYNCOL_GET_FUNC)
> +    str->append(STRING_WITH_LEN("column_get("));
> +  else
> +    str->append(STRING_WITH_LEN("cast("));
>    args[0]->print(str, query_type);
>    str->append(STRING_WITH_LEN(" as signed)"));

So, as I said on irc, I don't quite like it.
An Item should be independent from its arguments are should not
change its name depending on the arguments.

I've considered other approaches, like storing item_cast in the
Item_dyncol_get or inheriting Item_dyncol_get from cast. But they all
complicate the code notably.

So, an easy fix that wouldn't contaminate item_cast, could be

void Item_dyncol_get::print(String *str, enum_query_type query_type)
{
  DBUG_ASSERT(strncmp(str->ptr() - 5, "cast(", 5) == 0); // see 
create_func_dyncol_get

  str->length(str->length() - 5);    // removing "cast("
  str->append(STRING_WITH_LEN("column_get("));
  args[0]->print(str, query_type);
  str->append(',');
  args[1]->print(str, query_type);
  // let the parent cast item add " as <type>)"
}

Regards,
Sergei

_______________________________________________
Mailing list: https://launchpad.net/~maria-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~maria-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to