summaryrefslogtreecommitdiffstats
path: root/sql/item_timefunc.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 13:22:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 13:22:53 +0000
commit347c164c35eddab388009470e6848cb361ac93f8 (patch)
tree2c0c44eac690f510bb0a35b2a13b36d606b77b6b /sql/item_timefunc.h
parentReleasing progress-linux version 1:10.11.7-4~progress7.99u1. (diff)
downloadmariadb-347c164c35eddab388009470e6848cb361ac93f8.tar.xz
mariadb-347c164c35eddab388009470e6848cb361ac93f8.zip
Merging upstream version 1:10.11.8.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sql/item_timefunc.h')
-rw-r--r--sql/item_timefunc.h33
1 files changed, 19 insertions, 14 deletions
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 083eb7ba..5485f6c1 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -30,23 +30,23 @@ bool get_interval_value(THD *thd, Item *args,
interval_type int_type, INTERVAL *interval);
-class Item_long_func_date_field: public Item_long_func
+class Item_long_func_date_field: public Item_long_ge0_func
{
bool check_arguments() const override
{ return args[0]->check_type_can_return_date(func_name_cstring()); }
public:
Item_long_func_date_field(THD *thd, Item *a)
- :Item_long_func(thd, a) { }
+ :Item_long_ge0_func(thd, a) { }
};
-class Item_long_func_time_field: public Item_long_func
+class Item_long_func_time_field: public Item_long_ge0_func
{
bool check_arguments() const override
{ return args[0]->check_type_can_return_time(func_name_cstring()); }
public:
Item_long_func_time_field(THD *thd, Item *a)
- :Item_long_func(thd, a) { }
+ :Item_long_ge0_func(thd, a) { }
};
@@ -186,10 +186,10 @@ public:
};
-class Item_func_month :public Item_long_func
+class Item_func_month :public Item_long_ge0_func
{
public:
- Item_func_month(THD *thd, Item *a): Item_long_func(thd, a)
+ Item_func_month(THD *thd, Item *a): Item_long_ge0_func(thd, a)
{ }
longlong val_int() override;
LEX_CSTRING func_name_cstring() const override
@@ -381,7 +381,7 @@ public:
};
-class Item_func_week :public Item_long_func
+class Item_func_week :public Item_long_ge0_func
{
bool check_arguments() const override
{
@@ -389,8 +389,8 @@ class Item_func_week :public Item_long_func
(arg_count > 1 && args[1]->check_type_can_return_int(func_name_cstring()));
}
public:
- Item_func_week(THD *thd, Item *a): Item_long_func(thd, a) {}
- Item_func_week(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
+ Item_func_week(THD *thd, Item *a): Item_long_ge0_func(thd, a) {}
+ Item_func_week(THD *thd, Item *a, Item *b): Item_long_ge0_func(thd, a, b) {}
longlong val_int() override;
LEX_CSTRING func_name_cstring() const override
{
@@ -1166,12 +1166,17 @@ class Item_extract :public Item_int_func,
void set_date_length(uint32 length)
{
/*
- Although DATE components (e.g. YEAR, YEAR_MONTH, QUARTER, MONTH, WEEK)
- cannot have a sign, we should probably still add +1,
- because all around the code we assume that max_length is sign inclusive.
- Another options is to set unsigned_flag to "true".
+ DATE components (e.g. YEAR, YEAR_MONTH, QUARTER, MONTH, WEEK)
+ return non-negative values but historically EXTRACT for date
+ components always returned the signed int data type.
+ So do equivalent functions YEAR(), QUARTER(), MONTH(), WEEK().
+ Let's set the data type to "signed int, but not negative",
+ so "this" produces better data types in VARCHAR and DECIMAL context
+ by using the fact that all of the max_length characters are spent
+ for digits (non of them are spent for the sign).
*/
- set_handler(handler_by_length(max_length= length, 10)); // QQ: see above
+ set_handler(&type_handler_slong_ge0);
+ fix_char_length(length);
m_date_mode= date_mode_t(0);
}
void set_day_length(uint32 length)