summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-11-04 11:16:13 +0100
committerSergei Golubchik <serg@mariadb.org>2016-12-12 20:27:24 +0100
commitfd0044041bf70d5d8bbb530285055da585384ff1 (patch)
tree0cf9923eaeeb9facd2751e3b8df67f9b1394079c
parent867809f23a8f09b1ac0aa8f9212ac8afd572efc5 (diff)
downloadmariadb-git-fd0044041bf70d5d8bbb530285055da585384ff1.tar.gz
don't convert WEEK(x) to WEEK(x, @@default_week_format)
-rw-r--r--mysql-test/r/func_time.result2
-rw-r--r--mysql-test/r/set_statement.result2
-rw-r--r--mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result2
-rw-r--r--sql/item_timefunc.cc10
-rw-r--r--sql/item_timefunc.h18
-rw-r--r--sql/sql_yacc.yy10
6 files changed, 27 insertions, 17 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index f4b1a39294c..f75ec17c702 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -874,7 +874,7 @@ explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_d
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select period_add('9602',-12) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03',@@default_week_format) AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
+Note 1003 select period_add('9602',-12) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03') AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
SET @TMP='2007-08-01 12:22:49';
CREATE TABLE t1 (d DATETIME);
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
diff --git a/mysql-test/r/set_statement.result b/mysql-test/r/set_statement.result
index a66d636d18e..4cb143f6ba5 100644
--- a/mysql-test/r/set_statement.result
+++ b/mysql-test/r/set_statement.result
@@ -1152,7 +1152,7 @@ explain extended select week(a) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
Warnings:
-Note 1003 select week('2000-01-01',@@default_week_format) AS `week(a)` from dual
+Note 1003 select week('2000-01-01') AS `week(a)` from dual
prepare stmt1 from "select week(a) from t1";
execute stmt1;
week(a)
diff --git a/mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result b/mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result
index 0e03d80014d..dd580c344b0 100644
--- a/mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result
+++ b/mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result
@@ -57,7 +57,7 @@ create or replace table t1 (a datetime, b datetime as (utc_timestamp()) PERSISTE
ERROR HY000: Function or expression 'utc_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# WEEK() - one argument version
create or replace table t1 (a datetime, b datetime as (week(a)) PERSISTENT);
-ERROR HY000: Function or expression '@@default_week_format' cannot be used in the GENERATED ALWAYS AS clause of `b`
+ERROR HY000: Function or expression 'week()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# MATCH()
create or replace table t1 (a varchar(32), b bool as (match a against ('sample text')) PERSISTENT);
ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `b`
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 5e0ae028d88..c35606781ec 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1044,13 +1044,15 @@ uint week_mode(uint mode)
longlong Item_func_week::val_int()
{
DBUG_ASSERT(fixed == 1);
- uint year;
+ uint year, week_format;
MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0;
- return (longlong) calc_week(&ltime,
- week_mode((uint) args[1]->val_int()),
- &year);
+ if (arg_count > 1)
+ week_format= args[1]->val_int();
+ else
+ week_format= current_thd->variables.default_week_format;
+ return (longlong) calc_week(&ltime, week_mode(week_format), &year);
}
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 3d2b5c8c9e9..1e905c44fdf 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -334,6 +334,7 @@ public:
class Item_func_week :public Item_int_func
{
public:
+ Item_func_week(THD *thd, Item *a): Item_int_func(thd, a) {}
Item_func_week(THD *thd, Item *a, Item *b): Item_int_func(thd, a, b) {}
longlong val_int();
const char *func_name() const { return "week"; }
@@ -343,6 +344,16 @@ public:
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1;
}
+ bool check_vcol_func_processor(void *arg)
+ {
+ if (arg_count == 2)
+ return FALSE;
+ return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
+ }
+ bool check_valid_arguments_processor(void *int_arg)
+ {
+ return arg_count == 2;
+ }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_week>(thd, mem_root, this); }
};
@@ -981,7 +992,12 @@ class Item_extract :public Item_int_func
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type);
bool check_partition_func_processor(void *int_arg) {return FALSE;}
- bool check_vcol_func_processor(void *arg) { return FALSE;}
+ bool check_vcol_func_processor(void *arg)
+ {
+ if (int_type != INTERVAL_WEEK)
+ return FALSE;
+ return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
+ }
bool check_valid_arguments_processor(void *int_arg)
{
switch (int_type) {
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index da7fb37ef89..d6376777c62 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -10022,15 +10022,7 @@ function_call_conflict:
}
| WEEK_SYM '(' expr ')'
{
- Item *i1;
- LEX_STRING name= {C_STRING_WITH_LEN("default_week_format")};
- if (!(i1= get_system_var(thd, OPT_SESSION,
- name, null_lex_str)))
- MYSQL_YYABORT;
- i1->set_name(thd, (const char *)
- STRING_WITH_LEN("@@default_week_format"),
- system_charset_info);
- $$= new (thd->mem_root) Item_func_week(thd, $3, i1);
+ $$= new (thd->mem_root) Item_func_week(thd, $3);
if ($$ == NULL)
MYSQL_YYABORT;
}