Commit dfb60ca0 authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Added new ANSI functions LOCALTIME, LOCALTIMESTAMP and CURRENT_USER

Added CEIL as an alias for CEILING
Cleaned up CHECK constraint handling.
(We don't anymore require braces after CHECK)
Added casting to CHAR.
parent e60050c4
...@@ -52,24 +52,3 @@ select min(big),max(big),max(big)-1 from t1 group by a; ...@@ -52,24 +52,3 @@ select min(big),max(big),max(big)-1 from t1 group by a;
min(big) max(big) max(big)-1 min(big) max(big) max(big)-1
-1 9223372036854775807 9223372036854775806 -1 9223372036854775807 9223372036854775806
drop table t1; drop table t1;
select CAST(1-2 AS UNSIGNED);
CAST(1-2 AS UNSIGNED)
18446744073709551615
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER)
-1
select CONVERT('-1',UNSIGNED);
CONVERT('-1',UNSIGNED)
18446744073709551615
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
cast(-5 as unsigned) | 1 cast(-5 as unsigned) & -1
18446744073709551611 18446744073709551611
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
cast(-5 as unsigned) -1 cast(-5 as unsigned) + 1
18446744073709551610 18446744073709551612
select ~5, cast(~5 as signed);
~5 cast(~5 as signed)
18446744073709551610 -6
select cast(5 as unsigned) -6.0;
cast(5 as unsigned) -6.0
-1.0
select CAST(1-2 AS UNSIGNED);
CAST(1-2 AS UNSIGNED)
18446744073709551615
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER)
-1
select CONVERT('-1',UNSIGNED);
CONVERT('-1',UNSIGNED)
18446744073709551615
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
cast(-5 as unsigned) | 1 cast(-5 as unsigned) & -1
18446744073709551611 18446744073709551611
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
cast(-5 as unsigned) -1 cast(-5 as unsigned) + 1
18446744073709551610 18446744073709551612
select ~5, cast(~5 as signed);
~5 cast(~5 as signed)
18446744073709551610 -6
select cast(5 as unsigned) -6.0;
cast(5 as unsigned) -6.0
-1.0
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
cast("A" as binary) = "a" cast(BINARY "a" as CHAR) = "A"
0 1
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME)
2001-1-1 2001-1-1
select cast("1:2:3" as TIME);
cast("1:2:3" as TIME)
1:2:3
select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01"
0
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"
0
select cast("1:2:3" as TIME) = "1:02:03";
cast("1:2:3" as TIME) = "1:02:03"
0
drop table if exists t1;
create table t1 (a int check (a>0));
insert into t1 values (1);
insert into t1 values (0);
drop table t1;
create table t1 (a int ,b int, check a>b);
insert into t1 values (1,0);
insert into t1 values (0,1);
drop table t1;
create table t1 (a int ,b int, constraint abc check (a>b));
insert into t1 values (1,0);
insert into t1 values (0,1);
drop table t1;
create table t1 (a int null);
insert into t1 values (1),(NULL);
drop table t1;
...@@ -24,6 +24,12 @@ now()-curdate()*1000000-curtime() ...@@ -24,6 +24,12 @@ now()-curdate()*1000000-curtime()
select strcmp(current_timestamp(),concat(current_date()," ",current_time())); select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
strcmp(current_timestamp(),concat(current_date()," ",current_time())) strcmp(current_timestamp(),concat(current_date()," ",current_time()))
0 0
select strcmp(localtime(),concat(current_date()," ",current_time()));
strcmp(localtime(),concat(current_date()," ",current_time()))
0
select strcmp(localtimestamp(),concat(current_date()," ",current_time()));
strcmp(localtimestamp(),concat(current_date()," ",current_time()))
0
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"); select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w") date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")
January Thursday 2nd 1997 97 01 02 03 04 05 4 January Thursday 2nd 1997 97 01 02 03 04 05 4
......
...@@ -35,11 +35,3 @@ alter table t1 modify big bigint not null; ...@@ -35,11 +35,3 @@ alter table t1 modify big bigint not null;
select min(big),max(big),max(big)-1 from t1; select min(big),max(big),max(big)-1 from t1;
select min(big),max(big),max(big)-1 from t1 group by a; select min(big),max(big),max(big)-1 from t1 group by a;
drop table t1; drop table t1;
select CAST(1-2 AS UNSIGNED);
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
select CONVERT('-1',UNSIGNED);
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
select ~5, cast(~5 as signed);
select cast(5 as unsigned) -6.0;
#
# Test of cast function
#
select CAST(1-2 AS UNSIGNED);
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
select CONVERT('-1',UNSIGNED);
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
select ~5, cast(~5 as signed);
select cast(5 as unsigned) -6.0;
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
select cast("1:2:3" as TIME);
#
# The following should be fixed in 4.1
#
select cast("2001-1-1" as date) = "2001-01-01";
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
select cast("1:2:3" as TIME) = "1:02:03";
#
# Testing of constraints
# Currently MySQL only ignores the syntax.
#
drop table if exists t1;
create table t1 (a int check (a>0));
insert into t1 values (1);
insert into t1 values (0);
drop table t1;
create table t1 (a int ,b int, check a>b);
insert into t1 values (1,0);
insert into t1 values (0,1);
drop table t1;
create table t1 (a int ,b int, constraint abc check (a>b));
insert into t1 values (1,0);
insert into t1 values (0,1);
drop table t1;
create table t1 (a int null);
insert into t1 values (1),(NULL);
drop table t1;
...@@ -12,6 +12,8 @@ select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"), ...@@ -12,6 +12,8 @@ select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"),
select sec_to_time(time_to_sec('-838:59:59')); select sec_to_time(time_to_sec('-838:59:59'));
select now()-curdate()*1000000-curtime(); select now()-curdate()*1000000-curtime();
select strcmp(current_timestamp(),concat(current_date()," ",current_time())); select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
select strcmp(localtime(),concat(current_date()," ",current_time()));
select strcmp(localtimestamp(),concat(current_date()," ",current_time()));
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"); select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w")); select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"));
select dayofmonth("1997-01-02"),dayofmonth(19970323); select dayofmonth("1997-01-02"),dayofmonth(19970323);
......
...@@ -425,6 +425,7 @@ Item *create_func_cast(Item *a, Item_cast cast_type) ...@@ -425,6 +425,7 @@ Item *create_func_cast(Item *a, Item_cast cast_type)
LINT_INIT(res); LINT_INIT(res);
switch (cast_type) { switch (cast_type) {
case ITEM_CAST_BINARY: res= new Item_func_binary(a); break; case ITEM_CAST_BINARY: res= new Item_func_binary(a); break;
case ITEM_CAST_CHAR: res= new Item_char_typecast(a); break;
case ITEM_CAST_SIGNED_INT: res= new Item_func_signed(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_UNSIGNED_INT: res= new Item_func_unsigned(a); break;
case ITEM_CAST_DATE: res= new Item_date_typecast(a); break; case ITEM_CAST_DATE: res= new Item_date_typecast(a); break;
......
...@@ -1003,7 +1003,7 @@ class Item_func_match_bool :public Item_func_match ...@@ -1003,7 +1003,7 @@ class Item_func_match_bool :public Item_func_match
enum Item_cast enum Item_cast
{ {
ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT, ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR
}; };
Item *create_func_cast(Item *a, Item_cast cast_type); Item *create_func_cast(Item *a, Item_cast cast_type);
......
...@@ -410,6 +410,7 @@ class Item_date_add_interval :public Item_date_func ...@@ -410,6 +410,7 @@ class Item_date_add_interval :public Item_date_func
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
}; };
class Item_extract :public Item_int_func class Item_extract :public Item_int_func
{ {
const interval_type int_type; const interval_type int_type;
...@@ -424,10 +425,12 @@ class Item_extract :public Item_int_func ...@@ -424,10 +425,12 @@ class Item_extract :public Item_int_func
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
}; };
class Item_typecast :public Item_str_func class Item_typecast :public Item_str_func
{ {
public: public:
Item_typecast(Item *a) :Item_str_func(a) {} Item_typecast(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "char"; }
String *val_str(String *a) String *val_str(String *a)
{ a=args[0]->val_str(a); null_value=args[0]->null_value; return a; } { a=args[0]->val_str(a); null_value=args[0]->null_value; return a; }
void fix_length_and_dec() { max_length=args[0]->max_length; } void fix_length_and_dec() { max_length=args[0]->max_length; }
...@@ -435,6 +438,14 @@ class Item_typecast :public Item_str_func ...@@ -435,6 +438,14 @@ class Item_typecast :public Item_str_func
}; };
class Item_char_typecast :public Item_typecast
{
public:
Item_char_typecast(Item *a) :Item_typecast(a) {}
void fix_length_and_dec() { binary=0; max_length=args[0]->max_length; }
};
class Item_date_typecast :public Item_typecast class Item_date_typecast :public Item_typecast
{ {
public: public:
...@@ -450,6 +461,7 @@ class Item_date_typecast :public Item_typecast ...@@ -450,6 +461,7 @@ class Item_date_typecast :public Item_typecast
} }
}; };
class Item_time_typecast :public Item_typecast class Item_time_typecast :public Item_typecast
{ {
public: public:
...@@ -465,6 +477,7 @@ class Item_time_typecast :public Item_typecast ...@@ -465,6 +477,7 @@ class Item_time_typecast :public Item_typecast
} }
}; };
class Item_datetime_typecast :public Item_typecast class Item_datetime_typecast :public Item_typecast
{ {
public: public:
......
...@@ -210,6 +210,8 @@ static SYMBOL symbols[] = { ...@@ -210,6 +210,8 @@ static SYMBOL symbols[] = {
{ "LIMIT", SYM(LIMIT),0,0}, { "LIMIT", SYM(LIMIT),0,0},
{ "LOAD", SYM(LOAD),0,0}, { "LOAD", SYM(LOAD),0,0},
{ "LOCAL", SYM(LOCAL_SYM),0,0}, { "LOCAL", SYM(LOCAL_SYM),0,0},
{ "LOCALTIME", SYM(NOW_SYM),0,0},
{ "LOCALTIMESTAMP", SYM(NOW_SYM),0,0},
{ "LOCK", SYM(LOCK_SYM),0,0}, { "LOCK", SYM(LOCK_SYM),0,0},
{ "LOCKS", SYM(LOCKS_SYM),0,0}, { "LOCKS", SYM(LOCKS_SYM),0,0},
{ "LOGS", SYM(LOGS_SYM),0,0}, { "LOGS", SYM(LOGS_SYM),0,0},
...@@ -394,7 +396,9 @@ static SYMBOL sql_functions[] = { ...@@ -394,7 +396,9 @@ static SYMBOL sql_functions[] = {
{ "BIT_OR", SYM(BIT_OR),0,0}, { "BIT_OR", SYM(BIT_OR),0,0},
{ "BIT_AND", SYM(BIT_AND),0,0}, { "BIT_AND", SYM(BIT_AND),0,0},
{ "CAST", SYM(CAST_SYM),0,0}, { "CAST", SYM(CAST_SYM),0,0},
{ "CEIL", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "CEILING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)}, { "CEILING", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "CURRENT_USER", SYM(USER),0,0},
{ "BIT_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)}, { "BIT_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)},
{ "CHAR_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)}, { "CHAR_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
{ "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)}, { "CHARACTER_LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
......
...@@ -899,7 +899,7 @@ field_list: ...@@ -899,7 +899,7 @@ field_list:
field_list_item: field_list_item:
field_spec field_spec check_constraint
| field_spec references | field_spec references
{ {
Lex->col_list.empty(); /* Alloced by sql_alloc */ Lex->col_list.empty(); /* Alloced by sql_alloc */
...@@ -914,10 +914,16 @@ field_list_item: ...@@ -914,10 +914,16 @@ field_list_item:
{ {
Lex->col_list.empty(); /* Alloced by sql_alloc */ Lex->col_list.empty(); /* Alloced by sql_alloc */
} }
| opt_constraint CHECK_SYM '(' expr ')' | opt_constraint check_constraint
{ {
Lex->col_list.empty(); /* Alloced by sql_alloc */ Lex->col_list.empty(); /* Alloced by sql_alloc */
}; }
;
check_constraint:
/* empty */
| CHECK_SYM expr
;
opt_constraint: opt_constraint:
/* empty */ /* empty */
...@@ -1986,13 +1992,15 @@ in_sum_expr: ...@@ -1986,13 +1992,15 @@ in_sum_expr:
cast_type: cast_type:
BINARY { $$=ITEM_CAST_BINARY; } BINARY { $$=ITEM_CAST_BINARY; }
| CHAR_SYM { $$=ITEM_CAST_CHAR; }
| SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; } | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; }
| SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; } | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; }
| UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; } | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; }
| UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; } | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; }
| DATE_SYM { $$=ITEM_CAST_DATE; } | DATE_SYM { $$=ITEM_CAST_DATE; }
| TIME_SYM { $$=ITEM_CAST_TIME; } | TIME_SYM { $$=ITEM_CAST_TIME; }
| DATETIME { $$=ITEM_CAST_DATETIME; }; | DATETIME { $$=ITEM_CAST_DATETIME; }
;
expr_list: expr_list:
{ Select->expr_list.push_front(new List<Item>); } { Select->expr_list.push_front(new List<Item>); }
...@@ -2437,7 +2445,7 @@ table_name: ...@@ -2437,7 +2445,7 @@ table_name:
{ if (!add_table_to_list($1,NULL,1)) YYABORT; }; { if (!add_table_to_list($1,NULL,1)) YYABORT; };
if_exists: if_exists:
/* empty */ { $$=0; } /* empty */ { $$= 0; }
| IF EXISTS { $$= 1; } | IF EXISTS { $$= 1; }
; ;
...@@ -3154,7 +3162,6 @@ keyword: ...@@ -3154,7 +3162,6 @@ keyword:
| CACHE_SYM {} | CACHE_SYM {}
| CHANGED {} | CHANGED {}
| CHECKSUM_SYM {} | CHECKSUM_SYM {}
| CHECK_SYM {}
| CIPHER_SYM {} | CIPHER_SYM {}
| CLIENT_SYM {} | CLIENT_SYM {}
| CLOSE_SYM {} | CLOSE_SYM {}
......
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