Commit 8ae717d3 authored by unknown's avatar unknown

LTRIM, RTRIM and TRIM now honors coercibility

LTRIM, RTRIM and TRIM now work fine with ucs2

parent 27d95e96
...@@ -266,7 +266,7 @@ Item *create_func_lpad(Item* a, Item *b, Item *c) ...@@ -266,7 +266,7 @@ Item *create_func_lpad(Item* a, Item *b, Item *c)
Item *create_func_ltrim(Item* a) Item *create_func_ltrim(Item* a)
{ {
return new Item_func_ltrim(a,new Item_string(" ",1,default_charset_info)); return new Item_func_ltrim(a);
} }
Item *create_func_md5(Item* a) Item *create_func_md5(Item* a)
...@@ -365,7 +365,7 @@ Item *create_func_rpad(Item* a, Item *b, Item *c) ...@@ -365,7 +365,7 @@ Item *create_func_rpad(Item* a, Item *b, Item *c)
Item *create_func_rtrim(Item* a) Item *create_func_rtrim(Item* a)
{ {
return new Item_func_rtrim(a,new Item_string(" ",1,default_charset_info)); return new Item_func_rtrim(a);
} }
Item *create_func_sec_to_time(Item* a) Item *create_func_sec_to_time(Item* a)
......
...@@ -1136,7 +1136,7 @@ String *Item_func_ltrim::val_str(String *str) ...@@ -1136,7 +1136,7 @@ String *Item_func_ltrim::val_str(String *str)
return 0; /* purecov: inspected */ return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),res->charset()); String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp); String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove;
uint remove_length; uint remove_length;
LINT_INIT(remove_length); LINT_INIT(remove_length);
...@@ -1174,7 +1174,7 @@ String *Item_func_rtrim::val_str(String *str) ...@@ -1174,7 +1174,7 @@ String *Item_func_rtrim::val_str(String *str)
return 0; /* purecov: inspected */ return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),res->charset()); String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp); String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove;
uint remove_length; uint remove_length;
LINT_INIT(remove_length); LINT_INIT(remove_length);
...@@ -1246,7 +1246,7 @@ String *Item_func_trim::val_str(String *str) ...@@ -1246,7 +1246,7 @@ String *Item_func_trim::val_str(String *str)
return 0; /* purecov: inspected */ return 0; /* purecov: inspected */
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),res->charset()); String tmp(buff,sizeof(buff),res->charset());
String *remove_str=args[1]->val_str(&tmp); String *remove_str= (arg_count==2) ? args[1]->val_str(&tmp) : &remove;
uint remove_length; uint remove_length;
LINT_INIT(remove_length); LINT_INIT(remove_length);
...@@ -1291,6 +1291,29 @@ String *Item_func_trim::val_str(String *str) ...@@ -1291,6 +1291,29 @@ String *Item_func_trim::val_str(String *str)
return &tmp_value; return &tmp_value;
} }
void Item_func_trim::fix_length_and_dec()
{
max_length= args[0]->max_length;
if (arg_count == 1)
{
set_charset(args[0]->charset(), args[0]->coercibility);
remove.set_charset(charset());
remove.set_ascii(" ",1);
}
else
if (set_charset(args[1]->charset(), args[1]->coercibility,
args[0]->charset(), args[0]->coercibility))
{
my_error(ER_CANT_AGGREGATE_COLLATIONS,MYF(0),
args[1]->charset()->name,coercion_name(args[1]->coercibility),
args[0]->charset()->name,coercion_name(args[0]->coercibility),
func_name());
}
}
void Item_func_password::fix_length_and_dec() void Item_func_password::fix_length_and_dec()
{ {
/* /*
......
...@@ -220,35 +220,37 @@ class Item_func_substr_index :public Item_str_func ...@@ -220,35 +220,37 @@ class Item_func_substr_index :public Item_str_func
}; };
class Item_func_ltrim :public Item_str_func class Item_func_trim :public Item_str_func
{ {
protected:
String tmp_value; String tmp_value;
String remove;
public: public:
Item_func_ltrim(Item *a,Item *b) :Item_str_func(a,b) {} Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {}
Item_func_trim(Item *a) :Item_str_func(a) {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; } void fix_length_and_dec();
const char *func_name() const { return "ltrim"; } const char *func_name() const { return "trim"; }
}; };
class Item_func_rtrim :public Item_str_func class Item_func_ltrim :public Item_func_trim
{ {
String tmp_value;
public: public:
Item_func_rtrim(Item *a,Item *b) :Item_str_func(a,b) {} Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {}
Item_func_ltrim(Item *a) :Item_func_trim(a) {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "ltrim"; }
const char *func_name() const { return "rtrim"; }
}; };
class Item_func_trim :public Item_str_func
class Item_func_rtrim :public Item_func_trim
{ {
String tmp_value;
public: public:
Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {} Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {}
Item_func_rtrim(Item *a) :Item_func_trim(a) {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "rtrim"; }
const char *func_name() const { return "trim"; }
}; };
......
...@@ -593,7 +593,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -593,7 +593,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%type <item> %type <item>
literal text_literal insert_ident order_ident literal text_literal insert_ident order_ident
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr table_wild no_in_expr expr_expr simple_expr no_and_expr
using_list expr_or_default set_expr_or_default interval_expr using_list expr_or_default set_expr_or_default interval_expr
param_marker singlerow_subselect singlerow_subselect_init param_marker singlerow_subselect singlerow_subselect_init
exists_subselect exists_subselect_init exists_subselect exists_subselect_init
...@@ -2479,13 +2479,19 @@ simple_expr: ...@@ -2479,13 +2479,19 @@ simple_expr:
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')' | SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_substr_index($3,$5,$7); } { $$= new Item_func_substr_index($3,$5,$7); }
| TRIM '(' expr ')' | TRIM '(' expr ')'
{ $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); } { $$= new Item_func_trim($3); }
| TRIM '(' LEADING opt_pad FROM expr ')' | TRIM '(' LEADING expr FROM expr ')'
{ $$= new Item_func_ltrim($6,$4); } { $$= new Item_func_ltrim($6,$4); }
| TRIM '(' TRAILING opt_pad FROM expr ')' | TRIM '(' TRAILING expr FROM expr ')'
{ $$= new Item_func_rtrim($6,$4); } { $$= new Item_func_rtrim($6,$4); }
| TRIM '(' BOTH opt_pad FROM expr ')' | TRIM '(' BOTH expr FROM expr ')'
{ $$= new Item_func_trim($6,$4); } { $$= new Item_func_trim($6,$4); }
| TRIM '(' LEADING FROM expr ')'
{ $$= new Item_func_ltrim($5); }
| TRIM '(' TRAILING FROM expr ')'
{ $$= new Item_func_rtrim($5); }
| TRIM '(' BOTH FROM expr ')'
{ $$= new Item_func_trim($5); }
| TRIM '(' expr FROM expr ')' | TRIM '(' expr FROM expr ')'
{ $$= new Item_func_trim($5,$3); } { $$= new Item_func_trim($5,$3); }
| TRUNCATE_SYM '(' expr ',' expr ')' | TRUNCATE_SYM '(' expr ',' expr ')'
...@@ -2707,10 +2713,6 @@ when_list2: ...@@ -2707,10 +2713,6 @@ when_list2:
sel->when_list.head()->push_back($5); sel->when_list.head()->push_back($5);
}; };
opt_pad:
/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
| expr { $$=$1; };
join_table_list: join_table_list:
'(' join_table_list ')' { $$=$2; } '(' join_table_list ')' { $$=$2; }
| join_table { $$=$1; } | join_table { $$=$1; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment