mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
LTRIM, RTRIM and TRIM now honors coercibility
LTRIM, RTRIM and TRIM now work fine with ucs2
This commit is contained in:
parent
b175a26f44
commit
1ef8b2e34a
4 changed files with 58 additions and 31 deletions
|
@ -266,7 +266,7 @@ Item *create_func_lpad(Item* a, Item *b, Item *c)
|
|||
|
||||
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)
|
||||
|
@ -365,7 +365,7 @@ Item *create_func_rpad(Item* a, Item *b, Item *c)
|
|||
|
||||
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)
|
||||
|
|
|
@ -1136,7 +1136,7 @@ String *Item_func_ltrim::val_str(String *str)
|
|||
return 0; /* purecov: inspected */
|
||||
char buff[MAX_FIELD_WIDTH];
|
||||
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;
|
||||
LINT_INIT(remove_length);
|
||||
|
||||
|
@ -1174,7 +1174,7 @@ String *Item_func_rtrim::val_str(String *str)
|
|||
return 0; /* purecov: inspected */
|
||||
char buff[MAX_FIELD_WIDTH];
|
||||
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;
|
||||
LINT_INIT(remove_length);
|
||||
|
||||
|
@ -1246,7 +1246,7 @@ String *Item_func_trim::val_str(String *str)
|
|||
return 0; /* purecov: inspected */
|
||||
char buff[MAX_FIELD_WIDTH];
|
||||
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;
|
||||
LINT_INIT(remove_length);
|
||||
|
||||
|
@ -1291,6 +1291,29 @@ String *Item_func_trim::val_str(String *str)
|
|||
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()
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -220,37 +220,39 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class Item_func_ltrim :public Item_str_func
|
||||
class Item_func_trim :public Item_str_func
|
||||
{
|
||||
protected:
|
||||
String tmp_value;
|
||||
String remove;
|
||||
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 *);
|
||||
void fix_length_and_dec();
|
||||
const char *func_name() const { return "trim"; }
|
||||
};
|
||||
|
||||
|
||||
class Item_func_ltrim :public Item_func_trim
|
||||
{
|
||||
public:
|
||||
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 *);
|
||||
void fix_length_and_dec() { max_length= args[0]->max_length; }
|
||||
const char *func_name() const { return "ltrim"; }
|
||||
};
|
||||
|
||||
|
||||
class Item_func_rtrim :public Item_str_func
|
||||
class Item_func_rtrim :public Item_func_trim
|
||||
{
|
||||
String tmp_value;
|
||||
public:
|
||||
Item_func_rtrim(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 *);
|
||||
void fix_length_and_dec() { max_length= args[0]->max_length; }
|
||||
const char *func_name() const { return "rtrim"; }
|
||||
};
|
||||
|
||||
class Item_func_trim :public Item_str_func
|
||||
{
|
||||
String tmp_value;
|
||||
public:
|
||||
Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {}
|
||||
String *val_str(String *);
|
||||
void fix_length_and_dec() { max_length= args[0]->max_length; }
|
||||
const char *func_name() const { return "trim"; }
|
||||
};
|
||||
|
||||
|
||||
class Item_func_password :public Item_str_func
|
||||
{
|
||||
|
|
|
@ -593,7 +593,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
|||
%type <item>
|
||||
literal text_literal insert_ident order_ident
|
||||
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
|
||||
param_marker singlerow_subselect singlerow_subselect_init
|
||||
exists_subselect exists_subselect_init
|
||||
|
@ -2479,13 +2479,19 @@ simple_expr:
|
|||
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
|
||||
{ $$= new Item_func_substr_index($3,$5,$7); }
|
||||
| TRIM '(' expr ')'
|
||||
{ $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); }
|
||||
| TRIM '(' LEADING opt_pad FROM expr ')'
|
||||
{ $$= new Item_func_trim($3); }
|
||||
| TRIM '(' LEADING expr FROM expr ')'
|
||||
{ $$= new Item_func_ltrim($6,$4); }
|
||||
| TRIM '(' TRAILING opt_pad FROM expr ')'
|
||||
| TRIM '(' TRAILING expr FROM expr ')'
|
||||
{ $$= new Item_func_rtrim($6,$4); }
|
||||
| TRIM '(' BOTH opt_pad FROM expr ')'
|
||||
| TRIM '(' BOTH expr FROM expr ')'
|
||||
{ $$= 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 ')'
|
||||
{ $$= new Item_func_trim($5,$3); }
|
||||
| TRUNCATE_SYM '(' expr ',' expr ')'
|
||||
|
@ -2707,10 +2713,6 @@ when_list2:
|
|||
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 ')' { $$=$2; }
|
||||
| join_table { $$=$1; }
|
||||
|
|
Loading…
Reference in a new issue