summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <bar@bar.mysql.r18.ru>2002-08-22 18:12:45 +0500
committerunknown <bar@bar.mysql.r18.ru>2002-08-22 18:12:45 +0500
commit56e866ae05fda040fb04edf172c5651f577a3d46 (patch)
tree365e0d1f5734b8487f86b90852d63beaf62dd8d0 /sql
parent08a32ab1b12ec34bdf8f0e5da3bdffb6423884a2 (diff)
downloadmariadb-git-56e866ae05fda040fb04edf172c5651f577a3d46.tar.gz
Stupid bug fixes in sql_yacc.cc
New class Item_func_set_collation() Fixed that "SELECT CONVERT(expr USING charset) GROUP BY 1" was not working New COLLATION syntax: <expr> COLLATE latin1 mysql-test/r/ctype_many.result: New test slot has been added mysql-test/t/ctype_many.test: New test slot has been added sql/item_strfunc.cc: "SELECT CONVERT(expr USING another_charset) GROUP BY 1" was not working as expected New Item_func_set_collation class sql/item_strfunc.h: "SELECT CONVERT(expr USING another_charset) GROUP BY 1" was not working as expected New Item_func_set_collation class sql/lex.h: New keyword sql/sql_yacc.yy: Stupid bug fixes COLLATION syntax
Diffstat (limited to 'sql')
-rw-r--r--sql/item_strfunc.cc29
-rw-r--r--sql/item_strfunc.h22
-rw-r--r--sql/lex.h1
-rw-r--r--sql/sql_yacc.yy18
4 files changed, 62 insertions, 8 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 1aee4e7d553..b5b9ed2931e 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1843,9 +1843,11 @@ outp:
void Item_func_conv_charset::fix_length_and_dec()
{
max_length = args[0]->max_length*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1);
+ str_value.set_charset(conv_charset);
}
+
String *Item_func_conv_charset3::val_str(String *str)
{
my_wc_t wc;
@@ -1938,6 +1940,33 @@ void Item_func_conv_charset3::fix_length_and_dec()
max_length = args[0]->max_length;
}
+String *Item_func_set_collation::val_str(String *str)
+{
+ str=args[0]->val_str(str);
+ null_value=args[0]->null_value;
+ str->set_charset(set_collation);
+ return str;
+}
+
+bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables)
+{
+ char buff[STACK_BUFF_ALLOC]; // Max argument in function
+ binary=0;
+ used_tables_cache=0;
+ const_item_cache=1;
+
+ if (thd && check_stack_overrun(thd,buff))
+ return 0; // Fatal error if flag is set!
+ if (args[0]->fix_fields(thd, tables, args))
+ return 1;
+ maybe_null=args[0]->maybe_null;
+ binary=args[0]->binary;
+ const_item_cache=args[0]->const_item();
+ str_value.set_charset(set_collation);
+ fix_length_and_dec();
+ return 0;
+}
+
String *Item_func_charset::val_str(String *str)
{
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 7b5bd7ae90b..7f82cd3b5de 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -472,7 +472,7 @@ class Item_func_export_set: public Item_str_func
const char *func_name() const { return "export_set"; }
};
- class Item_func_inet_ntoa : public Item_str_func
+class Item_func_inet_ntoa : public Item_str_func
{
public:
Item_func_inet_ntoa(Item *a) :Item_str_func(a)
@@ -488,15 +488,29 @@ class Item_func_conv_charset :public Item_str_func
CHARSET_INFO *conv_charset;
public:
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
- {
- conv_charset=cs;
- }
+ { conv_charset=cs; }
bool fix_fields(THD *thd,struct st_table_list *tables);
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "conv_charset"; }
};
+class Item_func_set_collation :public Item_str_func
+{
+ CHARSET_INFO *set_collation;
+public:
+ Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
+ { set_collation=cs; }
+ bool fix_fields(THD *thd,struct st_table_list *tables);
+ String *val_str(String *);
+ void fix_length_and_dec()
+ {
+ max_length = args[0]->max_length;
+ str_value.set_charset(set_collation);
+ }
+ const char *func_name() const { return "set_collation"; }
+};
+
class Item_func_conv_charset3 :public Item_str_func
{
public:
diff --git a/sql/lex.h b/sql/lex.h
index c41ad8c1d44..cd25c3883fe 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -89,6 +89,7 @@ static SYMBOL symbols[] = {
{ "CHECKSUM", SYM(CHECKSUM_SYM),0,0},
{ "CIPHER", SYM(CIPHER_SYM),0,0},
{ "CLOSE", SYM(CLOSE_SYM),0,0},
+ { "COLLATE", SYM(COLLATE_SYM),0,0},
{ "COLUMN", SYM(COLUMN_SYM),0,0},
{ "COLUMNS", SYM(COLUMNS),0,0},
{ "COMMENT", SYM(COMMENT_SYM),0,0},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 160bc253dc9..01894bfb7ad 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -167,6 +167,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token CHECK_SYM
%token CIPHER
%token COMMITTED_SYM
+%token COLLATE_SYM
%token COLUMNS
%token COLUMN_SYM
%token CONCURRENT
@@ -522,7 +523,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%left '*' '/' '%'
%left NEG '~'
%right NOT
-%right BINARY
+%right BINARY COLLATE_SYM
%type <lex_str>
IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
@@ -1129,7 +1130,7 @@ charset:
{
if (!(Lex->charset=get_charset_by_name($1.str,MYF(0))))
{
- net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$1);
+ net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$1.str);
YYABORT;
}
};
@@ -1658,7 +1659,16 @@ expr_expr:
| expr '+' INTERVAL_SYM expr interval
{ $$= new Item_date_add_interval($1,$4,$5,0); }
| expr '-' INTERVAL_SYM expr interval
- { $$= new Item_date_add_interval($1,$4,$5,1); };
+ { $$= new Item_date_add_interval($1,$4,$5,1); }
+ | expr COLLATE_SYM ident
+ {
+ if (!(Lex->charset=get_charset_by_name($3.str,MYF(0))))
+ {
+ net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$3.str);
+ YYABORT;
+ }
+ $$= new Item_func_set_collation($1,Lex->charset);
+ };
/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
@@ -3446,7 +3456,7 @@ option_value:
CONVERT *tmp;
if (!(tmp=get_convert_set($3.str)))
{
- net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$3);
+ net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$3.str);
YYABORT;
}
current_thd->convert_set=tmp;