summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2002-01-03 00:46:43 +0200
committerunknown <monty@hundin.mysql.fi>2002-01-03 00:46:43 +0200
commitb79170b7fd6b77bbc6cc083fbcaa13faf7f02f92 (patch)
tree4e18e3ee4d74189f2a784d419334e02f025eacd1 /sql
parent301cdf9f240106978b04d4f8044b24e4a3fa6d00 (diff)
downloadmariadb-git-b79170b7fd6b77bbc6cc083fbcaa13faf7f02f92.tar.gz
New CAST syntax
Cleanup of multi-table-delete in sql_yacc.yy Changed syntax of MAXIMUM QUERIES PER HOUR to MAX_QUERIES_PER_HOUR to not get too many reserved words. Docs/manual.texi: Updated information about CAST mysql-test/r/bigint.result: New CAST syntax mysql-test/r/create.result: New CAST syntax mysql-test/r/variables.result: Fix after merge with 3.23 mysql-test/t/bigint.test: New CAST syntax mysql-test/t/create.test: New CAST syntax sql/item_create.cc: New CAST syntax sql/item_func.h: New CAST syntax sql/item_timefunc.cc: New CAST syntax sql/item_timefunc.h: New CAST syntax sql/lex.h: Changed syntax to MAX_QUERIES_PER_HOUR to not get too many reserved words. sql/mysql_priv.h: Cleanup multi-delete sql/sql_parse.cc: Cleanup multi-delete sql/sql_yacc.yy: Cleanup multi-delete. New CAST syntax. Removed some restricted words.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_create.cc15
-rw-r--r--sql/item_func.h9
-rw-r--r--sql/item_timefunc.cc10
-rw-r--r--sql/item_timefunc.h33
-rw-r--r--sql/lex.h9
-rw-r--r--sql/mysql_priv.h1
-rw-r--r--sql/sql_parse.cc10
-rw-r--r--sql/sql_yacc.yy103
8 files changed, 104 insertions, 86 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc
index a9567414b0b..4b60ad1bf56 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -393,3 +393,18 @@ Item *create_wait_for_master_pos(Item* a, Item* b)
current_thd->safe_to_cache_query=0;
return new Item_master_pos_wait(a, b);
}
+
+Item *create_func_cast(Item *a, Item_cast cast_type)
+{
+ Item *res;
+ LINT_INIT(res);
+ switch (cast_type) {
+ case ITEM_CAST_BINARY: res= new Item_func_binary(a); break;
+ case ITEM_CAST_SIGNED_INT: res= new Item_func_signed(a); break;
+ case ITEM_CAST_UNSIGNED_INT: res= new Item_func_unsigned(a); break;
+ case ITEM_CAST_DATE: res= new Item_date_typecast(a); break;
+ case ITEM_CAST_TIME: res= new Item_time_typecast(a); break;
+ case ITEM_CAST_DATETIME: res= new Item_datetime_typecast(a); break;
+ }
+ return res;
+}
diff --git a/sql/item_func.h b/sql/item_func.h
index d1d836db67b..91fd6cdcc26 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -952,3 +952,12 @@ public:
const char *func_name() const { return "match_bool"; }
};
+/* For type casts */
+
+enum Item_cast
+{
+ ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
+ ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME
+};
+
+Item *create_func_cast(Item *a, Item_cast cast_type);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 2b1bb9cae0e..9c29b594621 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1123,3 +1123,13 @@ longlong Item_extract::val_int()
}
return 0; // Impossible
}
+
+
+void Item_typecast::print(String *str)
+{
+ str->append("CASE(");
+ args[0]->print(str);
+ str->append(" AS ");
+ str->append(func_name());
+ str->append(')');
+}
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index b824174edf0..c9daa2316e8 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -414,14 +414,21 @@ class Item_extract :public Item_int_func
void fix_length_and_dec();
};
-class Item_date_typecast :public Item_str_func
+class Item_typecast :public Item_str_func
{
public:
- Item_date_typecast(Item *a) :Item_str_func(a) {}
- const char *func_name() const { return "date_typecast"; }
+ Item_typecast(Item *a) :Item_str_func(a) {}
String *val_str(String *a) { return (args[0]->val_str(a)); }
void fix_length_and_dec() { max_length=args[0]->max_length; }
- void print(String *str) { print_op(str); }
+ void print(String *str);
+};
+
+
+class Item_date_typecast :public Item_typecast
+{
+public:
+ Item_date_typecast(Item *a) :Item_typecast(a) {}
+ const char *func_name() const { return "date"; }
void make_field(Send_field *tmp_field)
{
init_make_field(tmp_field,FIELD_TYPE_DATE);
@@ -433,14 +440,11 @@ public:
}
};
-class Item_time_typecast :public Item_str_func
+class Item_time_typecast :public Item_typecast
{
public:
- Item_time_typecast(Item *a) :Item_str_func(a) {}
- const char *func_name() const { return "time_typecast"; }
- String *val_str(String *a) { return (args[0]->val_str(a)); }
- void fix_length_and_dec() { max_length=args[0]->max_length; }
- void print(String *str) { print_op(str); }
+ Item_time_typecast(Item *a) :Item_typecast(a) {}
+ const char *func_name() const { return "time"; }
void make_field(Send_field *tmp_field)
{
init_make_field(tmp_field,FIELD_TYPE_TIME);
@@ -452,14 +456,11 @@ public:
}
};
-class Item_datetime_typecast :public Item_str_func
+class Item_datetime_typecast :public Item_typecast
{
public:
- Item_datetime_typecast(Item *a) :Item_str_func(a) {}
- const char *func_name() const { return "datetime_typecast"; }
- String *val_str(String *a) { return (args[0]->val_str(a)); }
- void fix_length_and_dec() { max_length=args[0]->max_length; }
- void print(String *str) { print_op(str); }
+ Item_datetime_typecast(Item *a) :Item_typecast(a) {}
+ const char *func_name() const { return "datetime"; }
void make_field(Send_field *tmp_field)
{
init_make_field(tmp_field,FIELD_TYPE_DATETIME);
diff --git a/sql/lex.h b/sql/lex.h
index 3b91a0b35ef..c2664e4e8c0 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -228,7 +228,7 @@ static SYMBOL symbols[] = {
{ "MASTER_SERVER_ID", SYM(MASTER_SERVER_ID_SYM),0,0},
{ "MASTER_USER", SYM(MASTER_USER_SYM),0,0},
{ "MAX_ROWS", SYM(MAX_ROWS),0,0},
- { "MAXIMUM", SYM(MAXIMUM),0,0},
+ { "MAX_QUERIES_PER_HOUR", SYM(MAX_QUERIES_PER_HOUR), 0,0},
{ "MATCH", SYM(MATCH),0,0},
{ "MEDIUMBLOB", SYM(MEDIUMBLOB),0,0},
{ "MEDIUMTEXT", SYM(MEDIUMTEXT),0,0},
@@ -242,7 +242,6 @@ static SYMBOL symbols[] = {
{ "MODE", SYM(MODE_SYM),0,0},
{ "MODIFY", SYM(MODIFY_SYM),0,0},
{ "MONTH", SYM(MONTH_SYM),0,0},
- { "MQH", SYM(MQH_SYM),0,0},
{ "MRG_MYISAM", SYM(MERGE_SYM),0,0},
{ "MYISAM", SYM(MYISAM_SYM),0,0},
{ "NATURAL", SYM(NATURAL),0,0},
@@ -267,7 +266,6 @@ static SYMBOL symbols[] = {
{ "PACK_KEYS", SYM(PACK_KEYS_SYM),0,0},
{ "PARTIAL", SYM(PARTIAL),0,0},
{ "PASSWORD", SYM(PASSWORD),0,0},
- { "PER", SYM(PER_SYM),0,0},
{ "PURGE", SYM(PURGE),0,0},
{ "PRECISION", SYM(PRECISION),0,0},
{ "PREV", SYM(PREV_SYM),0,0},
@@ -276,7 +274,6 @@ static SYMBOL symbols[] = {
{ "PROCESS" , SYM(PROCESS),0,0},
{ "PROCESSLIST", SYM(PROCESSLIST_SYM),0,0},
{ "PRIVILEGES", SYM(PRIVILEGES),0,0},
- { "QUERIES", SYM(QUERIES),0,0},
{ "QUERY", SYM(QUERY_SYM),0,0},
{ "QUICK", SYM(QUICK),0,0},
{ "RAID0", SYM(RAID_0_SYM),0,0},
@@ -305,7 +302,7 @@ static SYMBOL symbols[] = {
{ "SERIALIZABLE", SYM(SERIALIZABLE_SYM),0,0},
{ "SESSION", SYM(SESSION_SYM),0,0},
{ "SET", SYM(SET),0,0},
- { "SIGNED", SYM(SIGNED),0,0},
+ { "SIGNED", SYM(SIGNED_SYM),0,0},
{ "SHARE", SYM(SHARE_SYM),0,0},
{ "SHOW", SYM(SHOW),0,0},
{ "SHUTDOWN", SYM(SHUTDOWN),0,0},
@@ -397,6 +394,7 @@ static SYMBOL sql_functions[] = {
{ "BIT_COUNT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_count)},
{ "BIT_OR", SYM(BIT_OR),0,0},
{ "BIT_AND", SYM(BIT_AND),0,0},
+ { "CAST", SYM(CAST_SYM),0,0},
{ "CEILING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "CHAR_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
@@ -405,6 +403,7 @@ static SYMBOL sql_functions[] = {
{ "CONCAT_WS", SYM(CONCAT_WS),0,0},
{ "CONNECTION_ID", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)},
{ "CONV", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)},
+ { "CONVERT", SYM(CONVERT_SYM),0,0},
{ "COUNT", SYM(COUNT_SYM),0,0},
{ "COS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
{ "COT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index ba39199a1ad..d7ec5917047 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -264,6 +264,7 @@ bool mysql_change_db(THD *thd,const char *name);
void mysql_parse(THD *thd,char *inBuf,uint length);
void mysql_init_select(LEX *lex);
bool mysql_new_select(LEX *lex);
+void mysql_init_multi_delete(LEX *lex);
void init_max_user_conn(void);
void free_max_user_conn(void);
pthread_handler_decl(handle_one_connection,arg);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 2f2e3deaa0d..2fbdf05e826 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2665,6 +2665,16 @@ mysql_new_select(LEX *lex)
return 0;
}
+void mysql_init_multi_delete(LEX *lex)
+{
+ lex->sql_command = SQLCOM_DELETE_MULTI;
+ mysql_init_select(lex);
+ lex->select->select_limit=HA_POS_ERROR;
+ lex->auxilliary_table_list=lex->select_lex.table_list;
+ lex->select->table_list.elements=0;
+ lex->select->table_list.first=0;
+ lex->select->table_list.next= (byte**) &(lex->select->table_list.first);
+}
void
mysql_parse(THD *thd,char *inBuf,uint length)
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index fc2432d5c03..1b0ef545f98 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+/* Copyright (C) 2000-2001 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -58,6 +58,7 @@ inline Item *or_or_concat(Item* A, Item* B)
enum row_type row_type;
enum ha_rkey_function ha_rkey_mode;
enum enum_tx_isolation tx_isolation;
+ enum Item_cast cast_type;
String *string;
key_part_spec *key_part;
TABLE_LIST *table_list;
@@ -81,11 +82,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token NEXT_SYM
%token PREV_SYM
%token SQL_CALC_FOUND_ROWS
-%token QUERIES
-%token MQH_SYM
-%token PER_SYM
-%token MAXIMUM
-
%token EQ
%token EQUAL_SYM
@@ -161,6 +157,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token BY
%token CACHE_SYM
%token CASCADE
+%token CAST_SYM
%token CHECKSUM_SYM
%token CHECK_SYM
%token CIPHER
@@ -169,6 +166,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token COLUMN_SYM
%token CONCURRENT
%token CONSTRAINT
+%token CONVERT_SYM
%token DATABASES
%token DATA_SYM
%token DEFAULT
@@ -243,6 +241,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token MASTER_SERVER_ID_SYM
%token MATCH
%token MAX_ROWS
+%token MAX_QUERIES_PER_HOUR
%token MEDIUM_SYM
%token MERGE_SYM
%token MIN_ROWS
@@ -356,7 +355,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token PRECISION
%token QUICK
%token REAL
-%token SIGNED
+%token SIGNED_SYM
%token SMALLINT
%token STRING_SYM
%token TEXT_SYM
@@ -487,11 +486,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%left NEG '~'
%right NOT
%right BINARY
-%right SIGNED
-%right UNSIGNED
-%right DATE_SYM
-%right TIME_SYM
-%right DATETIME
%type <lex_str>
IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
@@ -556,6 +550,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%type <ha_rkey_mode> handler_rkey_mode
+%type <cast_type> cast_type
+
%type <udf_type> udf_func_type
%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword
@@ -1020,7 +1016,7 @@ field_opt_list:
| field_option {}
field_option:
- SIGNED {}
+ SIGNED_SYM {}
| UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
| ZEROFILL { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
@@ -1607,14 +1603,11 @@ simple_expr:
| MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
{ Select->ftfunc_list.push_back((Item_func_match *)
($$=new Item_func_match_bool(*$2,$5))); }
- | BINARY expr %prec NEG { $$= new Item_func_binary($2); }
- | SIGNED expr %prec NEG { $$= new Item_func_signed($2); }
- | UNSIGNED expr %prec NEG { $$= new Item_func_unsigned($2); }
- | DATE_SYM expr { $$= new Item_date_typecast($2); }
- | TIME_SYM expr { $$= new Item_time_typecast($2); }
- | DATETIME expr { $$= new Item_datetime_typecast($2); }
+ | BINARY expr %prec NEG { $$= new Item_func_binary($2); }
+ | CAST_SYM '(' expr AS cast_type ')' { $$= create_func_cast($3, $5); }
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
{ $$= new Item_func_case(* $4, $2, $5 ) }
+ | CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); }
| FUNC_ARG0 '(' ')'
{ $$= ((Item*(*)(void))($1.symbol->create_func))();}
| FUNC_ARG1 '(' expr ')'
@@ -1886,6 +1879,16 @@ in_sum_expr:
$$=$2;
}
+cast_type:
+ BINARY { $$=ITEM_CAST_BINARY; }
+ | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; }
+ | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; }
+ | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; }
+ | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; }
+ | DATE_SYM { $$=ITEM_CAST_DATE; }
+ | TIME_SYM { $$=ITEM_CAST_TIME; }
+ | DATETIME { $$=ITEM_CAST_DATETIME; }
+
expr_list:
{ Select->expr_list.push_front(new List<Item>); }
expr_list2
@@ -2113,9 +2116,10 @@ opt_order_clause:
order_clause:
ORDER_SYM BY
{
- if (Lex->sql_command==SQLCOM_MULTI_UPDATE)
+ LEX *lex=Lex;
+ if (lex->sql_command == SQLCOM_MULTI_UPDATE)
YYABORT;
- Select->sort_default=1;
+ lex->select->sort_default=1;
} order_list
order_list:
@@ -2135,7 +2139,8 @@ limit_clause:
| LIMIT ULONG_NUM
{
SELECT_LEX *sel=Select;
- sel->select_limit= $2; sel->offset_limit=0L;
+ sel->select_limit= $2;
+ sel->offset_limit=0L;
}
| LIMIT ULONG_NUM ',' ULONG_NUM
{
@@ -2146,9 +2151,10 @@ limit_clause:
delete_limit_clause:
/* empty */
{
- if (Lex->sql_command==SQLCOM_MULTI_UPDATE)
+ LEX *lex=Lex;
+ if (lex->sql_command == SQLCOM_MULTI_UPDATE)
YYABORT;
- Select->select_limit= HA_POS_ERROR;
+ lex->select->select_limit= HA_POS_ERROR;
}
| LIMIT ulonglong_num
{ Select->select_limit= (ha_rows) $2; }
@@ -2438,42 +2444,11 @@ delete:
single_multi:
FROM table_name where_clause opt_order_clause delete_limit_clause {}
| table_wild_list
- {
- LEX *lex=Lex;
- lex->sql_command = SQLCOM_DELETE_MULTI;
- mysql_init_select(lex);
- lex->select->select_limit=HA_POS_ERROR;
- lex->auxilliary_table_list.elements=0;
- lex->auxilliary_table_list.first=0;
- lex->auxilliary_table_list.next= (byte**) &(lex->auxilliary_table_list.first);
- }
- FROM
- {
- LEX *lex=Lex;
- lex->auxilliary_table_list=lex->select_lex.table_list;
- lex->select->table_list.elements=0;
- lex->select->table_list.first=0;
- lex->select->table_list.next= (byte**) &(lex->select->table_list.first);
- } join_table_list where_clause
- | FROM table_wild_list
- {
- LEX *lex=Lex;
- lex->sql_command = SQLCOM_DELETE_MULTI;
- mysql_init_select(lex);
- lex->select->select_limit=HA_POS_ERROR;
- lex->auxilliary_table_list.elements=0;
- lex->auxilliary_table_list.first=0;
- lex->auxilliary_table_list.next= (byte**) &(lex->auxilliary_table_list.first);
- }
- USING
- {
- LEX *lex=Lex;
- lex->auxilliary_table_list=lex->select_lex.table_list;
- lex->select->table_list.elements=0;
- lex->select->table_list.first=0;
- lex->select->table_list.next= (byte**) &(lex->select->table_list.first);
- } join_table_list where_clause
-
+ { mysql_init_multi_delete(Lex); }
+ FROM join_table_list where_clause
+ | FROM table_wild_list
+ { mysql_init_multi_delete(Lex); }
+ USING join_table_list where_clause
table_wild_list:
table_wild_one {}
@@ -3019,6 +2994,7 @@ keyword:
| MASTER_USER_SYM {}
| MASTER_PASSWORD_SYM {}
| MASTER_CONNECT_RETRY_SYM {}
+ | MAX_QUERIES_PER_HOUR {}
| MEDIUM_SYM {}
| MERGE_SYM {}
| MINUTE_SYM {}
@@ -3058,6 +3034,7 @@ keyword:
| SECOND_SYM {}
| SERIALIZABLE_SYM {}
| SESSION_SYM {}
+ | SIGNED_SYM {}
| SHARE_SYM {}
| SHUTDOWN {}
| SLAVE {}
@@ -3607,17 +3584,13 @@ grant_option:
mqh_option:
/* empty */ {}
- | AND WITH short_or_long_one EQ NUM
+ | AND WITH MAX_QUERIES_PER_HOUR EQ NUM
{
Lex->mqh=atoi($5.str);
if (Lex->mqh > 65535)
YYABORT;
}
-short_or_long_one:
- MQH_SYM
- | MAXIMUM QUERIES PER_SYM HOUR_SYM
-
begin:
BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work