WL#1264 "Per-thread time zone support infrastructure".

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
This commit is contained in:
unknown 2004-06-18 10:11:31 +04:00
parent 6c2e161479
commit 6aaccbcbf7
81 changed files with 5146 additions and 579 deletions

View file

@ -780,3 +780,6 @@ ndb/src/common/mgmcommon/printConfig/*.d
ndb/src/mgmclient/test_cpcd/*.d
*.d
libmysqld/examples/client_test.c
sql/test_time
sql/mysql_tzinfo_to_sql
libmysqld/tztime.cc

View file

@ -1101,6 +1101,14 @@ do { doubleget_union _tmp; \
#endif /* sint2korr */
/*
Macro for reading 32-bit integer from network byte order (big-endian)
from unaligned memory location.
*/
#define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\
(((uint32) ((uchar) (A)[2])) << 8) |\
(((uint32) ((uchar) (A)[1])) << 16) |\
(((uint32) ((uchar) (A)[0])) << 24))
/*
Define-funktions for reading and storing in machine format from/to
short/long to/from some place in memory V should be a (not

View file

@ -314,4 +314,6 @@
#define ER_UNSUPPORTED_PS 1295
#define ER_GET_ERRMSG 1296
#define ER_GET_TEMPORARY_ERRMSG 1297
#define ER_ERROR_MESSAGES 298
#define ER_UNKNOWN_TIME_ZONE 1298
#define ER_WARN_INVALID_TIMESTAMP 1299
#define ER_ERROR_MESSAGES 300

View file

@ -56,7 +56,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \
spatial.cc gstream.cc sql_help.cc
spatial.cc gstream.cc sql_help.cc tztime.cc
libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources)
libmysqld_a_SOURCES=

View file

@ -356,6 +356,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
int fake_argc = 1;
char *fake_argv[] = { (char *)"", 0 };
const char *fake_groups[] = { "server", "embedded", 0 };
my_bool acl_error;
if (argc)
{
argcp= &argc;
@ -397,16 +398,17 @@ int init_embedded_server(int argc, char **argv, char **groups)
error_handler_hook = my_message_sql;
acl_error= 0;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (acl_init((THD *)0, opt_noacl))
if (!(acl_error= acl_init((THD *)0, opt_noacl)) &&
!opt_noacl)
(void) grant_init((THD *)0);
#endif
if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
{
mysql_server_end();
return 1;
}
if (!opt_noacl)
(void) grant_init((THD *)0);
#endif
init_max_user_conn();
init_update_queries();

View file

@ -9,6 +9,11 @@ help_relation
help_topic
host
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
show tables;
Tables_in_test
@ -25,6 +30,11 @@ help_relation
help_topic
host
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
show tables;
Tables_in_test
@ -42,6 +52,11 @@ help_relation
help_topic
host
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
show tables;
Tables_in_test

View file

@ -303,14 +303,14 @@ date format str_to_date
2003-01-02 10:11:12 %Y-%m-%d %h:%i:%S 2003-01-02 10:11:12
03-01-02 10:11:12 PM %Y-%m-%d %h:%i:%S %p 0003-01-02 22:11:12
Warnings:
Note 1292 Truncated incorrect string value: '10:20:10AM'
Warning 1292 Truncated incorrect datetime value: '10:20:10AM'
select date,format,concat(str_to_date(date, format),'') as con from t1;
date format con
10:20:10AM %h:%i:%s 0000-00-00 10:20:10
2003-01-02 10:11:12 %Y-%m-%d %h:%i:%S 2003-01-02 10:11:12
03-01-02 10:11:12 PM %Y-%m-%d %h:%i:%S %p 0003-01-02 22:11:12
Warnings:
Note 1292 Truncated incorrect string value: '10:20:10AM'
Warning 1292 Truncated incorrect datetime value: '10:20:10AM'
drop table t1;
select get_format(DATE, 'USA') as a;
a
@ -374,7 +374,7 @@ str_to_date("02 10", "%d %f") as f6;
f1 f2 f3 f4 f5 f6
2003-01-02 10:11:12.001200 2003-01-02 10:11:12 2003-01-02 58:11:12 58:11:12 48:00:00.100000
Warnings:
Note 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012'
Warning 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012'
drop table t1, t2;
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
@ -382,13 +382,13 @@ microsecond("1997-12-31 23:59:59.01XXXX") as f3;
f1 f2 f3
2003-01-02 10:11:12.001200 -25:01:00.110000 10000
Warnings:
Note 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD'
Note 1292 Truncated incorrect time value: '-01:01:01.01 GG'
Note 1292 Truncated incorrect datetime value: '1997-12-31 23:59:59.01XXXX'
Warning 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD'
Warning 1292 Truncated incorrect time value: '-01:01:01.01 GGG'
Warning 1292 Truncated incorrect time value: '1997-12-31 23:59:59.01XXXX'
select str_to_date("2003-04-05 g", "%Y-%m-%d") as f1,
str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
f1 f2
2003-04-05 2003-04-05 10:11:12.101010
Warnings:
Note 1292 Truncated incorrect date value: '2003-04-05 g'
Note 1292 Truncated incorrect datetime value: '2003-04-05 10:11:12.101010234567'
Warning 1292 Truncated incorrect date value: '2003-04-05 g'
Warning 1292 Truncated incorrect datetime value: '2003-04-05 10:11:12.101010234567'

View file

@ -119,6 +119,8 @@ timestamp("2001-12-01", "01:01:01.999999")
select timestamp("2001-13-01", "01:01:01.000001");
timestamp("2001-13-01", "01:01:01.000001")
NULL
Warnings:
Warning 1292 Truncated incorrect datetime value: '2001-13-01'
select timestamp("2001-12-01", "25:01:01");
timestamp("2001-12-01", "25:01:01")
2001-12-02 01:01:01
@ -137,12 +139,16 @@ date("1997-12-31 23:59:59.000001")
select date("1997-13-31 23:59:59.000001");
date("1997-13-31 23:59:59.000001")
NULL
Warnings:
Warning 1292 Truncated incorrect datetime value: '1997-13-31 23:59:59.000001'
select time("1997-12-31 23:59:59.000001");
time("1997-12-31 23:59:59.000001")
23:59:59.000001
select time("1997-12-31 25:59:59.000001");
time("1997-12-31 25:59:59.000001")
NULL
Warnings:
Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001'
select microsecond("1997-12-31 23:59:59.000001");
microsecond("1997-12-31 23:59:59.000001")
1

View file

@ -411,9 +411,13 @@ INSERT INTO t1 VALUES ('');
SELECT month(updated) from t1;
month(updated)
NULL
Warnings:
Warning 1292 Truncated incorrect datetime value: ''
SELECT year(updated) from t1;
year(updated)
NULL
Warnings:
Warning 1292 Truncated incorrect datetime value: ''
drop table t1;
create table t1 (d date, dt datetime, t timestamp, c char(10));
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
@ -536,6 +540,8 @@ last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
f1 f2 f3 f4 f5 last_day(NULL) last_day('2001-02-12')
2000-02-29 2002-12-31 NULL 2003-04-30 2001-01-31 NULL 2001-02-28
Warnings:
Warning 1292 Truncated incorrect datetime value: '2003-03-32'
create table t1 select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
describe t1;

View file

@ -0,0 +1,77 @@
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
create table t1 (t timestamp);
create table t2 (t char(32));
select @@time_zone;
@@time_zone
Europe/Moscow
set time_zone='UTC';
insert into t1 values ('20040101000000'), ('20040611093902');
select * from t1;
t
2004-01-01 00:00:00
2004-06-11 09:39:02
select * from t1;
t
2004-01-01 03:00:00
2004-06-11 13:39:02
delete from t1;
set time_zone='Europe/Moscow';
insert into t1 values ('20040101000000'), ('20040611093902');
select * from t1;
t
2004-01-01 00:00:00
2004-06-11 09:39:02
select * from t1;
t
2004-01-01 00:00:00
2004-06-11 09:39:02
show binlog events;
Log_name Pos Event_type Server_id Orig_log_pos Info
master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3
master-bin.000001 79 Query 1 79 use `test`; create table t1 (t timestamp)
master-bin.000001 143 Query 1 143 use `test`; create table t2 (t char(32))
master-bin.000001 206 Query 1 206 use `test`; SET ONE_SHOT TIME_ZONE='UTC'
master-bin.000001 269 Query 1 269 use `test`; insert into t1 values ('20040101000000'), ('20040611093902')
master-bin.000001 364 Query 1 364 use `test`; delete from t1
master-bin.000001 413 Query 1 413 use `test`; insert into t1 values ('20040101000000'), ('20040611093902')
set time_zone='MET';
insert into t2 (select t from t1);
select * from t1;
t
2003-12-31 22:00:00
2004-06-11 07:39:02
select * from t2;
t
2003-12-31 22:00:00
2004-06-11 07:39:02
delete from t2;
set timestamp=1000072000;
insert into t2 values (current_timestamp), (current_date), (current_time);
set timestamp=1000072000;
select current_timestamp, current_date, current_time;
current_timestamp current_date current_time
2001-09-10 01:46:40 2001-09-10 01:46:40
select * from t2;
t
2001-09-09 23:46:40
2001-09-09
23:46:40
delete from t2;
insert into t2 values (from_unixtime(1000000000)),
(unix_timestamp('2001-09-09 03:46:40'));
select * from t2;
t
2001-09-09 03:46:40
1000000000
select * from t2;
t
2001-09-09 03:46:40
1000000000
set global time_zone='MET';
ERROR HY000: Binary logging and replication forbid changing of the global server time zone
drop table t1, t2;

View file

@ -2071,7 +2071,14 @@ CREATE TABLE t1 (gvid int(10) unsigned default NULL, hmid int(10) unsigned defa
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
CREATE TABLE t2 ( hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, sampletid smallint(5) unsigned default NULL, sampletime datetime default NULL, samplevalue bigint(20) unsigned default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'NULL' AND b.sampletime < 'NULL' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
gvid the_success the_fail the_size the_time
Warnings:
Warning 1292 Truncated incorrect datetime value: 'wrong-date-value'
Warning 1292 Truncated incorrect datetime value: 'wrong-date-value'
Warning 1292 Truncated incorrect datetime value: 'wrong-date-value'
Warning 1292 Truncated incorrect datetime value: 'wrong-date-value'
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
gvid the_success the_fail the_size the_time
DROP TABLE t1,t2;
create table t1 ( A_Id bigint(20) NOT NULL default '0', A_UpdateBy char(10) NOT NULL default '', A_UpdateDate bigint(20) NOT NULL default '0', A_UpdateSerial int(11) NOT NULL default '0', other_types bigint(20) NOT NULL default '0', wss_type bigint(20) NOT NULL default '0');

View file

@ -9,6 +9,11 @@ help_relation
help_topic
host
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
show create table db;
Table Create Table

View file

@ -1,7 +1,7 @@
DROP TABLE IF EXISTS t1;
show variables like "timezone";
show variables like "system_time_zone";
Variable_name Value
timezone MET
system_time_zone MET
select @a:=FROM_UNIXTIME(1);
@a:=FROM_UNIXTIME(1)
1970-01-01 01:00:01
@ -32,6 +32,13 @@ ts from_unixtime(ts)
1048989599 2003-03-30 03:59:59
1048989601 2003-03-30 04:00:01
DROP TABLE t1;
CREATE TABLE t1 (ts timestamp);
INSERT INTO t1 (ts) VALUES ('2003-03-30 01:59:59'),
('2003-03-30 02:59:59'),
('2003-03-30 03:00:00');
Warnings:
Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2
DROP TABLE t1;
select unix_timestamp('1970-01-01 01:00:00'),
unix_timestamp('1970-01-01 01:00:01'),
unix_timestamp('2038-01-01 00:59:59'),

View file

@ -0,0 +1,246 @@
drop table if exists t1;
create table t1 (ts timestamp);
set time_zone='+00:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
0
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='+10:30';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
-37800
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='-10:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp())
36000
insert into t1 (ts) values ('2003-03-30 02:30:00');
select * from t1;
ts
2003-03-29 16:30:00
2003-03-29 06:00:00
2003-03-30 02:30:00
drop table t1;
select Name from mysql.time_zone_name where Name in
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow');
Name
Europe/Moscow
leap/Europe/Moscow
MET
Universal
UTC
create table t1 (i int, ts timestamp);
set time_zone='MET';
insert into t1 (i, ts) values
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00');
insert into t1 (i, ts) values
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'),
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'),
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00');
Warnings:
Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2
insert into t1 (i, ts) values
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00');
insert into t1 (i, ts) values
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'),
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'),
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59');
set time_zone='UTC';
select * from t1;
i ts
1046473200 2003-02-28 23:00:00
1048985999 2003-03-30 00:59:59
1048986000 2003-03-30 01:00:00
1048986000 2003-03-30 01:00:00
1051740000 2003-04-30 22:00:00
1067122800 2003-10-25 23:00:00
1067126400 2003-10-26 00:00:00
1067129999 2003-10-26 00:59:59
1067137200 2003-10-26 03:00:00
1067129999 2003-10-26 00:59:59
delete from t1;
set time_zone='Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
Warnings:
Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2
select * from t1;
i ts
1072904400 2004-01-01 00:00:00
1080428400 2004-03-28 03:00:00
1091304000 2003-08-01 00:00:00
1099175400 2004-10-31 02:30:00
delete from t1;
set time_zone='leap/Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
Warnings:
Warning 1299 Invalid TIMESTAMP value in column 'ts' at row 2
select * from t1;
i ts
1072904422 2004-01-01 00:00:00
1080428422 2004-03-28 03:00:00
1091304022 2003-08-01 00:00:00
1099175422 2004-10-31 02:30:00
delete from t1;
insert into t1 (i, ts) values
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'),
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00');
select * from t1;
i ts
362793608 1981-07-01 03:59:59
362793610 1981-07-01 04:00:00
select from_unixtime(362793609);
from_unixtime(362793609)
1981-07-01 03:59:60
drop table t1;
create table t1 (ts timestamp);
set time_zone='UTC';
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'),
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'),
('2037-12-31 23:59:59'),('2038-01-01 00:00:00');
Warnings:
Warning 1264 Data truncated; out of range for column 'ts' at row 2
Warning 1264 Data truncated; out of range for column 'ts' at row 3
Warning 1264 Data truncated; out of range for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 00:00:01
2037-12-31 23:59:59
0000-00-00 00:00:00
delete from t1;
set time_zone='MET';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'),
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'),
('2038-01-01 00:59:59'),('2038-01-01 01:00:00');
Warnings:
Warning 1264 Data truncated; out of range for column 'ts' at row 2
Warning 1264 Data truncated; out of range for column 'ts' at row 3
Warning 1264 Data truncated; out of range for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 01:00:01
2038-01-01 00:59:59
0000-00-00 00:00:00
delete from t1;
set time_zone='+01:30';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'),
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'),
('2038-01-01 01:29:59'),('2038-01-01 01:30:00');
Warnings:
Warning 1264 Data truncated; out of range for column 'ts' at row 2
Warning 1264 Data truncated; out of range for column 'ts' at row 3
Warning 1264 Data truncated; out of range for column 'ts' at row 6
select * from t1;
ts
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
1970-01-01 01:30:01
2038-01-01 01:29:59
0000-00-00 00:00:00
drop table t1;
show variables like 'time_zone';
Variable_name Value
time_zone +01:30
set time_zone = default;
show variables like 'time_zone';
Variable_name Value
time_zone SYSTEM
set time_zone= '0';
ERROR HY000: Unknown or incorrect time zone: '0'
set time_zone= '0:0';
ERROR HY000: Unknown or incorrect time zone: '0:0'
set time_zone= '-20:00';
ERROR HY000: Unknown or incorrect time zone: '-20:00'
set time_zone= '+20:00';
ERROR HY000: Unknown or incorrect time zone: '+20:00'
set time_zone= 'Some/Unknown/Time/Zone';
ERROR HY000: Unknown or incorrect time zone: 'Some/Unknown/Time/Zone'
select convert_tz(now(),'UTC', 'Universal') = now();
convert_tz(now(),'UTC', 'Universal') = now()
1
select convert_tz(now(),'utc', 'UTC') = now();
convert_tz(now(),'utc', 'UTC') = now()
1
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC');
convert_tz('1917-11-07 12:00:00', 'MET', 'UTC')
1917-11-07 12:00:00
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC');
convert_tz('1970-01-01 01:00:00', 'MET', 'UTC')
1970-01-01 01:00:00
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC');
convert_tz('1970-01-01 01:00:01', 'MET', 'UTC')
1970-01-01 00:00:01
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC');
convert_tz('2003-03-01 00:00:00', 'MET', 'UTC')
2003-02-28 23:00:00
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC');
convert_tz('2003-03-30 01:59:59', 'MET', 'UTC')
2003-03-30 00:59:59
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC');
convert_tz('2003-03-30 02:30:00', 'MET', 'UTC')
2003-03-30 01:00:00
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC');
convert_tz('2003-03-30 03:00:00', 'MET', 'UTC')
2003-03-30 01:00:00
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC');
convert_tz('2003-05-01 00:00:00', 'MET', 'UTC')
2003-04-30 22:00:00
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 01:00:00', 'MET', 'UTC')
2003-10-25 23:00:00
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 02:00:00', 'MET', 'UTC')
2003-10-26 00:00:00
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC');
convert_tz('2003-10-26 02:59:59', 'MET', 'UTC')
2003-10-26 00:59:59
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC');
convert_tz('2003-10-26 04:00:00', 'MET', 'UTC')
2003-10-26 03:00:00
select convert_tz('2038-01-01 00:59:59', 'MET', 'UTC');
convert_tz('2038-01-01 00:59:59', 'MET', 'UTC')
2037-12-31 23:59:59
select convert_tz('2038-01-01 01:00:00', 'MET', 'UTC');
convert_tz('2038-01-01 01:00:00', 'MET', 'UTC')
2038-01-01 01:00:00
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC');
convert_tz('2103-01-01 04:00:00', 'MET', 'UTC')
2103-01-01 04:00:00
create table t1 (tz varchar(3));
insert into t1 (tz) values ('MET'), ('UTC');
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz;
tz convert_tz('2003-12-31 00:00:00',tz,'UTC') convert_tz('2003-12-31 00:00:00','UTC',tz)
MET 2003-12-30 23:00:00 2003-12-31 01:00:00
UTC 2003-12-31 00:00:00 2003-12-31 00:00:00
drop table t1;
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC');
convert_tz('2003-12-31 04:00:00', NULL, 'UTC')
NULL
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC');
convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC')
NULL
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone');
convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone')
NULL
select convert_tz('2003-12-31 04:00:00', 'MET', NULL);
convert_tz('2003-12-31 04:00:00', 'MET', NULL)
NULL
select convert_tz( NULL, 'MET', 'UTC');
convert_tz( NULL, 'MET', 'UTC')
NULL

View file

@ -1,12 +1,6 @@
drop table if exists t1;
create table t1 (t datetime);
insert into t1 values(101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460);
Warnings:
Warning 1265 Data truncated for column 't' at row 13
Warning 1265 Data truncated for column 't' at row 14
Warning 1265 Data truncated for column 't' at row 15
Warning 1265 Data truncated for column 't' at row 16
Warning 1265 Data truncated for column 't' at row 17
insert into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);
select * from t1;
t
2000-01-01 00:00:00
@ -21,11 +15,8 @@ t
1999-12-31 23:59:59
1000-01-01 00:00:00
9999-12-31 23:59:59
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
2003-01-00 00:00:00
2003-00-00 00:00:00
delete from t1 where t > 0;
optimize table t1;
Table Op Msg_type Msg_text
@ -34,13 +25,7 @@ check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
delete from t1;
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460");
Warnings:
Warning 1264 Data truncated; out of range for column 't' at row 14
Warning 1264 Data truncated; out of range for column 't' at row 15
Warning 1264 Data truncated; out of range for column 't' at row 16
Warning 1264 Data truncated; out of range for column 't' at row 17
Warning 1264 Data truncated; out of range for column 't' at row 18
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");
select * from t1;
t
2000-01-01 00:00:00
@ -56,11 +41,8 @@ t
1999-12-31 23:59:59
1000-01-01 00:00:00
9999-12-31 23:59:59
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
2003-01-00 00:00:00
2003-00-00 00:00:00
drop table t1;
CREATE TABLE t1 (a timestamp, b date, c time, d datetime);
insert into t1 (b,c,d) values(now(),curtime(),now());
@ -114,3 +96,43 @@ insert into t1 values (now(), now());
select * from t1 where a is null or b is null;
a b
drop table t1;
create table t1 (t datetime);
insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460);
Warnings:
Warning 1265 Data truncated for column 't' at row 1
Warning 1265 Data truncated for column 't' at row 2
Warning 1265 Data truncated for column 't' at row 3
Warning 1265 Data truncated for column 't' at row 4
Warning 1265 Data truncated for column 't' at row 5
select * from t1;
t
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
delete from t1;
insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460");
Warnings:
Warning 1264 Data truncated; out of range for column 't' at row 1
Warning 1264 Data truncated; out of range for column 't' at row 2
Warning 1264 Data truncated; out of range for column 't' at row 3
Warning 1264 Data truncated; out of range for column 't' at row 4
Warning 1264 Data truncated; out of range for column 't' at row 5
select * from t1;
t
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
Warnings:
Warning 1264 Data truncated; out of range for column 't' at row 1
Warning 1264 Data truncated; out of range for column 't' at row 2
select * from t1;
t
0000-00-00 00:00:00
2003-01-01 00:00:00
drop table t1;

View file

@ -25,11 +25,11 @@ t
36:30:31
insert into t1 values("10.22.22"),(1234567),(123456789),(123456789.10),("10 22:22"),("12.45a");
Warnings:
Note 1292 Truncated incorrect time value: '10.22.22'
Warning 1265 Data truncated for column 't' at row 1
Warning 1264 Data truncated; out of range for column 't' at row 2
Warning 1264 Data truncated; out of range for column 't' at row 3
Warning 1264 Data truncated; out of range for column 't' at row 4
Note 1292 Truncated incorrect time value: '12.45a'
Warning 1265 Data truncated for column 't' at row 6
select * from t1;
t
10:22:33

View file

@ -43,13 +43,7 @@ date_format(a,"%Y %y") year(a) year(now())
1970 70 1970 1970
drop table t1;
create table t1 (ix timestamp);
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000),(20030101010160),(20030101016001),(20030101240101),(20030132010101),(20031301010101);
Warnings:
Warning 1265 Data truncated for column 'ix' at row 10
Warning 1265 Data truncated for column 'ix' at row 11
Warning 1265 Data truncated for column 'ix' at row 12
Warning 1265 Data truncated for column 'ix' at row 13
Warning 1265 Data truncated for column 'ix' at row 14
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000);
select ix+0 from t1;
ix+0
19991101000000
@ -61,24 +55,14 @@ ix+0
19990501000000
19991101000000
19990501000000
0
0
0
0
0
delete from t1;
insert into t1 values ("19991101000000"),("19990102030405"),("19990630232922"),("19990601000000"),("20030101010160"),("20030101016001"),("20030101240101"),("20030132010101"),("20031301010101");
insert into t1 values ("19991101000000"),("19990102030405"),("19990630232922"),("19990601000000");
select ix+0 from t1;
ix+0
19991101000000
19990102030405
19990630232922
19990601000000
0
0
0
0
0
drop table t1;
CREATE TABLE t1 (date date, date_time datetime, time_stamp timestamp);
INSERT INTO t1 VALUES ("1998-12-31","1998-12-31 23:59:59",19981231235959);
@ -128,6 +112,56 @@ t2 t4 t6 t8 t10 t12 t14
0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00 0000-00-00 00:00:00
1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59 1997-12-31 23:47:59
drop table t1;
create table t1 (ix timestamp);
insert into t1 values (0),(20030101010160),(20030101016001),(20030101240101),(20030132010101),(20031301010101),(20031200000000),(20030000000000);
Warnings:
Warning 1265 Data truncated for column 'ix' at row 2
Warning 1265 Data truncated for column 'ix' at row 3
Warning 1265 Data truncated for column 'ix' at row 4
Warning 1265 Data truncated for column 'ix' at row 5
Warning 1265 Data truncated for column 'ix' at row 6
Warning 1265 Data truncated for column 'ix' at row 7
Warning 1265 Data truncated for column 'ix' at row 8
select ix+0 from t1;
ix+0
0
0
0
0
0
0
0
0
delete from t1;
insert into t1 values ("00000000000000"),("20030101010160"),("20030101016001"),("20030101240101"),("20030132010101"),("20031301010101"),("20031200000000"),("20030000000000");
Warnings:
Warning 1265 Data truncated for column 'ix' at row 2
Warning 1265 Data truncated for column 'ix' at row 3
Warning 1265 Data truncated for column 'ix' at row 4
Warning 1265 Data truncated for column 'ix' at row 5
Warning 1265 Data truncated for column 'ix' at row 6
Warning 1265 Data truncated for column 'ix' at row 7
Warning 1265 Data truncated for column 'ix' at row 8
select ix+0 from t1;
ix+0
0
0
0
0
0
0
0
0
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
Warnings:
Warning 1265 Data truncated for column 'ix' at row 1
Warning 1265 Data truncated for column 'ix' at row 2
select ix+0 from t1;
ix+0
0
20030101000000
drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
create table t1 (t1 timestamp, t2 timestamp on update now());

View file

@ -0,0 +1 @@
--default-time-zone=Europe/Moscow

View file

@ -0,0 +1 @@
--default-time-zone=Europe/Moscow

View file

@ -0,0 +1,84 @@
# Test of replication of time zones.
source include/master-slave.inc;
# Some preparations
let $VERSION=`select version()`;
create table t1 (t timestamp);
create table t2 (t char(32));
#
# Let us check how well replication works when we are saving datetime
# value in TIMESTAMP field.
#
connection master;
select @@time_zone;
set time_zone='UTC';
insert into t1 values ('20040101000000'), ('20040611093902');
select * from t1;
# On slave we still in 'Europe/Moscow' so we should see equivalent but
# textually different values.
sync_slave_with_master;
select * from t1;
# Let us check also that setting of time_zone back to default also works
# well
connection master;
delete from t1;
set time_zone='Europe/Moscow';
insert into t1 values ('20040101000000'), ('20040611093902');
select * from t1;
sync_slave_with_master;
select * from t1;
connection master;
# We should not see SET ONE_SHOT time_zone before second insert
--replace_result $VERSION VERSION
show binlog events;
#
# Now let us check how well we replicate statments reading TIMESTAMP fields
# (We should see the same data on master and on slave but it should differ
# from originally inserted)
#
set time_zone='MET';
insert into t2 (select t from t1);
select * from t1;
sync_slave_with_master;
select * from t2;
#
# Now let us check how well we replicate various CURRENT_* functions
#
connection master;
delete from t2;
set timestamp=1000072000;
insert into t2 values (current_timestamp), (current_date), (current_time);
sync_slave_with_master;
# Values in ouput of these to queries should differ because we are in
# in 'MET' on master and in 'Europe/Moscow on slave...
set timestamp=1000072000;
select current_timestamp, current_date, current_time;
select * from t2;
#
# At last let us check replication of FROM_UNIXTIME/UNIX_TIMESTAMP functions.
#
connection master;
delete from t2;
insert into t2 values (from_unixtime(1000000000)),
(unix_timestamp('2001-09-09 03:46:40'));
select * from t2;
sync_slave_with_master;
# We should get same result on slave as on master
select * from t2;
#
# Let us check that we are not allowing to set global time_zone with
# replication
#
connection master;
--error 1105
set global time_zone='MET';
# Clean up
drop table t1, t2;
sync_slave_with_master;

View file

@ -1771,7 +1771,9 @@ CREATE TABLE t1 (gvid int(10) unsigned default NULL, hmid int(10) unsigned defa
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
CREATE TABLE t2 ( hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, sampletid smallint(5) unsigned default NULL, sampletime datetime default NULL, samplevalue bigint(20) unsigned default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'NULL' AND b.sampletime < 'NULL' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
# Testing the same select with NULL's instead of invalid datetime values
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
DROP TABLE t1,t2;
#

View file

@ -1,5 +1,6 @@
#
# Test of timezone handling. This script must be run with TZ=MET
# Test of SYSTEM time zone handling ( for my_system_gmt_sec()).
# This script must be run with TZ=MET
-- require r/have_met_timezone.require
disable_query_log;
@ -13,7 +14,7 @@ DROP TABLE IF EXISTS t1;
# The following is because of daylight saving time
--replace_result MEST MET
show variables like "timezone";
show variables like "system_time_zone";
#
# Test unix timestamp
@ -40,6 +41,16 @@ INSERT INTO t1 (ts) VALUES (Unix_timestamp('2003-03-30 04:00:01'));
SELECT ts,from_unixtime(ts) FROM t1;
DROP TABLE t1;
#
# Test of warning for spring time-gap values for system time zone
#
CREATE TABLE t1 (ts timestamp);
INSERT INTO t1 (ts) VALUES ('2003-03-30 01:59:59'),
('2003-03-30 02:59:59'),
('2003-03-30 03:00:00');
DROP TABLE t1;
#
# Test for fix for Bug#2523
#

189
mysql-test/t/timezone2.test Normal file
View file

@ -0,0 +1,189 @@
# This script tests our own time zone support functions
# Preparing playground
--disable_warnings
drop table if exists t1;
--enable_warnings
#
# Let us first check +HH:MM style timezones
#
create table t1 (ts timestamp);
set time_zone='+00:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='+10:30';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
insert into t1 (ts) values ('2003-03-30 02:30:00');
set time_zone='-10:00';
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
insert into t1 (ts) values ('2003-03-30 02:30:00');
# Here we will get different results
select * from t1;
drop table t1;
#
# Let us try DB specified time zones
#
select Name from mysql.time_zone_name where Name in
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow');
create table t1 (i int, ts timestamp);
set time_zone='MET';
# We check common date time value and non existent or ambiguios values
# Normal value without DST
insert into t1 (i, ts) values
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00');
# Values around and in spring time-gap
insert into t1 (i, ts) values
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'),
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'),
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00');
# Normal value with DST
insert into t1 (i, ts) values
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00');
# Ambiguos values (also check for determenism)
insert into t1 (i, ts) values
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'),
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'),
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'),
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59');
set time_zone='UTC';
select * from t1;
delete from t1;
# Simple check for 'Europe/Moscow' time zone just for showing that it works
set time_zone='Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
select * from t1;
delete from t1;
#
# Check for time zone with leap seconds
# Values in ts column must be the same but values in i column should
# differ from corresponding values for Europe/Moscow a bit.
#
set time_zone='leap/Europe/Moscow';
insert into t1 (i, ts) values
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
select * from t1;
delete from t1;
# Let us test leap jump
insert into t1 (i, ts) values
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'),
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00');
select * from t1;
# Additional 60ieth second!
select from_unixtime(362793609);
drop table t1;
#
# Let us test range for TIMESTAMP
#
create table t1 (ts timestamp);
set time_zone='UTC';
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'),
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'),
('2037-12-31 23:59:59'),('2038-01-01 00:00:00');
select * from t1;
delete from t1;
# MET time zone has range shifted by one hour
set time_zone='MET';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'),
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'),
('2038-01-01 00:59:59'),('2038-01-01 01:00:00');
select * from t1;
delete from t1;
# same for +01:30 time zone
set time_zone='+01:30';
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'),
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'),
('2038-01-01 01:29:59'),('2038-01-01 01:30:00');
select * from t1;
drop table t1;
#
# Test of show variables
#
show variables like 'time_zone';
set time_zone = default;
show variables like 'time_zone';
#
# Let us try some invalid time zone specifications
#
--error 1298
set time_zone= '0';
--error 1298
set time_zone= '0:0';
--error 1298
set time_zone= '-20:00';
--error 1298
set time_zone= '+20:00';
--error 1298
set time_zone= 'Some/Unknown/Time/Zone';
# Let us check that aliases for time zones work and they are
# case-insensitive
select convert_tz(now(),'UTC', 'Universal') = now();
select convert_tz(now(),'utc', 'UTC') = now();
#
# Let us test CONVERT_TZ function (may be func_time.test is better place).
#
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC');
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC');
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC');
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC');
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC');
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC');
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC');
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC');
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC');
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC');
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC');
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC');
select convert_tz('2038-01-01 00:59:59', 'MET', 'UTC');
select convert_tz('2038-01-01 01:00:00', 'MET', 'UTC');
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC');
# Let us test variable time zone argument
create table t1 (tz varchar(3));
insert into t1 (tz) values ('MET'), ('UTC');
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz;
drop table t1;
# Parameters to CONVERT_TZ() what should give NULL
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC');
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC');
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone');
select convert_tz('2003-12-31 04:00:00', 'MET', NULL);
select convert_tz( NULL, 'MET', 'UTC');

View file

@ -7,13 +7,13 @@ drop table if exists t1;
--enable_warnings
create table t1 (t datetime);
insert into t1 values(101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460);
insert into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);
select * from t1;
delete from t1 where t > 0;
optimize table t1;
check table t1;
delete from t1;
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460");
insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");
select * from t1;
drop table t1;
@ -71,3 +71,18 @@ insert into t1 values (now(), now());
insert into t1 values (now(), now());
select * from t1 where a is null or b is null;
drop table t1;
#
# Let us check if we properly treat wrong datetimes and produce proper
# warnings (for both strings and numbers)
#
create table t1 (t datetime);
insert into t1 values (20030102030460),(20030102036301),(20030102240401),(20030132030401),(20031302030460);
select * from t1;
delete from t1;
insert into t1 values ("20030102030460"),("20030102036301"),("20030102240401"),("20030132030401"),("20031302030460");
select * from t1;
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
select * from t1;
drop table t1;

View file

@ -37,10 +37,10 @@ select date_format(a,"%Y %y"),year(a),year(now()) from t1;
drop table t1;
create table t1 (ix timestamp);
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000),(20030101010160),(20030101016001),(20030101240101),(20030132010101),(20031301010101);
insert into t1 values (19991101000000),(19990102030405),(19990630232922),(19990601000000),(19990930232922),(19990531232922),(19990501000000),(19991101000000),(19990501000000);
select ix+0 from t1;
delete from t1;
insert into t1 values ("19991101000000"),("19990102030405"),("19990630232922"),("19990601000000"),("20030101010160"),("20030101016001"),("20030101240101"),("20030132010101"),("20031301010101");
insert into t1 values ("19991101000000"),("19990102030405"),("19990630232922"),("19990601000000");
select ix+0 from t1;
drop table t1;
@ -75,6 +75,21 @@ set new=1;
select * from t1;
drop table t1;
#
# Let us check if we properly treat wrong datetimes and produce proper warnings
# (for both strings and numbers)
#
create table t1 (ix timestamp);
insert into t1 values (0),(20030101010160),(20030101016001),(20030101240101),(20030132010101),(20031301010101),(20031200000000),(20030000000000);
select ix+0 from t1;
delete from t1;
insert into t1 values ("00000000000000"),("20030101010160"),("20030101016001"),("20030101240101"),("20030132010101"),("20031301010101"),("20031200000000"),("20030000000000");
select ix+0 from t1;
delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
select ix+0 from t1;
drop table t1;
#
# Test for TIMESTAMP column with default now() and on update now() clauses
#

View file

@ -39,6 +39,8 @@ c_hc=""
c_hr=""
c_hk=""
i_ht=""
c_tzn="" c_tz="" c_tzt="" c_tztt="" c_tzls=""
i_tzn="" i_tz="" i_tzt="" i_tztt="" i_tzls=""
# Check for old tables
if test ! -f $mdata/db.frm
@ -285,6 +287,332 @@ then
c_hr="$c_hr comment='keyword-topic relation';"
fi
if test ! -f $mdata/time_zone_name.frm
then
if test "$1" = "verbose" ; then
echo "Preparing time_zone_name table" 1>&2;
fi
c_tzn="$c_tzn CREATE TABLE time_zone_name ("
c_tzn="$c_tzn Name char(64) NOT NULL,"
c_tzn="$c_tzn Time_zone_id int unsigned NOT NULL,"
c_tzn="$c_tzn PRIMARY KEY Name (Name)"
c_tzn="$c_tzn ) DEFAULT CHARACTER SET latin1"
c_tzn="$c_tzn comment='Time zone names';"
if test "$1" = "test"
then
i_tzn="$i_tzn INSERT INTO time_zone_name (Name, Time_Zone_id) VALUES"
i_tzn="$i_tzn ('MET', 1), ('UTC', 2), ('Universal', 2), "
i_tzn="$i_tzn ('Europe/Moscow',3), ('leap/Europe/Moscow',4);"
fi
fi
if test ! -f $mdata/time_zone.frm
then
if test "$1" = "verbose" ; then
echo "Preparing time_zone table" 1>&2;
fi
c_tz="$c_tz CREATE TABLE time_zone ("
c_tz="$c_tz Time_zone_id int unsigned NOT NULL auto_increment,"
c_tz="$c_tz Use_leap_seconds enum('Y','N') DEFAULT 'N' NOT NULL,"
c_tz="$c_tz PRIMARY KEY TzId (Time_zone_id)"
c_tz="$c_tz ) DEFAULT CHARACTER SET latin1"
c_tz="$c_tz comment='Time zones';"
if test "$1" = "test"
then
i_tz="$i_tz INSERT INTO time_zone (Time_zone_id, Use_leap_seconds)"
i_tz="$i_tz VALUES (1,'N'), (2,'N'), (3,'N'), (4,'Y');"
fi
fi
if test ! -f $mdata/time_zone_transition.frm
then
if test "$1" = "verbose" ; then
echo "Preparing time_zone_transition table" 1>&2;
fi
c_tzt="$c_tzt CREATE TABLE time_zone_transition ("
c_tzt="$c_tzt Time_zone_id int unsigned NOT NULL,"
c_tzt="$c_tzt Transition_time bigint signed NOT NULL,"
c_tzt="$c_tzt Transition_type_id int unsigned NOT NULL,"
c_tzt="$c_tzt PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time)"
c_tzt="$c_tzt ) DEFAULT CHARACTER SET latin1"
c_tzt="$c_tzt comment='Time zone transitions';"
if test "$1" = "test"
then
i_tzt="$i_tzt INSERT INTO time_zone_transition"
i_tzt="$i_tzt (Time_zone_id, Transition_time, Transition_type_id)"
i_tzt="$i_tzt VALUES"
i_tzt="$i_tzt (1, -1693706400, 0) ,(1, -1680483600, 1)"
i_tzt="$i_tzt ,(1, -1663455600, 2) ,(1, -1650150000, 3)"
i_tzt="$i_tzt ,(1, -1632006000, 2) ,(1, -1618700400, 3)"
i_tzt="$i_tzt ,(1, -938905200, 2) ,(1, -857257200, 3)"
i_tzt="$i_tzt ,(1, -844556400, 2) ,(1, -828226800, 3)"
i_tzt="$i_tzt ,(1, -812502000, 2) ,(1, -796777200, 3)"
i_tzt="$i_tzt ,(1, 228877200, 2) ,(1, 243997200, 3)"
i_tzt="$i_tzt ,(1, 260326800, 2) ,(1, 276051600, 3)"
i_tzt="$i_tzt ,(1, 291776400, 2) ,(1, 307501200, 3)"
i_tzt="$i_tzt ,(1, 323830800, 2) ,(1, 338950800, 3)"
i_tzt="$i_tzt ,(1, 354675600, 2) ,(1, 370400400, 3)"
i_tzt="$i_tzt ,(1, 386125200, 2) ,(1, 401850000, 3)"
i_tzt="$i_tzt ,(1, 417574800, 2) ,(1, 433299600, 3)"
i_tzt="$i_tzt ,(1, 449024400, 2) ,(1, 465354000, 3)"
i_tzt="$i_tzt ,(1, 481078800, 2) ,(1, 496803600, 3)"
i_tzt="$i_tzt ,(1, 512528400, 2) ,(1, 528253200, 3)"
i_tzt="$i_tzt ,(1, 543978000, 2) ,(1, 559702800, 3)"
i_tzt="$i_tzt ,(1, 575427600, 2) ,(1, 591152400, 3)"
i_tzt="$i_tzt ,(1, 606877200, 2) ,(1, 622602000, 3)"
i_tzt="$i_tzt ,(1, 638326800, 2) ,(1, 654656400, 3)"
i_tzt="$i_tzt ,(1, 670381200, 2) ,(1, 686106000, 3)"
i_tzt="$i_tzt ,(1, 701830800, 2) ,(1, 717555600, 3)"
i_tzt="$i_tzt ,(1, 733280400, 2) ,(1, 749005200, 3)"
i_tzt="$i_tzt ,(1, 764730000, 2) ,(1, 780454800, 3)"
i_tzt="$i_tzt ,(1, 796179600, 2) ,(1, 811904400, 3)"
i_tzt="$i_tzt ,(1, 828234000, 2) ,(1, 846378000, 3)"
i_tzt="$i_tzt ,(1, 859683600, 2) ,(1, 877827600, 3)"
i_tzt="$i_tzt ,(1, 891133200, 2) ,(1, 909277200, 3)"
i_tzt="$i_tzt ,(1, 922582800, 2) ,(1, 941331600, 3)"
i_tzt="$i_tzt ,(1, 954032400, 2) ,(1, 972781200, 3)"
i_tzt="$i_tzt ,(1, 985482000, 2) ,(1, 1004230800, 3)"
i_tzt="$i_tzt ,(1, 1017536400, 2) ,(1, 1035680400, 3)"
i_tzt="$i_tzt ,(1, 1048986000, 2) ,(1, 1067130000, 3)"
i_tzt="$i_tzt ,(1, 1080435600, 2) ,(1, 1099184400, 3)"
i_tzt="$i_tzt ,(1, 1111885200, 2) ,(1, 1130634000, 3)"
i_tzt="$i_tzt ,(1, 1143334800, 2) ,(1, 1162083600, 3)"
i_tzt="$i_tzt ,(1, 1174784400, 2) ,(1, 1193533200, 3)"
i_tzt="$i_tzt ,(1, 1206838800, 2) ,(1, 1224982800, 3)"
i_tzt="$i_tzt ,(1, 1238288400, 2) ,(1, 1256432400, 3)"
i_tzt="$i_tzt ,(1, 1269738000, 2) ,(1, 1288486800, 3)"
i_tzt="$i_tzt ,(1, 1301187600, 2) ,(1, 1319936400, 3)"
i_tzt="$i_tzt ,(1, 1332637200, 2) ,(1, 1351386000, 3)"
i_tzt="$i_tzt ,(1, 1364691600, 2) ,(1, 1382835600, 3)"
i_tzt="$i_tzt ,(1, 1396141200, 2) ,(1, 1414285200, 3)"
i_tzt="$i_tzt ,(1, 1427590800, 2) ,(1, 1445734800, 3)"
i_tzt="$i_tzt ,(1, 1459040400, 2) ,(1, 1477789200, 3)"
i_tzt="$i_tzt ,(1, 1490490000, 2) ,(1, 1509238800, 3)"
i_tzt="$i_tzt ,(1, 1521939600, 2) ,(1, 1540688400, 3)"
i_tzt="$i_tzt ,(1, 1553994000, 2) ,(1, 1572138000, 3)"
i_tzt="$i_tzt ,(1, 1585443600, 2) ,(1, 1603587600, 3)"
i_tzt="$i_tzt ,(1, 1616893200, 2) ,(1, 1635642000, 3)"
i_tzt="$i_tzt ,(1, 1648342800, 2) ,(1, 1667091600, 3)"
i_tzt="$i_tzt ,(1, 1679792400, 2) ,(1, 1698541200, 3)"
i_tzt="$i_tzt ,(1, 1711846800, 2) ,(1, 1729990800, 3)"
i_tzt="$i_tzt ,(1, 1743296400, 2) ,(1, 1761440400, 3)"
i_tzt="$i_tzt ,(1, 1774746000, 2) ,(1, 1792890000, 3)"
i_tzt="$i_tzt ,(1, 1806195600, 2) ,(1, 1824944400, 3)"
i_tzt="$i_tzt ,(1, 1837645200, 2) ,(1, 1856394000, 3)"
i_tzt="$i_tzt ,(1, 1869094800, 2) ,(1, 1887843600, 3)"
i_tzt="$i_tzt ,(1, 1901149200, 2) ,(1, 1919293200, 3)"
i_tzt="$i_tzt ,(1, 1932598800, 2) ,(1, 1950742800, 3)"
i_tzt="$i_tzt ,(1, 1964048400, 2) ,(1, 1982797200, 3)"
i_tzt="$i_tzt ,(1, 1995498000, 2) ,(1, 2014246800, 3)"
i_tzt="$i_tzt ,(1, 2026947600, 2) ,(1, 2045696400, 3)"
i_tzt="$i_tzt ,(1, 2058397200, 2) ,(1, 2077146000, 3)"
i_tzt="$i_tzt ,(1, 2090451600, 2) ,(1, 2108595600, 3)"
i_tzt="$i_tzt ,(1, 2121901200, 2) ,(1, 2140045200, 3)"
i_tzt="$i_tzt ,(3, -1688265000, 2) ,(3, -1656819048, 1)"
i_tzt="$i_tzt ,(3, -1641353448, 2) ,(3, -1627965048, 3)"
i_tzt="$i_tzt ,(3, -1618716648, 1) ,(3, -1596429048, 3)"
i_tzt="$i_tzt ,(3, -1593829848, 5) ,(3, -1589860800, 4)"
i_tzt="$i_tzt ,(3, -1542427200, 5) ,(3, -1539493200, 6)"
i_tzt="$i_tzt ,(3, -1525323600, 5) ,(3, -1522728000, 4)"
i_tzt="$i_tzt ,(3, -1491188400, 7) ,(3, -1247536800, 4)"
i_tzt="$i_tzt ,(3, 354920400, 5) ,(3, 370728000, 4)"
i_tzt="$i_tzt ,(3, 386456400, 5) ,(3, 402264000, 4)"
i_tzt="$i_tzt ,(3, 417992400, 5) ,(3, 433800000, 4)"
i_tzt="$i_tzt ,(3, 449614800, 5) ,(3, 465346800, 8)"
i_tzt="$i_tzt ,(3, 481071600, 9) ,(3, 496796400, 8)"
i_tzt="$i_tzt ,(3, 512521200, 9) ,(3, 528246000, 8)"
i_tzt="$i_tzt ,(3, 543970800, 9) ,(3, 559695600, 8)"
i_tzt="$i_tzt ,(3, 575420400, 9) ,(3, 591145200, 8)"
i_tzt="$i_tzt ,(3, 606870000, 9) ,(3, 622594800, 8)"
i_tzt="$i_tzt ,(3, 638319600, 9) ,(3, 654649200, 8)"
i_tzt="$i_tzt ,(3, 670374000, 10) ,(3, 686102400, 11)"
i_tzt="$i_tzt ,(3, 695779200, 8) ,(3, 701812800, 5)"
i_tzt="$i_tzt ,(3, 717534000, 4) ,(3, 733273200, 9)"
i_tzt="$i_tzt ,(3, 748998000, 8) ,(3, 764722800, 9)"
i_tzt="$i_tzt ,(3, 780447600, 8) ,(3, 796172400, 9)"
i_tzt="$i_tzt ,(3, 811897200, 8) ,(3, 828226800, 9)"
i_tzt="$i_tzt ,(3, 846370800, 8) ,(3, 859676400, 9)"
i_tzt="$i_tzt ,(3, 877820400, 8) ,(3, 891126000, 9)"
i_tzt="$i_tzt ,(3, 909270000, 8) ,(3, 922575600, 9)"
i_tzt="$i_tzt ,(3, 941324400, 8) ,(3, 954025200, 9)"
i_tzt="$i_tzt ,(3, 972774000, 8) ,(3, 985474800, 9)"
i_tzt="$i_tzt ,(3, 1004223600, 8) ,(3, 1017529200, 9)"
i_tzt="$i_tzt ,(3, 1035673200, 8) ,(3, 1048978800, 9)"
i_tzt="$i_tzt ,(3, 1067122800, 8) ,(3, 1080428400, 9)"
i_tzt="$i_tzt ,(3, 1099177200, 8) ,(3, 1111878000, 9)"
i_tzt="$i_tzt ,(3, 1130626800, 8) ,(3, 1143327600, 9)"
i_tzt="$i_tzt ,(3, 1162076400, 8) ,(3, 1174777200, 9)"
i_tzt="$i_tzt ,(3, 1193526000, 8) ,(3, 1206831600, 9)"
i_tzt="$i_tzt ,(3, 1224975600, 8) ,(3, 1238281200, 9)"
i_tzt="$i_tzt ,(3, 1256425200, 8) ,(3, 1269730800, 9)"
i_tzt="$i_tzt ,(3, 1288479600, 8) ,(3, 1301180400, 9)"
i_tzt="$i_tzt ,(3, 1319929200, 8) ,(3, 1332630000, 9)"
i_tzt="$i_tzt ,(3, 1351378800, 8) ,(3, 1364684400, 9)"
i_tzt="$i_tzt ,(3, 1382828400, 8) ,(3, 1396134000, 9)"
i_tzt="$i_tzt ,(3, 1414278000, 8) ,(3, 1427583600, 9)"
i_tzt="$i_tzt ,(3, 1445727600, 8) ,(3, 1459033200, 9)"
i_tzt="$i_tzt ,(3, 1477782000, 8) ,(3, 1490482800, 9)"
i_tzt="$i_tzt ,(3, 1509231600, 8) ,(3, 1521932400, 9)"
i_tzt="$i_tzt ,(3, 1540681200, 8) ,(3, 1553986800, 9)"
i_tzt="$i_tzt ,(3, 1572130800, 8) ,(3, 1585436400, 9)"
i_tzt="$i_tzt ,(3, 1603580400, 8) ,(3, 1616886000, 9)"
i_tzt="$i_tzt ,(3, 1635634800, 8) ,(3, 1648335600, 9)"
i_tzt="$i_tzt ,(3, 1667084400, 8) ,(3, 1679785200, 9)"
i_tzt="$i_tzt ,(3, 1698534000, 8) ,(3, 1711839600, 9)"
i_tzt="$i_tzt ,(3, 1729983600, 8) ,(3, 1743289200, 9)"
i_tzt="$i_tzt ,(3, 1761433200, 8) ,(3, 1774738800, 9)"
i_tzt="$i_tzt ,(3, 1792882800, 8) ,(3, 1806188400, 9)"
i_tzt="$i_tzt ,(3, 1824937200, 8) ,(3, 1837638000, 9)"
i_tzt="$i_tzt ,(3, 1856386800, 8) ,(3, 1869087600, 9)"
i_tzt="$i_tzt ,(3, 1887836400, 8) ,(3, 1901142000, 9)"
i_tzt="$i_tzt ,(3, 1919286000, 8) ,(3, 1932591600, 9)"
i_tzt="$i_tzt ,(3, 1950735600, 8) ,(3, 1964041200, 9)"
i_tzt="$i_tzt ,(3, 1982790000, 8) ,(3, 1995490800, 9)"
i_tzt="$i_tzt ,(3, 2014239600, 8) ,(3, 2026940400, 9)"
i_tzt="$i_tzt ,(3, 2045689200, 8) ,(3, 2058390000, 9)"
i_tzt="$i_tzt ,(3, 2077138800, 8) ,(3, 2090444400, 9)"
i_tzt="$i_tzt ,(3, 2108588400, 8) ,(3, 2121894000, 9)"
i_tzt="$i_tzt ,(3, 2140038000, 8)"
i_tzt="$i_tzt ,(4, -1688265000, 2) ,(4, -1656819048, 1)"
i_tzt="$i_tzt ,(4, -1641353448, 2) ,(4, -1627965048, 3)"
i_tzt="$i_tzt ,(4, -1618716648, 1) ,(4, -1596429048, 3)"
i_tzt="$i_tzt ,(4, -1593829848, 5) ,(4, -1589860800, 4)"
i_tzt="$i_tzt ,(4, -1542427200, 5) ,(4, -1539493200, 6)"
i_tzt="$i_tzt ,(4, -1525323600, 5) ,(4, -1522728000, 4)"
i_tzt="$i_tzt ,(4, -1491188400, 7) ,(4, -1247536800, 4)"
i_tzt="$i_tzt ,(4, 354920409, 5) ,(4, 370728010, 4)"
i_tzt="$i_tzt ,(4, 386456410, 5) ,(4, 402264011, 4)"
i_tzt="$i_tzt ,(4, 417992411, 5) ,(4, 433800012, 4)"
i_tzt="$i_tzt ,(4, 449614812, 5) ,(4, 465346812, 8)"
i_tzt="$i_tzt ,(4, 481071612, 9) ,(4, 496796413, 8)"
i_tzt="$i_tzt ,(4, 512521213, 9) ,(4, 528246013, 8)"
i_tzt="$i_tzt ,(4, 543970813, 9) ,(4, 559695613, 8)"
i_tzt="$i_tzt ,(4, 575420414, 9) ,(4, 591145214, 8)"
i_tzt="$i_tzt ,(4, 606870014, 9) ,(4, 622594814, 8)"
i_tzt="$i_tzt ,(4, 638319615, 9) ,(4, 654649215, 8)"
i_tzt="$i_tzt ,(4, 670374016, 10) ,(4, 686102416, 11)"
i_tzt="$i_tzt ,(4, 695779216, 8) ,(4, 701812816, 5)"
i_tzt="$i_tzt ,(4, 717534017, 4) ,(4, 733273217, 9)"
i_tzt="$i_tzt ,(4, 748998018, 8) ,(4, 764722818, 9)"
i_tzt="$i_tzt ,(4, 780447619, 8) ,(4, 796172419, 9)"
i_tzt="$i_tzt ,(4, 811897219, 8) ,(4, 828226820, 9)"
i_tzt="$i_tzt ,(4, 846370820, 8) ,(4, 859676420, 9)"
i_tzt="$i_tzt ,(4, 877820421, 8) ,(4, 891126021, 9)"
i_tzt="$i_tzt ,(4, 909270021, 8) ,(4, 922575622, 9)"
i_tzt="$i_tzt ,(4, 941324422, 8) ,(4, 954025222, 9)"
i_tzt="$i_tzt ,(4, 972774022, 8) ,(4, 985474822, 9)"
i_tzt="$i_tzt ,(4, 1004223622, 8) ,(4, 1017529222, 9)"
i_tzt="$i_tzt ,(4, 1035673222, 8) ,(4, 1048978822, 9)"
i_tzt="$i_tzt ,(4, 1067122822, 8) ,(4, 1080428422, 9)"
i_tzt="$i_tzt ,(4, 1099177222, 8) ,(4, 1111878022, 9)"
i_tzt="$i_tzt ,(4, 1130626822, 8) ,(4, 1143327622, 9)"
i_tzt="$i_tzt ,(4, 1162076422, 8) ,(4, 1174777222, 9)"
i_tzt="$i_tzt ,(4, 1193526022, 8) ,(4, 1206831622, 9)"
i_tzt="$i_tzt ,(4, 1224975622, 8) ,(4, 1238281222, 9)"
i_tzt="$i_tzt ,(4, 1256425222, 8) ,(4, 1269730822, 9)"
i_tzt="$i_tzt ,(4, 1288479622, 8) ,(4, 1301180422, 9)"
i_tzt="$i_tzt ,(4, 1319929222, 8) ,(4, 1332630022, 9)"
i_tzt="$i_tzt ,(4, 1351378822, 8) ,(4, 1364684422, 9)"
i_tzt="$i_tzt ,(4, 1382828422, 8) ,(4, 1396134022, 9)"
i_tzt="$i_tzt ,(4, 1414278022, 8) ,(4, 1427583622, 9)"
i_tzt="$i_tzt ,(4, 1445727622, 8) ,(4, 1459033222, 9)"
i_tzt="$i_tzt ,(4, 1477782022, 8) ,(4, 1490482822, 9)"
i_tzt="$i_tzt ,(4, 1509231622, 8) ,(4, 1521932422, 9)"
i_tzt="$i_tzt ,(4, 1540681222, 8) ,(4, 1553986822, 9)"
i_tzt="$i_tzt ,(4, 1572130822, 8) ,(4, 1585436422, 9)"
i_tzt="$i_tzt ,(4, 1603580422, 8) ,(4, 1616886022, 9)"
i_tzt="$i_tzt ,(4, 1635634822, 8) ,(4, 1648335622, 9)"
i_tzt="$i_tzt ,(4, 1667084422, 8) ,(4, 1679785222, 9)"
i_tzt="$i_tzt ,(4, 1698534022, 8) ,(4, 1711839622, 9)"
i_tzt="$i_tzt ,(4, 1729983622, 8) ,(4, 1743289222, 9)"
i_tzt="$i_tzt ,(4, 1761433222, 8) ,(4, 1774738822, 9)"
i_tzt="$i_tzt ,(4, 1792882822, 8) ,(4, 1806188422, 9)"
i_tzt="$i_tzt ,(4, 1824937222, 8) ,(4, 1837638022, 9)"
i_tzt="$i_tzt ,(4, 1856386822, 8) ,(4, 1869087622, 9)"
i_tzt="$i_tzt ,(4, 1887836422, 8) ,(4, 1901142022, 9)"
i_tzt="$i_tzt ,(4, 1919286022, 8) ,(4, 1932591622, 9)"
i_tzt="$i_tzt ,(4, 1950735622, 8) ,(4, 1964041222, 9)"
i_tzt="$i_tzt ,(4, 1982790022, 8) ,(4, 1995490822, 9)"
i_tzt="$i_tzt ,(4, 2014239622, 8) ,(4, 2026940422, 9)"
i_tzt="$i_tzt ,(4, 2045689222, 8) ,(4, 2058390022, 9)"
i_tzt="$i_tzt ,(4, 2077138822, 8) ,(4, 2090444422, 9)"
i_tzt="$i_tzt ,(4, 2108588422, 8) ,(4, 2121894022, 9)"
i_tzt="$i_tzt ,(4, 2140038022, 8);"
fi
fi
if test ! -f $mdata/time_zone_transition_type.frm
then
if test "$1" = "verbose" ; then
echo "Preparing time_zone_transition_type table" 1>&2;
fi
c_tztt="$c_tztt CREATE TABLE time_zone_transition_type ("
c_tztt="$c_tztt Time_zone_id int unsigned NOT NULL,"
c_tztt="$c_tztt Transition_type_id int unsigned NOT NULL,"
c_tztt="$c_tztt Offset int signed DEFAULT 0 NOT NULL,"
c_tztt="$c_tztt Is_DST tinyint unsigned DEFAULT 0 NOT NULL,"
c_tztt="$c_tztt Abbreviation char(8) DEFAULT '' NOT NULL,"
c_tztt="$c_tztt PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id)"
c_tztt="$c_tztt ) DEFAULT CHARACTER SET latin1"
c_tztt="$c_tztt comment='Time zone transition types';"
if test "$1" = "test"
then
i_tztt="$i_tztt INSERT INTO time_zone_transition_type (Time_zone_id,"
i_tztt="$i_tztt Transition_type_id, Offset, Is_DST, Abbreviation) VALUES"
i_tztt="$i_tztt (1, 0, 7200, 1, 'MEST') ,(1, 1, 3600, 0, 'MET')"
i_tztt="$i_tztt ,(1, 2, 7200, 1, 'MEST') ,(1, 3, 3600, 0, 'MET')"
i_tztt="$i_tztt ,(2, 0, 0, 0, 'UTC')"
i_tztt="$i_tztt ,(3, 0, 9000, 0, 'MMT') ,(3, 1, 12648, 1, 'MST')"
i_tztt="$i_tztt ,(3, 2, 9048, 0, 'MMT') ,(3, 3, 16248, 1, 'MDST')"
i_tztt="$i_tztt ,(3, 4, 10800, 0, 'MSK') ,(3, 5, 14400, 1, 'MSD')"
i_tztt="$i_tztt ,(3, 6, 18000, 1, 'MSD') ,(3, 7, 7200, 0, 'EET')"
i_tztt="$i_tztt ,(3, 8, 10800, 0, 'MSK') ,(3, 9, 14400, 1, 'MSD')"
i_tztt="$i_tztt ,(3, 10, 10800, 1, 'EEST') ,(3, 11, 7200, 0, 'EET')"
i_tztt="$i_tztt ,(4, 0, 9000, 0, 'MMT') ,(4, 1, 12648, 1, 'MST')"
i_tztt="$i_tztt ,(4, 2, 9048, 0, 'MMT') ,(4, 3, 16248, 1, 'MDST')"
i_tztt="$i_tztt ,(4, 4, 10800, 0, 'MSK') ,(4, 5, 14400, 1, 'MSD')"
i_tztt="$i_tztt ,(4, 6, 18000, 1, 'MSD') ,(4, 7, 7200, 0, 'EET')"
i_tztt="$i_tztt ,(4, 8, 10800, 0, 'MSK') ,(4, 9, 14400, 1, 'MSD')"
i_tztt="$i_tztt ,(4, 10, 10800, 1, 'EEST') ,(4, 11, 7200, 0, 'EET');"
fi
fi
if test ! -f $mdata/time_zone_leap_second.frm
then
if test "$1" = "verbose" ; then
echo "Preparing time_zone_leap_second table" 1>&2;
fi
c_tzls="$c_tzls CREATE TABLE time_zone_leap_second ("
c_tzls="$c_tzls Transition_time bigint signed NOT NULL,"
c_tzls="$c_tzls Correction int signed NOT NULL,"
c_tzls="$c_tzls PRIMARY KEY TranTime (Transition_time)"
c_tzls="$c_tzls ) DEFAULT CHARACTER SET latin1"
c_tzls="$c_tzls comment='Leap seconds information for time zones';"
if test "$1" = "test"
then
i_tzls="$i_tzls INSERT INTO time_zone_leap_second "
i_tzls="$i_tzls (Transition_time, Correction) VALUES "
i_tzls="$i_tzls (78796800, 1) ,(94694401, 2) ,(126230402, 3)"
i_tzls="$i_tzls ,(157766403, 4) ,(189302404, 5) ,(220924805, 6)"
i_tzls="$i_tzls ,(252460806, 7) ,(283996807, 8) ,(315532808, 9)"
i_tzls="$i_tzls ,(362793609, 10) ,(394329610, 11) ,(425865611, 12)"
i_tzls="$i_tzls ,(489024012, 13) ,(567993613, 14) ,(631152014, 15)"
i_tzls="$i_tzls ,(662688015, 16) ,(709948816, 17) ,(741484817, 18)"
i_tzls="$i_tzls ,(773020818, 19) ,(820454419, 20) ,(867715220, 21)"
i_tzls="$i_tzls ,(915148821, 22);"
fi
fi
cat << END_OF_DATA
use mysql;
$c_d
@ -306,5 +634,16 @@ $c_ht
$c_hc
$c_hr
$c_hk
$c_tzn
$i_tzn
$c_tz
$i_tz
$c_tzt
$i_tzt
$c_tztt
$i_tztt
$c_tzls
$i_tzls
END_OF_DATA

View file

@ -179,3 +179,42 @@ name varchar(64) not null,
primary key (help_keyword_id),
unique index (name)
) comment='help keywords';
#
# Create missing time zone related tables
#
CREATE TABLE IF NOT EXISTS time_zone_name (
Name char(64) NOT NULL,
Time_zone_id int unsigned NOT NULL,
PRIMARY KEY Name (Name)
) DEFAULT CHARACTER SET latin1 comment='Time zone names';
CREATE TABLE IF NOT EXISTS time_zone (
Time_zone_id int unsigned NOT NULL auto_increment,
Use_leap_seconds enum('Y','N') DEFAULT 'N' NOT NULL,
PRIMARY KEY TzId (Time_zone_id)
) DEFAULT CHARACTER SET latin1 comment='Time zones';
CREATE TABLE IF NOT EXISTS time_zone_transition (
Time_zone_id int unsigned NOT NULL,
Transition_time bigint signed NOT NULL,
Transition_type_id int unsigned NOT NULL,
PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time)
) DEFAULT CHARACTER SET latin1 comment='Time zone transitions';
CREATE TABLE IF NOT EXISTS time_zone_transition_type (
Time_zone_id int unsigned NOT NULL,
Transition_type_id int unsigned NOT NULL,
Offset int signed DEFAULT 0 NOT NULL,
Is_DST tinyint unsigned DEFAULT 0 NOT NULL,
Abbreviation char(8) DEFAULT '' NOT NULL,
PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id)
) DEFAULT CHARACTER SET latin1 comment='Time zone transition types';
CREATE TABLE IF NOT EXISTS time_zone_leap_second (
Transition_time bigint signed NOT NULL,
Correction int signed NOT NULL,
PRIMARY KEY TranTime (Transition_time)
) DEFAULT CHARACTER SET latin1 comment='Leap seconds information for time zones';

View file

@ -26,7 +26,8 @@ INCLUDES = @MT_INCLUDES@ \
WRAPLIBS= @WRAPLIBS@
SUBDIRS = share
libexec_PROGRAMS = mysqld
noinst_PROGRAMS = gen_lex_hash
bin_PROGRAMS = mysql_tzinfo_to_sql
noinst_PROGRAMS = gen_lex_hash test_time
gen_lex_hash_LDFLAGS = @NOINST_LDFLAGS@
LDADD = @isam_libs@ \
../myisam/libmyisam.a \
@ -57,8 +58,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
lex.h lex_symbol.h sql_acl.h sql_crypt.h \
log_event.h sql_repl.h slave.h \
stacktrace.h sql_sort.h sql_cache.h set_var.h \
spatial.h gstream.h client_settings.h \
examples/ha_example.h examples/ha_archive.h
spatial.h gstream.h client_settings.h tzfile.h \
tztime.h examples/ha_example.h examples/ha_archive.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
@ -88,10 +89,18 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
client.c sql_client.cc mini_client_errors.c pack.c\
stacktrace.c repl_failsafe.h repl_failsafe.cc \
gstream.cc spatial.cc sql_help.cc protocol_cursor.cc \
examples/ha_example.cc examples/ha_archive.cc
tztime.cc examples/ha_example.cc examples/ha_archive.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS)
mysql_tzinfo_to_sql_SOURCES = tztime.cc tzfile.h
mysql_tzinfo_to_sql_CPPFLAGS = -DTZINFO2SQL $(AM_CPPFLAGS)
mysql_tzinfo_to_sql_LDADD = $(LDADD) $(CXXLDFLAGS)
test_time_SOURCES = tztime.cc time.cc tzfile.h
test_time_CPPFLAGS = -DTESTTIME $(AM_CPPFLAGS)
test_time_LDADD = $(LDADD) $(CXXLDFLAGS)
DEFS = -DMYSQL_SERVER \
-DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \
-DDATADIR="\"$(MYSQLDATAdir)\"" \

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,10 @@ public:
char *ptr; // Position to field in record
uchar *null_ptr; // Byte where null_bit is
/*
Note that you can use table->in_use as replacement for current_thd member
only inside of val_*() and store() members (e.g. you can't use it in cons)
*/
struct st_table *table; // Pointer for table
struct st_table *orig_table; // Pointer to original table
const char *table_name,*field_name;
@ -264,7 +268,16 @@ public:
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
virtual bool has_charset(void) const { return FALSE; }
virtual void set_charset(CHARSET_INFO *charset) { }
void set_warning(const unsigned int level, const unsigned int code);
bool set_warning(const unsigned int level, const unsigned int code,
int cuted_increment);
void set_datetime_warning(const uint level, const uint code,
const char *str, uint str_len,
timestamp_type ts_type, int cuted_increment);
void set_datetime_warning(const uint level, const uint code,
longlong nr, timestamp_type ts_type,
int cuted_increment);
void set_datetime_warning(const uint level, const uint code,
double nr, timestamp_type ts_type);
virtual field_cast_enum field_cast_type()= 0;
bool field_cast_compatible(field_cast_enum type);
/* maximum possible display length */

View file

@ -121,7 +121,8 @@ set_field_to_null(Field *field)
field->reset();
if (current_thd->count_cuted_fields == CHECK_FIELD_WARN)
{
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_DATA_TRUNCATED);
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED, 1);
return 0;
}
if (!current_thd->no_errors)
@ -178,7 +179,8 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
}
if (current_thd->count_cuted_fields == CHECK_FIELD_WARN)
{
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,ER_WARN_NULL_TO_NOTNULL);
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_NULL_TO_NOTNULL, 1);
return 0;
}
if (!current_thd->no_errors)
@ -229,7 +231,7 @@ static void do_copy_not_null(Copy_field *copy)
if (*copy->from_null_ptr & copy->from_bit)
{
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
ER_WARN_DATA_TRUNCATED, 1);
copy->to_field->reset();
}
else
@ -329,7 +331,7 @@ static void do_cut_string(Copy_field *copy)
if (!my_isspace(system_charset_info, *ptr)) // QQ: ucs incompatible
{
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
ER_WARN_DATA_TRUNCATED, 1);
break;
}
}
@ -350,7 +352,7 @@ static void do_varstring(Copy_field *copy)
length=copy->to_length-2;
if (current_thd->count_cuted_fields)
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_TRUNCATED);
ER_WARN_DATA_TRUNCATED, 1);
}
int2store(copy->to_ptr,length);
memcpy(copy->to_ptr+2, copy->from_ptr,length);

View file

@ -843,8 +843,8 @@ int ha_berkeley::write_row(byte * record)
else
{
DB_TXN *sub_trans = transaction;
/* Don't use sub transactions in temporary tables (in_use == 0) */
ulong thd_options = table->in_use ? table->in_use->options : 0;
/* Don't use sub transactions in temporary tables */
ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
for (uint retry=0 ; retry < berkeley_trans_retry ; retry++)
{
key_map changed_keys(0);
@ -1067,7 +1067,7 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row)
DBT prim_key, key, old_prim_key;
int error;
DB_TXN *sub_trans;
ulong thd_options = table->in_use ? table->in_use->options : 0;
ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
bool primary_key_changed;
DBUG_ENTER("update_row");
LINT_INIT(error);
@ -1260,7 +1260,7 @@ int ha_berkeley::delete_row(const byte * record)
int error;
DBT row, prim_key;
key_map keys=table->keys_in_use;
ulong thd_options = table->in_use ? table->in_use->options : 0;
ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
DBUG_ENTER("delete_row");
statistic_increment(ha_delete_count,&LOCK_status);

View file

@ -228,7 +228,7 @@ bool Item::get_date(TIME *ltime,uint fuzzydate)
char buff[40];
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
if (!(res=val_str(&tmp)) ||
str_to_TIME(res->ptr(),res->length(),ltime,fuzzydate) <=
str_to_TIME_with_warn(res->ptr(),res->length(),ltime,fuzzydate) <=
TIMESTAMP_DATETIME_ERROR)
{
bzero((char*) ltime,sizeof(*ltime));
@ -247,7 +247,7 @@ bool Item::get_time(TIME *ltime)
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
if (!(res=val_str(&tmp)) ||
str_to_time(res->ptr(),res->length(),ltime))
str_to_time_with_warn(res->ptr(), res->length(), ltime))
{
bzero((char*) ltime,sizeof(*ltime));
return 1;

View file

@ -89,6 +89,11 @@ Item *create_func_conv(Item* a, Item *b, Item *c)
return new Item_func_conv(a,b,c);
}
Item *create_func_convert_tz(Item* a, Item *b, Item *c)
{
return new Item_func_convert_tz(a,b,c);
}
Item *create_func_cos(Item* a)
{
return new Item_func_cos(a);

View file

@ -31,6 +31,7 @@ Item *create_func_char_length(Item* a);
Item *create_func_cast(Item *a, Cast_target cast_type, int len, CHARSET_INFO *cs);
Item *create_func_connection_id(void);
Item *create_func_conv(Item* a, Item *b, Item *c);
Item *create_func_convert_tz(Item* a, Item *b, Item *c);
Item *create_func_cos(Item* a);
Item *create_func_cot(Item* a);
Item *create_func_crc32(Item* a);

View file

@ -894,6 +894,9 @@ longlong Item_func_year::val_int()
longlong Item_func_unix_timestamp::val_int()
{
TIME ltime;
bool not_used;
DBUG_ASSERT(fixed == 1);
if (arg_count == 0)
return (longlong) current_thd->query_start();
@ -903,12 +906,19 @@ longlong Item_func_unix_timestamp::val_int()
if (field->type() == FIELD_TYPE_TIMESTAMP)
return ((Field_timestamp*) field)->get_timestamp();
}
String *str=args[0]->val_str(&value);
if ((null_value=args[0]->null_value))
if (get_arg0_date(&ltime, 0))
{
return 0; /* purecov: inspected */
/*
We have to set null_value again because get_arg0_date will also set it
to true if we have wrong datetime parameter (and we should return 0 in
this case).
*/
null_value= args[0]->null_value;
return 0;
}
return (longlong) str_to_timestamp(str->ptr(),str->length());
return (longlong) TIME_to_timestamp(current_thd, &ltime, &not_used);
}
@ -1126,23 +1136,14 @@ bool Item_func_from_days::get_date(TIME *ltime, uint fuzzy_date)
void Item_func_curdate::fix_length_and_dec()
{
struct tm start;
collation.set(&my_charset_bin);
decimals=0;
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
store_now_in_tm(current_thd->query_start(),&start);
store_now_in_TIME(&ltime);
/* For getdate */
ltime.year= start.tm_year+1900;
ltime.month= start.tm_mon+1;
ltime.day= start.tm_mday;
ltime.hour= 0;
ltime.minute= 0;
ltime.second= 0;
ltime.second_part=0;
ltime.neg=0;
/* We don't need to set second_part and neg because they already 0 */
ltime.hour= ltime.minute= ltime.second= 0;
ltime.time_type=TIMESTAMP_DATE;
value= (longlong) TIME_to_ulonglong_date(&ltime);
}
@ -1159,6 +1160,34 @@ String *Item_func_curdate::val_str(String *str)
return str;
}
/*
Converts current time in my_time_t to TIME represenatation for local
time zone. Defines time zone (local) used for whole CURDATE function.
*/
void Item_func_curdate_local::store_now_in_TIME(TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
(my_time_t)thd->query_start());
thd->time_zone_used= 1;
}
/*
Converts current time in my_time_t to TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_DATE function.
*/
void Item_func_curdate_utc::store_now_in_TIME(TIME *now_time)
{
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
/*
We are not flagging this query as using time zone, since it uses fixed
UTC-SYSTEM time-zone.
*/
}
bool Item_func_curdate::get_date(TIME *res,
uint fuzzy_date __attribute__((unused)))
{
@ -1167,26 +1196,6 @@ bool Item_func_curdate::get_date(TIME *res,
}
/*
Converts time in time_t to struct tm represenatation for local timezone.
Defines timezone (local) used for whole CURDATE function
*/
void Item_func_curdate_local::store_now_in_tm(time_t now, struct tm *now_tm)
{
localtime_r(&now,now_tm);
}
/*
Converts time in time_t to struct tm represenatation for UTC
Defines timezone (UTC) used for whole UTC_DATE function
*/
void Item_func_curdate_utc::store_now_in_tm(time_t now, struct tm *now_tm)
{
gmtime_r(&now,now_tm);
}
String *Item_func_curtime::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
@ -1197,17 +1206,12 @@ String *Item_func_curtime::val_str(String *str)
void Item_func_curtime::fix_length_and_dec()
{
struct tm start;
String tmp((char*) buff,sizeof(buff), &my_charset_bin);
TIME ltime;
String tmp((char*) buff,sizeof(buff), &my_charset_bin);
decimals=0;
store_now_in_tm(current_thd->query_start(),&start);
ltime.hour= start.tm_hour;
ltime.minute= start.tm_min;
ltime.second= start.tm_sec;
ltime.second_part= 0;
ltime.neg= 0;
decimals=0;
collation.set(&my_charset_bin);
store_now_in_TIME(&ltime);
value= TIME_to_ulonglong_time(&ltime);
make_time((DATE_TIME_FORMAT *) 0, &ltime, &tmp);
max_length= buff_length= tmp.length();
@ -1215,22 +1219,30 @@ void Item_func_curtime::fix_length_and_dec()
/*
Converts time in time_t to struct tm represenatation for local timezone.
Defines timezone (local) used for whole CURTIME function
Converts current time in my_time_t to TIME represenatation for local
time zone. Defines time zone (local) used for whole CURTIME function.
*/
void Item_func_curtime_local::store_now_in_tm(time_t now, struct tm *now_tm)
void Item_func_curtime_local::store_now_in_TIME(TIME *now_time)
{
localtime_r(&now,now_tm);
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
(my_time_t)thd->query_start());
thd->time_zone_used= 1;
}
/*
Converts time in time_t to struct tm represenatation for UTC.
Defines timezone (UTC) used for whole UTC_TIME function
Converts current time in my_time_t to TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_TIME function.
*/
void Item_func_curtime_utc::store_now_in_tm(time_t now, struct tm *now_tm)
void Item_func_curtime_utc::store_now_in_TIME(TIME *now_time)
{
gmtime_r(&now,now_tm);
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
/*
We are not flagging this query as using time zone, since it uses fixed
UTC-SYSTEM time-zone.
*/
}
@ -1244,18 +1256,12 @@ String *Item_func_now::val_str(String *str)
void Item_func_now::fix_length_and_dec()
{
struct tm start;
String tmp((char*) buff,sizeof(buff),&my_charset_bin);
decimals=0;
collation.set(&my_charset_bin);
store_now_in_tm(current_thd->query_start(),&start);
/* For getdate */
localtime_to_TIME(&ltime, &start);
ltime.time_type= TIMESTAMP_DATETIME;
store_now_in_TIME(&ltime);
value= (longlong) TIME_to_ulonglong_datetime(&ltime);
make_datetime((DATE_TIME_FORMAT *) 0, &ltime, &tmp);
@ -1263,6 +1269,34 @@ void Item_func_now::fix_length_and_dec()
}
/*
Converts current time in my_time_t to TIME represenatation for local
time zone. Defines time zone (local) used for whole NOW function.
*/
void Item_func_now_local::store_now_in_TIME(TIME *now_time)
{
THD *thd= current_thd;
thd->variables.time_zone->gmt_sec_to_TIME(now_time,
(my_time_t)thd->query_start());
thd->time_zone_used= 1;
}
/*
Converts current time in my_time_t to TIME represenatation for UTC
time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
*/
void Item_func_now_utc::store_now_in_TIME(TIME *now_time)
{
my_tz_UTC->gmt_sec_to_TIME(now_time,
(my_time_t)(current_thd->query_start()));
/*
We are not flagging this query as using time zone, since it uses fixed
UTC-SYSTEM time-zone.
*/
}
bool Item_func_now::get_date(TIME *res,
uint fuzzy_date __attribute__((unused)))
{
@ -1279,26 +1313,6 @@ int Item_func_now::save_in_field(Field *to, bool no_conversions)
}
/*
Converts time in time_t to struct tm represenatation for local timezone.
Defines timezone (local) used for whole CURRENT_TIMESTAMP function
*/
void Item_func_now_local::store_now_in_tm(time_t now, struct tm *now_tm)
{
localtime_r(&now,now_tm);
}
/*
Converts time in time_t to struct tm represenatation for UTC.
Defines timezone (UTC) used for whole UTC_TIMESTAMP function
*/
void Item_func_now_utc::store_now_in_tm(time_t now, struct tm *now_tm)
{
gmtime_r(&now,now_tm);
}
String *Item_func_sec_to_time::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
@ -1455,7 +1469,7 @@ String *Item_func_date_format::val_str(String *str)
{
String *res;
if (!(res=args[0]->val_str(str)) ||
(str_to_time(res->ptr(),res->length(),&l_time)))
(str_to_time_with_warn(res->ptr(), res->length(), &l_time)))
goto null_date;
l_time.year=l_time.month=l_time.day=0;
@ -1489,24 +1503,31 @@ null_date:
}
void Item_func_from_unixtime::fix_length_and_dec()
{
thd= current_thd;
collation.set(&my_charset_bin);
decimals=0;
max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
thd->time_zone_used= 1;
}
String *Item_func_from_unixtime::val_str(String *str)
{
struct tm tm_tmp;
time_t tmp;
TIME ltime;
TIME time_tmp;
my_time_t tmp;
DBUG_ASSERT(fixed == 1);
tmp= (time_t) args[0]->val_int();
if ((null_value=args[0]->null_value))
goto null_date;
localtime_r(&tmp,&tm_tmp);
localtime_to_TIME(&ltime, &tm_tmp);
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp);
if (str->alloc(20*MY_CHARSET_BIN_MB_MAXLEN))
goto null_date;
make_datetime((DATE_TIME_FORMAT *) 0, &ltime, str);
make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
return str;
null_date:
@ -1517,28 +1538,109 @@ null_date:
longlong Item_func_from_unixtime::val_int()
{
TIME ltime;
struct tm tm_tmp;
time_t tmp;
TIME time_tmp;
my_time_t tmp;
DBUG_ASSERT(fixed == 1);
tmp= (time_t) (ulong) args[0]->val_int();
if ((null_value=args[0]->null_value))
return 0;
localtime_r(&tmp,&tm_tmp);
localtime_to_TIME(&ltime, &tm_tmp);
return (longlong) TIME_to_ulonglong_datetime(&ltime);
current_thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp);
return (longlong) TIME_to_ulonglong_datetime(&time_tmp);
}
bool Item_func_from_unixtime::get_date(TIME *ltime,
uint fuzzy_date __attribute__((unused)))
{
time_t tmp=(time_t) (ulong) args[0]->val_int();
my_time_t tmp=(my_time_t) args[0]->val_int();
if ((null_value=args[0]->null_value))
return 1;
struct tm tm_tmp;
localtime_r(&tmp,&tm_tmp);
localtime_to_TIME(ltime, &tm_tmp);
current_thd->variables.time_zone->gmt_sec_to_TIME(ltime, tmp);
return 0;
}
void Item_func_convert_tz::fix_length_and_dec()
{
String str;
thd= current_thd;
collation.set(&my_charset_bin);
decimals= 0;
max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
if (args[1]->const_item())
from_tz= my_tz_find(thd, args[1]->val_str(&str));
if (args[2]->const_item())
to_tz= my_tz_find(thd, args[2]->val_str(&str));
}
String *Item_func_convert_tz::val_str(String *str)
{
TIME time_tmp;
if (get_date(&time_tmp, 0))
return 0;
if (str->alloc(20*MY_CHARSET_BIN_MB_MAXLEN))
{
null_value= 1;
return 0;
}
make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
return str;
}
longlong Item_func_convert_tz::val_int()
{
TIME time_tmp;
if (get_date(&time_tmp, 0))
return 0;
return (longlong)TIME_to_ulonglong_datetime(&time_tmp);
}
bool Item_func_convert_tz::get_date(TIME *ltime,
uint fuzzy_date __attribute__((unused)))
{
my_time_t my_time_tmp;
bool not_used;
String str;
if (!args[1]->const_item())
from_tz= my_tz_find(thd, args[1]->val_str(&str));
if (!args[2]->const_item())
to_tz= my_tz_find(thd, args[2]->val_str(&str));
if (from_tz==0 || to_tz==0 || get_arg0_date(ltime, 0))
{
null_value= 1;
return 1;
}
/* Check if we in range where we treat datetime values as non-UTC */
if (ltime->year < TIMESTAMP_MAX_YEAR && ltime->year > TIMESTAMP_MIN_YEAR ||
ltime->year==TIMESTAMP_MAX_YEAR && ltime->month==1 && ltime->day==1 ||
ltime->year==TIMESTAMP_MIN_YEAR && ltime->month==12 && ltime->day==31)
{
my_time_tmp= from_tz->TIME_to_gmt_sec(ltime, &not_used);
if (my_time_tmp >= TIMESTAMP_MIN_VALUE && my_time_tmp <= TIMESTAMP_MAX_VALUE)
to_tz->gmt_sec_to_TIME(ltime, my_time_tmp);
}
null_value= 0;
return 0;
}
@ -1795,7 +1897,7 @@ longlong Item_extract::val_int()
else
{
String *res= args[0]->val_str(&value);
if (!res || str_to_time(res->ptr(),res->length(),&ltime))
if (!res || str_to_time_with_warn(res->ptr(), res->length(), &ltime))
{
null_value=1;
return 0;

View file

@ -348,6 +348,7 @@ 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)
{
@ -356,7 +357,7 @@ public:
};
/* Abstract CURTIME function. Children should define what timezone is used */
/* Abstract CURTIME function. Children should define what time zone is used */
class Item_func_curtime :public Item_func
{
@ -378,10 +379,10 @@ public:
}
/*
Abstract method that defines which time zone is used for conversion.
Converts time from time_t representation to broken down representation
in struct tm using gmtime_r or localtime_r functions.
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_tm(time_t now, struct tm *now_tm)=0;
virtual void store_now_in_TIME(TIME *now_time)=0;
};
@ -391,7 +392,7 @@ 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"; }
void store_now_in_tm(time_t now, struct tm *now_tm);
virtual void store_now_in_TIME(TIME *now_time);
};
@ -401,7 +402,7 @@ 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"; }
void store_now_in_tm(time_t now, struct tm *now_tm);
virtual void store_now_in_TIME(TIME *now_time);
};
@ -413,12 +414,11 @@ class Item_func_curdate :public Item_date
TIME ltime;
public:
Item_func_curdate() :Item_date() {}
void set_result_from_tm(struct tm *now);
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_tm(time_t now, struct tm *now_tm)=0;
virtual void store_now_in_TIME(TIME *now_time)=0;
};
@ -427,7 +427,7 @@ 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_tm(time_t now, struct tm *now_tm);
void store_now_in_TIME(TIME *now_time);
};
@ -436,7 +436,7 @@ 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_tm(time_t now, struct tm *now_tm);
void store_now_in_TIME(TIME *now_time);
};
@ -458,7 +458,7 @@ public:
String *val_str(String *str);
void fix_length_and_dec();
bool get_date(TIME *res, uint fuzzy_date);
virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0;
virtual void store_now_in_TIME(TIME *now_time)=0;
};
@ -468,7 +468,7 @@ 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"; }
void store_now_in_tm(time_t now, struct tm *now_tm);
virtual void store_now_in_TIME(TIME *now_time);
virtual enum Functype functype() const { return NOW_FUNC; }
};
@ -479,7 +479,7 @@ 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"; }
void store_now_in_tm(time_t now, struct tm *now_tm);
virtual void store_now_in_TIME(TIME *now_time);
};
@ -509,6 +509,7 @@ public:
class Item_func_from_unixtime :public Item_date_func
{
THD *thd;
public:
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
double val()
@ -519,12 +520,29 @@ class Item_func_from_unixtime :public Item_date_func
longlong val_int();
String *val_str(String *str);
const char *func_name() const { return "from_unixtime"; }
void fix_length_and_dec()
{
collation.set(&my_charset_bin);
decimals=0;
max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
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);
};

View file

@ -499,6 +499,7 @@ static SYMBOL sql_functions[] = {
{ "CONNECTION_ID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)},
{ "CONTAINS", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_contains)},
{ "CONV", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)},
{ "CONVERT_TZ", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_convert_tz)},
{ "COUNT", SYM(COUNT_SYM)},
{ "COS", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
{ "COT", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},

View file

@ -1269,10 +1269,24 @@ COLLATION_CONNECTION=%lu,COLLATION_DATABASE=%lu,COLLATION_SERVER=%lu",
if (e.write(file))
goto err;
}
/*
We use the same ONE_SHOT trick for making replication of time zones
working in 4.1. Again in 5.0 we have better means for doing this.
*/
if (thd->time_zone_used &&
thd->variables.time_zone != global_system_variables.time_zone)
{
char buf[MAX_TIME_ZONE_NAME_LENGTH + 26];
char *buf_end= strxmov(buf, "SET ONE_SHOT TIME_ZONE='",
thd->variables.time_zone->get_name()->ptr(),
"'", NullS);
Query_log_event e(thd, buf, buf_end - buf, 0);
e.set_log_pos(this);
if (e.write(file))
goto err;
}
#endif
/* Add logging of timezones here */
if (thd->last_insert_id_used)
{
Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,

View file

@ -39,6 +39,14 @@ extern const key_map key_map_empty;
extern const key_map key_map_full;
extern const char *primary_key_name;
/*
Portable time_t replacement.
Should be signed and hold seconds for 1902-2038 range.
*/
typedef long my_time_t;
#define MY_TIME_T_MAX LONG_MAX
#define MY_TIME_T_MIN LONG_MIN
#include "mysql_com.h"
#include <violite.h>
#include "unireg.h"
@ -349,6 +357,7 @@ inline THD *_current_thd(void)
#include "sql_udf.h"
class user_var_entry;
#include "item.h"
#include "tztime.h"
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
/* sql_parse.cc */
void free_items(Item *item);
@ -378,6 +387,7 @@ struct Query_cache_query_flags
uint character_set_results_num;
uint collation_connection_num;
ha_rows limit;
Time_zone *time_zone;
};
#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
#include "sql_cache.h"
@ -822,7 +832,7 @@ extern Le_creator le_creator;
extern uchar *days_in_month;
extern char language[LIBLEN],reg_ext[FN_EXTLEN];
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file;
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
extern char log_error_file[FN_REFLEN];
extern double log_10[32];
extern ulonglong log_10_int[20];
@ -878,6 +888,7 @@ extern my_bool opt_enable_named_pipe, opt_sync_frm;
extern my_bool opt_secure_auth;
extern char *shared_memory_base_name, *mysqld_unix_port;
extern bool opt_enable_shared_memory;
extern char *default_tz_name;
extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
extern FILE *bootstrap_file;
@ -988,12 +999,16 @@ uint calc_days_in_year(uint year);
void get_date_from_daynr(long daynr,uint *year, uint *month,
uint *day);
void init_time(void);
long my_gmt_sec(TIME *, long *current_timezone);
time_t str_to_timestamp(const char *str,uint length);
bool str_to_time(const char *str,uint length,TIME *l_time);
longlong str_to_datetime(const char *str,uint length, uint fuzzy_date);
my_time_t my_system_gmt_sec(const TIME *, long *current_timezone, bool *not_exist);
my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *not_exist);
bool str_to_time(const char *str,uint length,TIME *l_time, int *was_cut);
bool str_to_time_with_warn(const char *str,uint length,TIME *l_time);
timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time,
uint flags);
uint flags, int *was_cut);
timestamp_type str_to_TIME_with_warn(const char *str, uint length,
TIME *l_time, uint flags);
longlong number_to_TIME(longlong nr, TIME *time_res, bool fuzzy_date,
int *was_cut);
void localtime_to_TIME(TIME *to, struct tm *from);
void calc_time_from_sec(TIME *to, long seconds, long microseconds);

View file

@ -324,7 +324,8 @@ ulonglong log_10_int[20]=
time_t start_time;
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], time_zone[30];
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
char *default_tz_name;
char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
char* log_error_file_ptr= log_error_file;
char mysql_real_data_home[FN_REFLEN],
@ -911,6 +912,7 @@ void clean_up(bool print_message)
if (use_slave_mask)
bitmap_free(&slave_error_mask);
#endif
my_tz_free();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
acl_free(1);
grant_free();
@ -2270,9 +2272,17 @@ static int init_common_variables(const char *conf_file_name, int argc,
{
struct tm tm_tmp;
localtime_r(&start_time,&tm_tmp);
strmov(time_zone,tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]);
strmov(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]);
}
#endif
/*
We set SYSTEM time zone as reasonable default and
also for failure of my_tz_init() and bootstrap mode.
If user explicitly set time zone with --default-time-zone
option we will change this value in my_tz_init().
*/
global_system_variables.time_zone= my_tz_SYSTEM;
/*
Init mutexes for the global MYSQL_LOG objects.
@ -2810,7 +2820,8 @@ we force server id to 2, but this MySQL server will not act as a slave.");
*/
error_handler_hook = my_message_sql;
start_signal_handler(); // Creates pidfile
if (acl_init((THD *)0, opt_noacl))
if (acl_init((THD *)0, opt_noacl) ||
my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
{
abort_loop=1;
select_thread_in_use=0;
@ -3897,7 +3908,8 @@ enum options_mysqld
OPT_DATE_FORMAT,
OPT_TIME_FORMAT,
OPT_DATETIME_FORMAT,
OPT_LOG_QUERIES_NOT_USING_INDEXES
OPT_LOG_QUERIES_NOT_USING_INDEXES,
OPT_DEFAULT_TIME_ZONE
};
@ -4010,6 +4022,9 @@ Disable with --skip-bdb (will save memory).",
{"default-table-type", OPT_STORAGE_ENGINE,
"(deprecated) Use default-storage-engine.", 0, 0,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default-time-zone", OPT_DEFAULT_TIME_ZONE, "Set the default time zone.",
(gptr*) &default_tz_name, (gptr*) &default_tz_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{"delay-key-write", OPT_DELAY_KEY_WRITE, "Type of DELAY_KEY_WRITE.",
0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"delay-key-write-for-all-tables", OPT_DELAY_KEY_WRITE_ALL,

View file

@ -441,6 +441,7 @@ static sys_var_thd_ulong sys_default_week_format("default_week_format",
sys_var_thd_ulong sys_group_concat_max_len("group_concat_max_len",
&SV::group_concat_max_len);
sys_var_thd_time_zone sys_time_zone("time_zone");
/* Read only variables */
@ -586,6 +587,7 @@ sys_var *sys_variables[]=
&sys_thread_cache_size,
&sys_time_format,
&sys_timestamp,
&sys_time_zone,
&sys_tmp_table_size,
&sys_trans_alloc_block_size,
&sys_trans_prealloc_size,
@ -809,8 +811,9 @@ struct show_var_st init_vars[]= {
{"thread_stack", (char*) &thread_stack, SHOW_LONG},
{sys_time_format.name, (char*) &sys_time_format, SHOW_SYS},
#ifdef HAVE_TZNAME
{"timezone", time_zone, SHOW_CHAR},
{"system_time_zone", system_time_zone, SHOW_CHAR},
#endif
{"time_zone", (char*) &sys_time_zone, SHOW_SYS},
{sys_tmp_table_size.name, (char*) &sys_tmp_table_size, SHOW_SYS},
{"tmpdir", (char*) &opt_mysql_tmpdir, SHOW_CHAR_PTR},
{sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size,
@ -2352,6 +2355,77 @@ bool sys_var_rand_seed2::update(THD *thd, set_var *var)
}
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
{
char buff[MAX_TIME_ZONE_NAME_LENGTH];
String str(buff, sizeof(buff), &my_charset_latin1);
String *res= var->value->val_str(&str);
#if defined(HAVE_REPLICATION) && (MYSQL_VERSION_ID < 50000)
if ((var->type == OPT_GLOBAL) &&
(mysql_bin_log.is_open() ||
active_mi->slave_running || active_mi->rli.slave_running))
{
my_printf_error(0, "Binary logging and replication forbid changing "
"of the global server time zone", MYF(0));
return 1;
}
#endif
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
{
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
return 1;
}
return 0;
}
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
{
/* We are using Time_zone object found during check() phase */
*get_tz_ptr(thd,var->type)= var->save_result.time_zone;
return 0;
}
byte *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
LEX_STRING *base)
{
/*
We can use ptr() instead of c_ptr() here because String contaning
time zone name is guaranteed to be zero ended.
*/
return (byte *)((*get_tz_ptr(thd,type))->get_name()->ptr());
}
Time_zone** sys_var_thd_time_zone::get_tz_ptr(THD *thd,
enum_var_type type)
{
if (type == OPT_GLOBAL)
return &global_system_variables.time_zone;
else
return &thd->variables.time_zone;
}
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
{
if (default_tz_name)
{
String str(default_tz_name, &my_charset_latin1);
global_system_variables.time_zone= my_tz_find(thd, &str);
}
else
global_system_variables.time_zone= my_tz_SYSTEM;
}
else
thd->variables.time_zone= global_system_variables.time_zone;
}
/*
Functions to update thd->options bits
*/

View file

@ -716,6 +716,29 @@ public:
SHOW_TYPE type() { return show_type; }
};
class sys_var_thd_time_zone :public sys_var_thd
{
public:
sys_var_thd_time_zone(const char *name_arg):
sys_var_thd(name_arg)
{
#if MYSQL_VERSION_ID < 50000
no_support_one_shot= 0;
#endif
}
bool check(THD *thd, set_var *var);
SHOW_TYPE type() { return SHOW_CHAR; }
bool check_update_type(Item_result type)
{
return type != STRING_RESULT; /* Only accept strings */
}
bool check_default(enum_var_type type) { return 0; }
bool update(THD *thd, set_var *var);
byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
virtual void set_default(THD *thd, enum_var_type type);
Time_zone **get_tz_ptr(THD *thd, enum_var_type type);
};
/****************************************************************************
Classes for parsing of the SET command
****************************************************************************/
@ -749,6 +772,7 @@ public:
ulong ulong_value;
ulonglong ulonglong_value;
DATE_TIME_FORMAT *date_time_format;
Time_zone *time_zone;
} save_result;
LEX_STRING base; /* for structs */

View file

@ -310,3 +310,5 @@ character-set=latin2
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -304,3 +304,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Modtog fejl %d '%-.100s' fra %s",
"Modtog temporary fejl %d '%-.100s' fra %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -312,3 +312,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -306,3 +306,5 @@ character-set=latin7
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -313,3 +313,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=greek
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=latin2
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=ujis
"This command is not supported in the prepared statement protocol yet",
"Got NDB error %d '%-.100s'",
"Got temporary NDB error %d '%-.100s'",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=euckr
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Mottok feil %d '%-.100s' fra %s",
"Mottok temporary feil %d '%-.100s' fra %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Mottok feil %d '%-.100s' fa %s",
"Mottok temporary feil %d '%-.100s' fra %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -305,3 +305,5 @@ character-set=latin2
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -302,3 +302,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -305,3 +305,5 @@ character-set=latin2
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=koi8r
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -307,3 +307,5 @@ character-set=cp1250
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -309,3 +309,5 @@ character-set=latin2
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -303,3 +303,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -301,3 +301,5 @@ character-set=latin1
"This command is not supported in the prepared statement protocol yet",
"Fick felkod %d '%-.100s' från %s",
"Fick tilfällig felkod %d '%-.100s' från %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -306,3 +306,5 @@ character-set=koi8u
"This command is not supported in the prepared statement protocol yet",
"Got error %d '%-.100s' from %s",
"Got temporary error %d '%-.100s' from %s",
"Unknown or incorrect time zone: '%-.64s'",
"Invalid TIMESTAMP value in column '%s' at row %ld",

View file

@ -1248,7 +1248,30 @@ be equal for replication to work";
mysql_free_result(master_res);
}
/* Add a timezones check here */
/*
Perform analogous check for time zone. Theoretically we also should
perform check here to verify that SYSTEM time zones are the same on
slave and master, but we can't rely on value of @@system_time_zone
variable (it is time zone abbreviation) since it determined at start
time and so could differ for slave and master even if they are really
in the same system time zone. So we are omiting this check and just
relying on documentation. Also according to Monty there are many users
who are using replication between servers in various time zones. Hence
such check will broke everything for them. (And now everything will
work for them because by default both their master and slave will have
'SYSTEM' time zone).
*/
if (!mysql_real_query(mysql, "SELECT @@GLOBAL.TIME_ZONE", 25) &&
(master_res= mysql_store_result(mysql)))
{
if ((master_row= mysql_fetch_row(master_res)) &&
strcmp(master_row[0],
global_system_variables.time_zone->get_name()->ptr()))
errmsg= "The slave I/O thread stops because master and slave have \
different values for the TIME_ZONE global variable. The values must \
be equal for replication to work";
mysql_free_result(master_res);
}
if (errmsg)
{

View file

@ -1760,6 +1760,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
}
tmp_table->reginfo.lock_type=TL_WRITE; // Simulate locked
tmp_table->in_use= thd;
tmp_table->tmp_table = (tmp_table->file->has_transactions() ?
TRANSACTIONAL_TMP_TABLE : TMP_TABLE);
tmp_table->table_cache_key=(char*) (tmp_table+1);

View file

@ -786,6 +786,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
flags.collation_connection_num=
thd->variables.collation_connection->number;
flags.limit= thd->variables.select_limit;
flags.time_zone= thd->variables.time_zone;
STRUCT_LOCK(&structure_guard_mutex);
if (query_cache_size == 0)
@ -972,6 +973,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
UINT_MAX);
flags.collation_connection_num= thd->variables.collation_connection->number;
flags.limit= thd->variables.select_limit;
flags.time_zone= thd->variables.time_zone;
memcpy((void *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
&flags, QUERY_CACHE_FLAGS_SIZE);
query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql,
@ -3231,9 +3233,10 @@ void Query_cache::queries_dump()
Query_cache_query_flags flags;
memcpy(&flags, str+len, QUERY_CACHE_FLAGS_SIZE);
str[len]= 0; // make zero ending DB name
DBUG_PRINT("qcache", ("F:%u C:%u L:%lu (%u) '%s' '%s'",
DBUG_PRINT("qcache", ("F:%u C:%u L:%lu T:'%s' (%u) '%s' '%s'",
flags.client_long_flag,
flags.character_set_client_num, (ulong)flags.limit,
flags.character_set_client_num,
(ulong)flags.limit, flags.time_zone->get_name(),
len, str, strend(str)+1));
DBUG_PRINT("qcache", ("-b- 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx", (ulong) block,
(ulong) block->next, (ulong) block->prev,

View file

@ -157,8 +157,8 @@ bool foreign_key_prefix(Key *a, Key *b)
THD::THD():user_time(0), current_statement(0), is_fatal_error(0),
last_insert_id_used(0),
insert_id_used(0), rand_used(0), in_lock_tables(0),
global_read_lock(0), bootstrap(0)
insert_id_used(0), rand_used(0), time_zone_used(0),
in_lock_tables(0), global_read_lock(0), bootstrap(0)
{
host= user= priv_user= db= ip=0;
host_or_ip= "connecting host";

View file

@ -405,6 +405,8 @@ struct system_variables
CHARSET_INFO *collation_database;
CHARSET_INFO *collation_connection;
Time_zone *time_zone;
/* DATE, DATETIME and TIME formats */
DATE_TIME_FORMAT *date_format;
DATE_TIME_FORMAT *datetime_format;
@ -826,6 +828,7 @@ public:
bool last_cuted_field;
bool no_errors, password, is_fatal_error;
bool query_start_used,last_insert_id_used,insert_id_used,rand_used;
bool time_zone_used;
bool in_lock_tables,global_read_lock;
bool query_error, bootstrap, cleanup_done;
bool tmp_table_used;

View file

@ -945,6 +945,10 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
/* _rowid is not used with delayed insert */
copy->rowid_field=0;
/* Adjust in_use for pointing to client thread */
copy->in_use= client_thd;
return copy;
/* Got fatal error */

View file

@ -530,7 +530,7 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
((Field_timestamp*) field)->set_time();
else if (field != table->next_number_field)
field->set_warning((uint) MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_NULL_TO_NOTNULL);
ER_WARN_NULL_TO_NOTNULL, 1);
}
continue;
}

View file

@ -3489,7 +3489,8 @@ purposes internal to the MySQL server", MYF(0));
thd->variables.collation_server=
global_system_variables.collation_server;
thd->update_charset();
/* Add timezone stuff here */
thd->variables.time_zone=
global_system_variables.time_zone;
thd->one_shot_set= 0;
}
}
@ -3847,7 +3848,7 @@ mysql_init_query(THD *thd)
thd->total_warn_count=0; // Warnings for this query
thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0;
thd->sent_row_count= thd->examined_row_count= 0;
thd->is_fatal_error= thd->rand_used= 0;
thd->is_fatal_error= thd->rand_used= thd->time_zone_used= 0;
thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
SERVER_QUERY_NO_INDEX_USED |
SERVER_QUERY_NO_GOOD_INDEX_USED);

View file

@ -4975,6 +4975,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
table->db_low_byte_first=1; // True for HEAP and MyISAM
table->temp_pool_slot = temp_pool_slot;
table->copy_blobs= 1;
table->in_use= thd;
table->keys_for_keyread.init();
table->keys_in_use.init();
table->read_only_keys.init();

View file

@ -529,7 +529,6 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
}
else
{
struct tm tm_tmp;
const char *str;
handler *file=table->file;
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
@ -562,24 +561,21 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
protocol->store_null();
else
{
localtime_r(&file->create_time,&tm_tmp);
localtime_to_TIME(&time, &tm_tmp);
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->create_time);
protocol->store(&time);
}
if (!file->update_time)
protocol->store_null();
else
{
localtime_r(&file->update_time,&tm_tmp);
localtime_to_TIME(&time, &tm_tmp);
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->update_time);
protocol->store(&time);
}
if (!file->check_time)
protocol->store_null();
else
{
localtime_r(&file->check_time,&tm_tmp);
localtime_to_TIME(&time, &tm_tmp);
thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time);
protocol->store(&time);
}
str= (table->table_charset ? table->table_charset->name : "default");

View file

@ -23,16 +23,26 @@
static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */
uchar *days_in_month= (uchar*) "\037\034\037\036\037\036\037\037\036\037\036\037";
/* Init some variabels needed when using my_local_time */
/* Currently only my_time_zone is inited */
/*
Offset of system time zone from UTC in seconds used to speed up
work of my_system_gmt_sec() function.
*/
static long my_time_zone=0;
/*
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
SYNOPSIS
init_time()
*/
void init_time(void)
{
time_t seconds;
struct tm *l_time,tm_tmp;;
TIME my_time;
bool not_used;
seconds= (time_t) time((time_t*) 0);
localtime_r(&seconds,&tm_tmp);
@ -44,33 +54,40 @@ void init_time(void)
my_time.hour= (uint) l_time->tm_hour;
my_time.minute= (uint) l_time->tm_min;
my_time.second= (uint) l_time->tm_sec;
my_gmt_sec(&my_time, &my_time_zone); /* Init my_time_zone */
my_system_gmt_sec(&my_time, &my_time_zone, &not_used); /* Init my_time_zone */
}
/*
Convert current time to sec. since 1970.01.01
This code handles also day light saving time.
The idea is to cache the time zone (including daylight saving time)
for the next call to make things faster.
Convert time in TIME representation in system time zone to its
my_time_t form (number of seconds in UTC since begginning of Unix Epoch).
SYNOPSIS
my_system_gmt_sec()
t - time value to be converted
my_timezone - pointer to long where offset of system time zone
from UTC will be stored for caching
in_dst_time_gap - set to true if time falls into spring time-gap
NOTES
The idea is to cache the time zone offset from UTC (including daylight
saving time) for the next call to make things faster. But currently we
just calculate this offset during startup (by calling init_time()
function) and use it all the time.
Time value provided should be legal time value (e.g. '2003-01-01 25:00:00'
is not allowed).
RETURN VALUE
Time in UTC seconds since Unix Epoch representation.
*/
long my_gmt_sec(TIME *t, long *my_timezone)
my_time_t
my_system_gmt_sec(const TIME *t, long *my_timezone, bool *in_dst_time_gap)
{
uint loop;
time_t tmp;
struct tm *l_time,tm_tmp;
long diff, current_timezone;
if (t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR)
return 0;
if (t->hour >= 24)
{ /* Fix for time-loop */
t->day+=t->hour/24;
t->hour%=24;
}
/*
Calculate the gmt time based on current time and timezone
The -1 on the end is to ensure that if have a date that exists twice
@ -125,14 +142,13 @@ long my_gmt_sec(TIME *t, long *my_timezone)
tmp+=3600 - t->minute*60 - t->second; // Move to next hour
else if (diff == -3600)
tmp-=t->minute*60 + t->second; // Move to previous hour
*in_dst_time_gap= 1;
}
*my_timezone= current_timezone;
if (tmp < TIMESTAMP_MIN_VALUE || tmp > TIMESTAMP_MAX_VALUE)
tmp= 0;
return (long) tmp;
} /* my_gmt_sec */
return (my_time_t) tmp;
} /* my_system_gmt_sec */
/* Some functions to calculate dates */
@ -164,6 +180,7 @@ long calc_daynr(uint year,uint month,uint day)
} /* calc_daynr */
#ifndef TESTTIME
/* Calc weekday from daynr */
/* Returns 0 for monday, 1 for tuesday .... */
@ -346,6 +363,8 @@ static char time_separator=':';
flags Bitmap of following items
TIME_FUZZY_DATE Set if we should allow partial dates
TIME_DATETIME_ONLY Set if we only allow full datetimes.
was_cut Set to 1 if value was cut during conversion or to 0
otherwise.
DESCRIPTION
At least the following formats are recogniced (based on number of digits)
@ -383,7 +402,8 @@ static char time_separator=':';
#define MAX_DATE_PARTS 8
timestamp_type
str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
str_to_TIME(const char *str, uint length, TIME *l_time, uint flags,
int *was_cut)
{
uint field_length, year_length, digits, i, number_of_fields;
uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS];
@ -403,11 +423,16 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
LINT_INIT(year_length);
LINT_INIT(last_field_pos);
*was_cut= 0;
// Skip space at start
for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++)
;
if (str == end || ! my_isdigit(&my_charset_latin1, *str))
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE);
}
is_internal_format= 0;
/* This has to be changed if want to activate different timestamp formats */
@ -449,7 +474,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
if (pos == end)
{
if (flags & TIME_DATETIME_ONLY)
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE); // Can't be a full datetime
}
/* Date field. Set hour, minutes and seconds to 0 */
date[0]= date[1]= date[2]= date[3]= date[4]= 0;
start_loop= 5; // Start with first date part
@ -486,7 +514,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
}
date_len[i]= (uint) (str - start);
if (tmp_value > 999999) // Impossible date part
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE);
}
date[i]=tmp_value;
not_zero_date|= tmp_value;
@ -523,7 +554,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
if (my_isspace(&my_charset_latin1,*str))
{
if (!(allow_space & (1 << i)))
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE);
}
found_space= 1;
}
str++;
@ -551,7 +585,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
last_field_pos= str;
}
if (found_delimitier && !found_space && (flags & TIME_DATETIME_ONLY))
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE); // Can't be a datetime
}
str= last_field_pos;
@ -566,7 +603,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
{
year_length= date_len[(uint) format_position[0]];
if (!year_length) // Year must be specified
{
*was_cut= 1;
DBUG_RETURN(TIMESTAMP_NONE);
}
l_time->year= date[(uint) format_position[0]];
l_time->month= date[(uint) format_position[1]];
@ -584,7 +624,10 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
if (format_position[7] != (uchar) 255)
{
if (l_time->hour > 12)
{
*was_cut= 1;
goto err;
}
l_time->hour= l_time->hour%12 + add_hours;
}
}
@ -624,7 +667,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
}
}
if (not_zero_date)
current_thd->cuted_fields++;
*was_cut= 1;
goto err;
}
@ -635,8 +678,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
{
if (!my_isspace(&my_charset_latin1,*str))
{
make_truncated_value_warning(current_thd, str_begin, length,
l_time->time_type);
*was_cut= 1;
break;
}
}
@ -650,43 +692,59 @@ err:
}
time_t str_to_timestamp(const char *str,uint length)
{
TIME l_time;
long not_used;
time_t timestamp= 0;
/*
Convert a timestamp string to a TIME value and produce a warning
if string was truncated during conversion.
if (str_to_TIME(str,length,&l_time,0) > TIMESTAMP_DATETIME_ERROR &&
!(timestamp= my_gmt_sec(&l_time, &not_used)))
current_thd->cuted_fields++;
return timestamp;
NOTE
See description of str_to_TIME() for more information.
*/
timestamp_type
str_to_TIME_with_warn(const char *str, uint length, TIME *l_time, uint flags)
{
int was_cut;
timestamp_type ts_type= str_to_TIME(str, length, l_time, flags, &was_cut);
if (was_cut)
make_truncated_value_warning(current_thd, str, length, ts_type);
return ts_type;
}
/*
Convert a string to datetime.
Convert a datetime from broken-down TIME representation to corresponding
TIMESTAMP value.
SYNOPSIS
str_to_datetime()
str String to parse (see str_to_TIME() synopsis)
length Length of str
fuzzy_date Flags (see str_to_TIME() synopsis)
TIME_to_timestamp()
thd - current thread
t - datetime in broken-down representation,
in_dst_time_gap - pointer to bool which is set to true if t represents
value which doesn't exists (falls into the spring
time-gap) or to false otherwise.
RETURN
-1 if error
datetime value otherwise
Number seconds in UTC since start of Unix Epoch corresponding to t.
0 - t contains datetime value which is out of TIMESTAMP range.
*/
longlong str_to_datetime(const char *str,uint length, uint fuzzy_date)
my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *in_dst_time_gap)
{
TIME l_time;
if (str_to_TIME(str,length,&l_time,fuzzy_date) <= TIMESTAMP_DATETIME_ERROR)
return -1;
return (longlong) (l_time.year*LL(10000000000) +
l_time.month*LL(100000000)+
l_time.day*LL(1000000)+
l_time.hour*LL(10000)+
(longlong) (l_time.minute*100+l_time.second));
my_time_t timestamp;
*in_dst_time_gap= 0;
if (t->year < TIMESTAMP_MAX_YEAR && t->year > TIMESTAMP_MIN_YEAR ||
t->year == TIMESTAMP_MAX_YEAR && t->month == 1 && t->day == 1 ||
t->year == TIMESTAMP_MIN_YEAR && t->month == 12 && t->day == 31)
{
thd->time_zone_used= 1;
timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
if (timestamp >= TIMESTAMP_MIN_VALUE && timestamp <= TIMESTAMP_MAX_VALUE)
return timestamp;
}
/* If we are here we have range error. */
return(0);
}
@ -701,6 +759,8 @@ longlong str_to_datetime(const char *str,uint length, uint fuzzy_date)
There may be an optional [.second_part] after seconds
length Length of str
l_time Store result here
was_cut Set to 1 if value was cut during conversion or to 0
otherwise.
NOTES
Because of the extra days argument, this function can only
@ -711,7 +771,7 @@ longlong str_to_datetime(const char *str,uint length, uint fuzzy_date)
1 error
*/
bool str_to_time(const char *str,uint length,TIME *l_time)
bool str_to_time(const char *str, uint length, TIME *l_time, int *was_cut)
{
long date[5],value;
const char *end=str+length, *end_of_days;
@ -720,6 +780,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
uint state;
l_time->neg=0;
*was_cut= 0;
for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++)
length--;
if (str != end && *str == '-')
@ -736,9 +797,12 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
{ // Probably full timestamp
enum timestamp_type res= str_to_TIME(str,length,l_time,
(TIME_FUZZY_DATE |
TIME_DATETIME_ONLY));
TIME_DATETIME_ONLY),
was_cut);
if ((int) res >= (int) TIMESTAMP_DATETIME_ERROR)
return res == TIMESTAMP_DATETIME_ERROR;
/* We need to restore was_cut flag since str_to_TIME can modify it */
*was_cut= 0;
}
/* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */
@ -841,7 +905,7 @@ fractional:
/* Some simple checks */
if (date[2] >= 60 || date[3] >= 60)
{
current_thd->cuted_fields++;
*was_cut= 1;
return 1;
}
l_time->year= 0; // For protocol::store_time
@ -860,8 +924,7 @@ fractional:
{
if (!my_isspace(&my_charset_latin1,*str))
{
make_truncated_value_warning(current_thd, str_begin, length,
TIMESTAMP_TIME);
*was_cut= 1;
break;
}
} while (++str != end);
@ -870,6 +933,113 @@ fractional:
}
/*
Convert a time string to a TIME struct and produce a warning
if string was cut during conversion.
NOTE
See str_to_time() for more info.
*/
bool
str_to_time_with_warn(const char *str, uint length, TIME *l_time)
{
int was_cut;
bool ret_val= str_to_time(str, length, l_time, &was_cut);
if (was_cut)
make_truncated_value_warning(current_thd, str, length, TIMESTAMP_TIME);
return ret_val;
}
/*
Convert datetime value specified as number to broken-down TIME
representation and form value of DATETIME type as side-effect.
SYNOPSIS
number_to_TIME()
nr - datetime value as number
time_res - pointer for structure for broken-down representation
fuzzy_date - indicates whenever we allow fuzzy dates
was_cut - set ot 1 if there was some kind of error during
conversion or to 0 if everything was OK.
DESCRIPTION
Convert a datetime value of formats YYMMDD, YYYYMMDD, YYMMDDHHMSS,
YYYYMMDDHHMMSS to broken-down TIME representation. Return value in
YYYYMMDDHHMMSS format as side-effect.
This function also checks if datetime value fits in DATETIME range.
RETURN VALUE
Datetime value in YYYYMMDDHHMMSS format.
If input value is not valid datetime value then 0 is returned.
*/
longlong number_to_TIME(longlong nr, TIME *time_res, bool fuzzy_date,
int *was_cut)
{
long part1,part2;
*was_cut= 0;
if (nr == LL(0) || nr >= LL(10000101000000))
goto ok;
if (nr < 101)
goto err;
if (nr <= (YY_PART_YEAR-1)*10000L+1231L)
{
nr= (nr+20000000L)*1000000L; // YYMMDD, year: 2000-2069
goto ok;
}
if (nr < (YY_PART_YEAR)*10000L+101L)
goto err;
if (nr <= 991231L)
{
nr= (nr+19000000L)*1000000L; // YYMMDD, year: 1970-1999
goto ok;
}
if (nr < 10000101L)
goto err;
if (nr <= 99991231L)
{
nr= nr*1000000L;
goto ok;
}
if (nr < 101000000L)
goto err;
if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959))
{
nr= nr+LL(20000000000000); // YYMMDDHHMMSS, 2000-2069
goto ok;
}
if (nr < YY_PART_YEAR*LL(10000000000)+ LL(101000000))
goto err;
if (nr <= LL(991231235959))
nr= nr+LL(19000000000000); // YYMMDDHHMMSS, 1970-1999
ok:
part1=(long) (nr/LL(1000000));
part2=(long) (nr - (longlong) part1*LL(1000000));
time_res->year= (int) (part1/10000L); part1%=10000L;
time_res->month= (int) part1 / 100;
time_res->day= (int) part1 % 100;
time_res->hour= (int) (part2/10000L); part2%=10000L;
time_res->minute=(int) part2 / 100;
time_res->second=(int) part2 % 100;
if (time_res->year <= 9999 && time_res->month <= 12 &&
time_res->day <= 31 && time_res->hour <= 23 &&
time_res->minute <= 59 && time_res->second <= 59 &&
(fuzzy_date || (time_res->month != 0 && time_res->day != 0) || nr==0))
return nr;
err:
*was_cut= 1;
return LL(0);
}
/*
Convert a system time structure to TIME
*/
@ -1307,6 +1477,7 @@ void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)),
str->set_charset(&my_charset_bin);
}
void make_truncated_value_warning(THD *thd, const char *str_val,
uint str_length, timestamp_type time_type)
{
@ -1323,19 +1494,17 @@ void make_truncated_value_warning(THD *thd, const char *str_val,
case TIMESTAMP_DATE:
type_str= "date";
break;
case TIMESTAMP_DATETIME:
type_str= "datetime";
break;
case TIMESTAMP_TIME:
type_str= "time";
break;
case TIMESTAMP_DATETIME: // FALLTHROUGH
default:
type_str= "string";
type_str= "datetime";
break;
}
sprintf(warn_buff, ER(ER_TRUNCATED_WRONG_VALUE),
type_str, str.ptr());
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE, warn_buff);
}
@ -1446,3 +1615,5 @@ void TIME_to_string(const TIME *time, String *str)
DBUG_ASSERT(0);
}
}
#endif

137
sql/tzfile.h Normal file
View file

@ -0,0 +1,137 @@
/* Copyright (C) 2004 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
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 */
/*
This file is based on public domain code from ftp://elsie.ncih.nist.gov/
Initial source code is in the public domain, so clarified as of
1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
*/
/*
Information about time zone files.
*/
#ifndef TZDIR
#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */
#endif /* !defined TZDIR */
/*
Each file begins with. . .
*/
#define TZ_MAGIC "TZif"
struct tzhead {
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */
char tzh_charcnt[4]; /* coded number of abbr. chars */
};
/*
. . .followed by. . .
tzh_timecnt (char [4])s coded transition times a la time(2)
tzh_timecnt (unsigned char)s types of local time starting at above
tzh_typecnt repetitions of
one (char [4]) coded UTC offset in seconds
one (unsigned char) used to set tm_isdst
one (unsigned char) that's an abbreviation list index
tzh_charcnt (char)s '\0'-terminated zone abbreviations
tzh_leapcnt repetitions of
one (char [4]) coded leap second transition times
one (char [4]) total correction after above
tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
time is standard time, if FALSE,
transition time is wall clock time
if absent, transition times are
assumed to be wall clock time
tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
time is UTC, if FALSE,
transition time is local time
if absent, transition times are
assumed to be local time
*/
/*
In the current implementation, we refuse to deal with files that
exceed any of the limits below.
*/
#ifndef TZ_MAX_TIMES
/*
The TZ_MAX_TIMES value below is enough to handle a bit more than a
year's worth of solar time (corrected daily to the nearest second) or
138 years of Pacific Presidential Election time
(where there are three time zone transitions every fourth year).
*/
#define TZ_MAX_TIMES 370
#endif /* !defined TZ_MAX_TIMES */
#ifndef TZ_MAX_TYPES
#ifdef SOLAR
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#else
/*
Must be at least 14 for Europe/Riga as of Jan 12 1995,
as noted by Earl Chew <earl@hpato.aus.hp.com>.
*/
#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
#endif /* defined SOLAR */
#endif /* !defined TZ_MAX_TYPES */
#ifndef TZ_MAX_CHARS
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
/* (limited by what unsigned chars can hold) */
#endif /* !defined TZ_MAX_CHARS */
#ifndef TZ_MAX_LEAPS
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
#endif /* !defined TZ_MAX_LEAPS */
#ifndef TZ_MAX_REV_RANGES
#ifdef SOLAR
/* Solar (Asia/RiyadhXX) zones need significantly bigger TZ_MAX_REV_RANGES */
#define TZ_MAX_REV_RANGES (TZ_MAX_TIMES*2+TZ_MAX_LEAPS*2+2)
#else
#define TZ_MAX_REV_RANGES (TZ_MAX_TIMES+TZ_MAX_LEAPS+2)
#endif
#endif
#define SECS_PER_MIN 60
#define MINS_PER_HOUR 60
#define HOURS_PER_DAY 24
#define DAYS_PER_WEEK 7
#define DAYS_PER_NYEAR 365
#define DAYS_PER_LYEAR 366
#define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR)
#define SECS_PER_DAY ((long) SECS_PER_HOUR * HOURS_PER_DAY)
#define MONS_PER_YEAR 12
#define TM_YEAR_BASE 1900
#define EPOCH_YEAR 1970
/*
Accurate only for the past couple of centuries,
that will probably do.
*/
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))

2559
sql/tztime.cc Normal file

File diff suppressed because it is too large Load diff

71
sql/tztime.h Normal file
View file

@ -0,0 +1,71 @@
/* Copyright (C) 2004 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
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 */
#ifdef __GNUC__
#pragma interface /* gcc class interface */
#endif
#if !defined(TESTTIME) && !defined(TZINFO2SQL)
/*
This class represents abstract time zone and provides
basic interface for TIME <-> my_time_t conversion.
Actual time zones which are specified by DB, or via offset
or use system functions are its descendants.
*/
class Time_zone: public Sql_alloc
{
public:
/*
Converts local time in broken down TIME representation to
my_time_t (UTC seconds since Epoch) represenation.
Returns 0 in case of error. Sets in_dst_time_gap to true if date provided
falls into spring time-gap (or lefts it untouched otherwise).
*/
virtual my_time_t TIME_to_gmt_sec(const TIME *t,
bool *in_dst_time_gap) const = 0;
/*
Converts time in my_time_t representation to local time in
broken down TIME representation.
*/
virtual void gmt_sec_to_TIME(TIME *tmp, my_time_t t) const = 0;
/*
Because of constness of String returned by get_name() time zone name
have to be already zeroended to be able to use String::ptr() instead
of c_ptr().
*/
virtual const String * get_name() const = 0;
/*
We need this only for surpressing warnings, objects of this type are
allocated on MEM_ROOT and should not require destruction.
*/
virtual ~Time_zone() {};
};
extern Time_zone * my_tz_UTC;
extern Time_zone * my_tz_SYSTEM;
extern Time_zone * my_tz_find(THD *thd, const String *name);
extern my_bool my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap);
extern void my_tz_free();
/*
Maximum length of time zone name that we support
(Time zone name is char(64) in db)
*/
#define MAX_TIME_ZONE_NAME_LENGTH 72
#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */

View file

@ -633,6 +633,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
DBUG_RETURN(1);
}
table.in_use= current_thd;
table.db_low_byte_first= handler->low_byte_first();
table.blob_ptr_size=portable_sizeof_char_ptr;