mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 14:02:32 +01:00
6aaccbcbf7
Added basic per-thread time zone functionality (based on public domain elsie-code). Now user can select current time zone (from the list of time zones described in system tables). All NOW-like functions honor this time zone, values of TIMESTAMP type are interpreted as values in this time zone, so now our TIMESTAMP type behaves similar to Oracle's TIMESTAMP WITH LOCAL TIME ZONE (or proper PostgresSQL type). WL#1266 "CONVERT_TZ() - basic time with time zone conversion function". Fixed problems described in Bug #2336 (Different number of warnings when inserting bad datetime as string or as number). This required reworking of datetime realted warning hadling (they now generated at Field object level not in conversion functions). Optimization: Now Field class descendants use table->in_use member instead of current_thd macro. include/my_global.h: Added macro for reading of 32-bit ints stored in network order from unaligned memory location. include/mysqld_error.h: Added error-code for invalid timestamp warning and error-code for wrong or unknown time zone specification. libmysqld/Makefile.am: Added main per-thread time zone support file to libmysqld libmysqld/lib_sql.cc: Added initialization of time zones infrastructure to embedded server. mysql-test/r/connect.result: Updated test result since now mysql database contains more system tables. mysql-test/r/date_formats.result: Now when truncation occurs during conversion to datetime value we are producing Warnings instead of Notes. Also we are giving more clear warnings about this in some cases. mysql-test/r/func_sapdb.result: New warnings about truncation occured during conversion to datetime value added due their better handling. mysql-test/r/func_time.result: New warnings about truncation occured during conversion to datetime value added due their better handling. mysql-test/r/select.result: New warnings about truncation occured during conversion to datetime value added due their better handling. Also tweaked test a bit to made it less ambigious for reader. mysql-test/r/system_mysql_db.result: Updated test result because new system tables holding time zone descriptions were added. mysql-test/r/timezone.result: Updated timezone.test to use new system variable which shows system time zone. Added test of warning which is produced if someone tries to store non-existing (due falling into spring time-gap) datetime value into TIMESTAMP field. mysql-test/r/type_datetime.result: Separated and extended test of values and warnings produced for bad values stored in DATETTIME fields. mysql-test/r/type_time.result: Now we are producing more consistent warning when we are truncating datetime value while storing it in TIME field. mysql-test/r/type_timestamp.result: Separated and extended test of values and warnings produced for bad values stored in TIMESTAMP fields. mysql-test/t/select.test: Updated test to make it less ambigous for reader. mysql-test/t/timezone.test: Updated timezone.test to use new system variable which shows system time zone. Added test of warning which is produced if someone tries to store non-existing (due falling into spring time-gap) datetime value into TIMESTAMP field. mysql-test/t/type_datetime.test: Separated and extended test of values and warnings produced for bad values stored in DATETTIME fields. mysql-test/t/type_timestamp.test: Separated and extended test of values and warnings produced for bad values stored in TIMESTAMP fields. scripts/mysql_create_system_tables.sh: Added creation of tables with time zone descriptions. Also added descriptions of time zones used in tests. scripts/mysql_fix_privilege_tables.sql: Added mysql.time_zone* tables family. sql/Makefile.am: Added files implementing time zone support to server, also added rules for building of mysql_tzinfo_to_sql converter and test_time test. sql/field.cc: Now we are using per-thread time zone for TIMESTAMP <-> whatever conversion. Fixed generation of warnings for datetime types (DATETIME/TIMESTAMP/DATE/...) and any other Field to datetime conversion (now we are generating warnings no in lower level functions like in str_to_TIME() but in Field methods. This allows generate better and more consistent warnings and to reuse code of str_to_TIME() outside of server). Added 3rd parameter to set_warning() method to be able to not increment cut fields but still produce a warning. Also added set_datetime_warning() family of auxiliary methods which allow easier generate datetime related warnings. Also replaced occurences of current_thd with table->in_use member, added asserts for catching all places there we need to set table->in_use accordingly. Renamed fix_datetime() function to number_to_TIME() and moved it to sql/time.cc there it fits better. sql/field.h: Added comment about places where we can use table->in_use member instead of current_thd. Added 3rd parameter to Field::set_warning() method and set_datetime_warning() family of methods. sql/field_conv.cc: Field::set_warning() method with 2 arguments was replaced with more generic set_warning() method with 3 arguments. sql/ha_berkeley.cc: Now we set table->in_use for temporary tables so we have to use table->tmp_table for checking if table is temporary. sql/item.cc: Replaced calls to str_to_time() and str_to_TIME() funcs with their warning generating analogs. sql/item_create.cc: Added creation of CONVERT_TZ function as FUNC_ARG3. sql/item_create.h: Added creation of CONVERT_TZ function as FUNC_ARG3. sql/item_timefunc.cc: Added support of per-thread time zone to NOW-like and FROM_UNIXTIME, UNIX_TIMESTAMP functions. Added support for CONVERT_TZ function. Removed call to str_to_timestamp function which caused non-optimal behavior in certain cases. Replaced calls to str_to_time() function with its warning generating analog. sql/item_timefunc.h: Added support of per-thread time zone to NOW-like and FROM_UNIXTIME, UNIX_TIMESTAMP functions. Added support of CONVERT_TZ function. sql/lex.h: Added support of CONVERT_TZ function. sql/log.cc: Added support for replication of statements depending on time zone. sql/mysql_priv.h: Now including headers with per-thread time zone support functions and classes. Added portable replacement of time_t - my_time_t type. Added time zone as one of query distinguishing parameters for query cache. Fixed declarations of str_to_TIME, str_to_time and my_system_gmt_sec (former my_gmt_sec) since now they have one more out parameter which informs about wrong datetime value or data truncation during conversion. Added warning generating version of str_to_TIME() and str_to_time() functions. Thrown away str_to_datetime/timestamp functions since they are not needed any longer. Added number_to_TIME function. sql/mysqld.cc: Added per-thread time zone support initialization. Added new startup parameter --default-time-zone. sql/set_var.cc: Added support for per-thread time_zone variable. Renamed old timezone variable to system_time_zone. sql/set_var.h: Added support for per-thread time_zone variable. sql/share/czech/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/danish/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/dutch/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/english/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/estonian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/french/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/german/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/greek/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/hungarian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/italian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/japanese/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/korean/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/norwegian-ny/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/norwegian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/polish/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/portuguese/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/romanian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/russian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/serbian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/slovak/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/spanish/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/swedish/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/share/ukrainian/errmsg.txt: Added error message for barking when incorrect time zone name or specifiaction is provided and for warning about invalid TIMESTAMP values (e.g. falling into the spring time-gap). sql/slave.cc: In order to support replication of statements using time zones in 4.1 we should ensure that both master and slave have same default time zone. sql/sql_base.cc: Now we are setting TABLE::in_use member for all tables (which assume calls to Field::store or val_ methods). sql/sql_cache.cc: Added time zone as one more query distinguishing parameter for query cache. sql/sql_class.cc: Added THD::time_zone_used variable indicating that this query uses per thread time zone. sql/sql_class.h: Added per-thread time zone variable. Added THD::time_zone_used variable indicating that this query uses per thread time zone so if this is updating query the time zone should be logged to binlog. sql/sql_insert.cc: We should set TABLE::in_use member pointing to thread which is called INSERT DELAYED and not to worker thread. sql/sql_load.cc: Field::set_warning() now has one more argument now. sql/sql_parse.cc: Resetting THD::time_zone_used variable in the end of query processing. sql/sql_select.cc: Now we are setting TABLE::in_use member for all tables (which assume calls to Field::store or val_ methods). sql/sql_show.cc: Now using per thread time zone for extended show tables. sql/time.cc: Added support for per-thread time zones for TIMESTAMP type and reworked generation of warnings for TIMESTAMP and DATETIME types. (Introduced new TIME_to_timestamp() function. Removed hours normalisation from former my_gmt_sec() since it was not working and not used anywhere now, but breaks parameter constness, added to this function generation of warning if we are falling in spring time-gap. Removed str_to_timestamp and str_to_datetime functions which are no longer used. Moved fix_datetime function from sql/field.cc to this file as number_to_TIME() function. Added out parameter for str_to_TIME and str_to_time functions which indicates if value was truncated during conversion, removed direct generation of warnings from this functions.) sql/unireg.cc: Now we are setting TABLE::in_use member for all tables (which assume calls to Field::store or val_ methods). BitKeeper/etc/ignore: Added sql/test_time sql/mysql_tzinfo_to_sql libmysqld/tztime.cc to the ignore list
871 lines
22 KiB
C++
871 lines
22 KiB
C++
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
/* Function items used by mysql */
|
|
|
|
#ifdef __GNUC__
|
|
#pragma interface /* gcc class implementation */
|
|
#endif
|
|
|
|
enum date_time_format_types
|
|
{
|
|
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
|
|
};
|
|
|
|
class Item_func_period_add :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "period_add"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_period_diff :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "period_diff"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_to_days :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_to_days(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "to_days"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_dayofmonth :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "dayofmonth"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_month :public Item_func
|
|
{
|
|
public:
|
|
Item_func_month(Item *a) :Item_func(a) {}
|
|
longlong val_int();
|
|
double val()
|
|
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
|
|
String *val_str(String *str)
|
|
{
|
|
str->set(val_int(), &my_charset_bin);
|
|
return null_value ? 0 : str;
|
|
}
|
|
const char *func_name() const { return "month"; }
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_monthname :public Item_func_month
|
|
{
|
|
public:
|
|
Item_func_monthname(Item *a) :Item_func_month(a) {}
|
|
const char *func_name() const { return "monthname"; }
|
|
String *val_str(String *str);
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=10*my_charset_bin.mbmaxlen;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_dayofyear :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_dayofyear(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "dayofyear"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=3*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_hour :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_hour(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "hour"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_minute :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_minute(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "minute"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_quarter :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_quarter(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "quarter"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_second :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_second(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "second"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_week :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "week"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
class Item_func_yearweek :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "yearweek"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_year :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_year(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "year"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_weekday :public Item_func
|
|
{
|
|
bool odbc_type;
|
|
public:
|
|
Item_func_weekday(Item *a,bool type_arg)
|
|
:Item_func(a), odbc_type(type_arg) {}
|
|
longlong val_int();
|
|
double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
String *val_str(String *str)
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
str->set(val_int(), &my_charset_bin);
|
|
return null_value ? 0 : str;
|
|
}
|
|
const char *func_name() const { return "weekday"; }
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
class Item_func_dayname :public Item_func_weekday
|
|
{
|
|
public:
|
|
Item_func_dayname(Item *a) :Item_func_weekday(a,0) {}
|
|
const char *func_name() const { return "dayname"; }
|
|
String *val_str(String *str);
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=9*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_unix_timestamp :public Item_int_func
|
|
{
|
|
String value;
|
|
public:
|
|
Item_func_unix_timestamp() :Item_int_func() {}
|
|
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "unix_timestamp"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_time_to_sec :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "time_to_sec"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
/* This can't be a Item_str_func, because the val() functions are special */
|
|
|
|
class Item_date :public Item_func
|
|
{
|
|
public:
|
|
Item_date() :Item_func() {}
|
|
Item_date(Item *a) :Item_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
String *val_str(String *str);
|
|
longlong val_int();
|
|
double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
const char *func_name() const { return "date"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
int save_in_field(Field *to, bool no_conversions);
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
|
|
class Item_date_func :public Item_str_func
|
|
{
|
|
public:
|
|
Item_date_func() :Item_str_func() {}
|
|
Item_date_func(Item *a) :Item_str_func(a) {}
|
|
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
|
|
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
|
|
/* Abstract CURTIME function. Children should define what time zone is used */
|
|
|
|
class Item_func_curtime :public Item_func
|
|
{
|
|
longlong value;
|
|
char buff[9*2+32];
|
|
uint buff_length;
|
|
public:
|
|
Item_func_curtime() :Item_func() {}
|
|
Item_func_curtime(Item *a) :Item_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
/*
|
|
Abstract method that defines which time zone is used for conversion.
|
|
Converts time current time in my_time_t representation to broken-down
|
|
TIME representation using UTC-SYSTEM or per-thread time zone.
|
|
*/
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_curtime_local :public Item_func_curtime
|
|
{
|
|
public:
|
|
Item_func_curtime_local() :Item_func_curtime() {}
|
|
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
|
|
const char *func_name() const { return "curtime"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
class Item_func_curtime_utc :public Item_func_curtime
|
|
{
|
|
public:
|
|
Item_func_curtime_utc() :Item_func_curtime() {}
|
|
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
|
|
const char *func_name() const { return "utc_time"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
/* Abstract CURDATE function. See also Item_func_curtime. */
|
|
|
|
class Item_func_curdate :public Item_date
|
|
{
|
|
longlong value;
|
|
TIME ltime;
|
|
public:
|
|
Item_func_curdate() :Item_date() {}
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_curdate_local :public Item_func_curdate
|
|
{
|
|
public:
|
|
Item_func_curdate_local() :Item_func_curdate() {}
|
|
const char *func_name() const { return "curdate"; }
|
|
void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
class Item_func_curdate_utc :public Item_func_curdate
|
|
{
|
|
public:
|
|
Item_func_curdate_utc() :Item_func_curdate() {}
|
|
const char *func_name() const { return "utc_date"; }
|
|
void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
|
|
|
|
class Item_func_now :public Item_date_func
|
|
{
|
|
longlong value;
|
|
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
|
|
uint buff_length;
|
|
TIME ltime;
|
|
public:
|
|
Item_func_now() :Item_date_func() {}
|
|
Item_func_now(Item *a) :Item_date_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
double val() { DBUG_ASSERT(fixed == 1); return (double) value; }
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
|
|
int save_in_field(Field *to, bool no_conversions);
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_now_local :public Item_func_now
|
|
{
|
|
public:
|
|
Item_func_now_local() :Item_func_now() {}
|
|
Item_func_now_local(Item *a) :Item_func_now(a) {}
|
|
const char *func_name() const { return "now"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
virtual enum Functype functype() const { return NOW_FUNC; }
|
|
};
|
|
|
|
|
|
class Item_func_now_utc :public Item_func_now
|
|
{
|
|
public:
|
|
Item_func_now_utc() :Item_func_now() {}
|
|
Item_func_now_utc(Item *a) :Item_func_now(a) {}
|
|
const char *func_name() const { return "utc_timestamp"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
class Item_func_from_days :public Item_date
|
|
{
|
|
public:
|
|
Item_func_from_days(Item *a) :Item_date(a) {}
|
|
const char *func_name() const { return "from_days"; }
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|
|
|
|
|
|
class Item_func_date_format :public Item_str_func
|
|
{
|
|
int fixed_length;
|
|
const bool is_time_format;
|
|
String value;
|
|
public:
|
|
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
|
|
:Item_str_func(a,b),is_time_format(is_time_format_arg) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "date_format"; }
|
|
void fix_length_and_dec();
|
|
uint format_length(const String *format);
|
|
};
|
|
|
|
|
|
class Item_func_from_unixtime :public Item_date_func
|
|
{
|
|
THD *thd;
|
|
public:
|
|
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
|
|
double val()
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
return (double) Item_func_from_unixtime::val_int();
|
|
}
|
|
longlong val_int();
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "from_unixtime"; }
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|
|
|
|
|
|
/*
|
|
We need Time_zone class declaration for storing pointers in
|
|
Item_func_convert_tz.
|
|
*/
|
|
class Time_zone;
|
|
|
|
class Item_func_convert_tz :public Item_date_func
|
|
{
|
|
THD *thd;
|
|
Time_zone *from_tz, *to_tz;
|
|
public:
|
|
Item_func_convert_tz(Item *a, Item *b, Item *c):
|
|
Item_date_func(a, b, c) {}
|
|
longlong val_int();
|
|
double val() { return (double) val_int(); }
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "convert_tz"; }
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|
|
|
|
|
|
class Item_func_sec_to_time :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_sec_to_time(Item *item) :Item_str_func(item) {}
|
|
double val()
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
return (double) Item_func_sec_to_time::val_int();
|
|
}
|
|
longlong val_int();
|
|
String *val_str(String *);
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
maybe_null=1;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
const char *func_name() const { return "sec_to_time"; }
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
/*
|
|
The following must be sorted so that simple intervals comes first.
|
|
(get_interval_value() depends on this)
|
|
*/
|
|
|
|
enum interval_type
|
|
{
|
|
INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE,
|
|
INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH,
|
|
INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND,
|
|
INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND,
|
|
INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
|
|
INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND
|
|
};
|
|
|
|
class Item_date_add_interval :public Item_date_func
|
|
{
|
|
const interval_type int_type;
|
|
String value;
|
|
const bool date_sub_interval;
|
|
enum_field_types cached_field_type;
|
|
|
|
public:
|
|
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
|
|
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
|
|
String *val_str(String *);
|
|
const char *func_name() const { return "date_add_interval"; }
|
|
void fix_length_and_dec();
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
double val() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
longlong val_int();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_extract :public Item_int_func
|
|
{
|
|
const interval_type int_type;
|
|
String value;
|
|
bool date_value;
|
|
public:
|
|
Item_extract(interval_type type_arg, Item *a)
|
|
:Item_int_func(a), int_type(type_arg) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "extract"; }
|
|
void fix_length_and_dec();
|
|
bool eq(const Item *item, bool binary_cmp) const;
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_typecast :public Item_str_func
|
|
{
|
|
public:
|
|
Item_typecast(Item *a) :Item_str_func(a) {}
|
|
String *val_str(String *a)
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
String *tmp=args[0]->val_str(a);
|
|
null_value=args[0]->null_value;
|
|
if (tmp)
|
|
tmp->set_charset(collation.collation);
|
|
return tmp;
|
|
}
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
max_length=args[0]->max_length;
|
|
}
|
|
virtual const char* cast_type() const= 0;
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_typecast_maybe_null :public Item_typecast
|
|
{
|
|
public:
|
|
Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
max_length=args[0]->max_length;
|
|
maybe_null= 1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_char_typecast :public Item_typecast
|
|
{
|
|
int cast_length;
|
|
CHARSET_INFO *cast_cs;
|
|
bool charset_conversion;
|
|
String tmp_value;
|
|
public:
|
|
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
|
|
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
|
|
const char* cast_type() const { return "char"; };
|
|
String *val_str(String *a);
|
|
void fix_length_and_dec();
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_date_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
String *val_str(String *str);
|
|
bool get_date(TIME *ltime, uint fuzzy_date);
|
|
const char *cast_type() const { return "date"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
|
|
class Item_time_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
String *val_str(String *str);
|
|
bool get_time(TIME *ltime);
|
|
const char *cast_type() const { return "time"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
|
|
class Item_datetime_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
String *val_str(String *str);
|
|
const char *cast_type() const { return "datetime"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
class Item_func_makedate :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_makedate(Item *a,Item *b) :Item_str_func(a,b) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "makedate"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_add_time :public Item_str_func
|
|
{
|
|
const bool is_date;
|
|
int sign;
|
|
enum_field_types cached_field_type;
|
|
|
|
public:
|
|
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
|
|
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
|
|
String *val_str(String *str);
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
void fix_length_and_dec();
|
|
|
|
/*
|
|
TODO:
|
|
Change this when we support
|
|
microseconds in TIME/DATETIME
|
|
*/
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
if (cached_field_type == MYSQL_TYPE_TIME)
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
else if (cached_field_type == MYSQL_TYPE_DATETIME)
|
|
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
|
|
return (new Field_string(max_length, maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
void print(String *str);
|
|
};
|
|
|
|
class Item_func_timediff :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_timediff(Item *a, Item *b)
|
|
:Item_str_func(a, b) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "timediff"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
class Item_func_maketime :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_maketime(Item *a, Item *b, Item *c)
|
|
:Item_str_func(a, b ,c) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "maketime"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
Field *tmp_table_field(TABLE *t_arg)
|
|
{
|
|
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
|
|
}
|
|
};
|
|
|
|
class Item_func_microsecond :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_microsecond(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "microsecond"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
enum date_time_format
|
|
{
|
|
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
|
|
};
|
|
|
|
class Item_func_get_format :public Item_str_func
|
|
{
|
|
const timestamp_type type;
|
|
public:
|
|
Item_func_get_format(timestamp_type type_arg, Item *a)
|
|
:Item_str_func(a), type(type_arg)
|
|
{}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "get_format"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
maybe_null= 1;
|
|
decimals=0;
|
|
max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_func_str_to_date :public Item_str_func
|
|
{
|
|
enum_field_types cached_field_type;
|
|
date_time_format_types cached_format_type;
|
|
timestamp_type cached_timestamp_type;
|
|
bool const_item;
|
|
public:
|
|
Item_func_str_to_date(Item *a, Item *b)
|
|
:Item_str_func(a, b)
|
|
{}
|
|
String *val_str(String *str);
|
|
bool get_date(TIME *ltime, uint fuzzy_date);
|
|
const char *func_name() const { return "str_to_date"; }
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
void fix_length_and_dec();
|
|
Field *tmp_table_field(TABLE *t_arg);
|
|
};
|
|
|
|
|
|
class Item_func_last_day :public Item_date
|
|
{
|
|
public:
|
|
Item_func_last_day(Item *a) :Item_date(a) {}
|
|
const char *func_name() const { return "last_day"; }
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|