diff options
author | Sergei Golubchik <serg@mariadb.org> | 2016-11-27 19:50:10 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-12-12 20:44:41 +0100 |
commit | 180065ebb0db78ea5c955b54c9f7997dbcba3121 (patch) | |
tree | 849adc822b510535367bdffa1153809091fb64df /sql/item_func.cc | |
parent | 1db438c83386e0e58487056d6ea25a0f5e97f4d9 (diff) | |
download | mariadb-git-180065ebb0db78ea5c955b54c9f7997dbcba3121.tar.gz |
Item::print(): remove redundant parentheses
by introducing new Item::precedence() method and using it
to decide whether parentheses are required
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index 64e4db80aa9..9bafe25e431 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -471,16 +471,14 @@ void Item_func::print_args(String *str, uint from, enum_query_type query_type) void Item_func::print_op(String *str, enum_query_type query_type) { - str->append('('); for (uint i=0 ; i < arg_count-1 ; i++) { - args[i]->print(str, query_type); + args[i]->print_parenthesised(str, query_type, precedence()); str->append(' '); str->append(func_name()); str->append(' '); } - args[arg_count-1]->print(str, query_type); - str->append(')'); + args[arg_count-1]->print_parenthesised(str, query_type, precedence()); } @@ -5245,11 +5243,10 @@ bool Item_func_set_user_var::is_null_result() void Item_func_set_user_var::print(String *str, enum_query_type query_type) { - str->append(STRING_WITH_LEN("(@")); + str->append(STRING_WITH_LEN("@")); str->append(name.str, name.length); str->append(STRING_WITH_LEN(":=")); - args[0]->print(str, query_type); - str->append(')'); + args[0]->print_parenthesised(str, query_type, precedence()); } @@ -5259,8 +5256,7 @@ void Item_func_set_user_var::print_as_stmt(String *str, str->append(STRING_WITH_LEN("set @")); str->append(name.str, name.length); str->append(STRING_WITH_LEN(":=")); - args[0]->print(str, query_type); - str->append(')'); + args[0]->print_parenthesised(str, query_type, precedence()); } bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg) @@ -5629,9 +5625,8 @@ bool Item_func_get_user_var::const_item() const void Item_func_get_user_var::print(String *str, enum_query_type query_type) { - str->append(STRING_WITH_LEN("(@")); + str->append(STRING_WITH_LEN("@")); append_identifier(current_thd, str, name.str, name.length); - str->append(')'); } |