2010-01-07 06:42:07 +01:00
|
|
|
/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Most of the following code and structures were derived from
|
|
|
|
public domain code from ftp://elsie.nci.nih.gov/pub
|
2004-06-18 08:11:31 +02:00
|
|
|
(We will refer to this code as to elsie-code further.)
|
|
|
|
*/
|
|
|
|
|
2004-06-25 19:04:48 +02:00
|
|
|
/*
|
|
|
|
We should not include mysql_priv.h in mysql_tzinfo_to_sql utility since
|
|
|
|
it creates unsolved link dependencies on some platforms.
|
|
|
|
*/
|
2005-06-02 02:43:32 +02:00
|
|
|
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
2005-06-05 19:38:52 +02:00
|
|
|
#include <my_global.h>
|
2004-06-25 19:04:48 +02:00
|
|
|
#if !defined(TZINFO2SQL) && !defined(TESTTIME)
|
2004-06-18 08:11:31 +02:00
|
|
|
#include "mysql_priv.h"
|
2004-06-25 19:04:48 +02:00
|
|
|
#else
|
2004-08-05 23:16:43 +02:00
|
|
|
#include <my_time.h>
|
2004-06-25 19:04:48 +02:00
|
|
|
#include "tztime.h"
|
|
|
|
#include <my_sys.h>
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
#include "tzfile.h"
|
|
|
|
#include <m_string.h>
|
|
|
|
#include <my_dir.h>
|
2010-01-07 06:42:07 +01:00
|
|
|
#include <mysql/psi/mysql_file.h>
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Now we don't use abbreviations in server but we will do this in future.
|
|
|
|
*/
|
|
|
|
#if defined(TZINFO2SQL) || defined(TESTTIME)
|
|
|
|
#define ABBR_ARE_USED
|
2004-06-22 01:10:30 +02:00
|
|
|
#else
|
|
|
|
#if !defined(DBUG_OFF)
|
|
|
|
/* Let use abbreviations for debug purposes */
|
2004-06-18 08:11:31 +02:00
|
|
|
#undef ABBR_ARE_USED
|
|
|
|
#define ABBR_ARE_USED
|
2004-06-22 01:10:30 +02:00
|
|
|
#endif /* !defined(DBUG_OFF) */
|
|
|
|
#endif /* defined(TZINFO2SQL) || defined(TESTTIME) */
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/* Structure describing local time type (e.g. Moscow summer time (MSD)) */
|
|
|
|
typedef struct ttinfo
|
|
|
|
{
|
|
|
|
long tt_gmtoff; // Offset from UTC in seconds
|
2004-06-22 01:10:30 +02:00
|
|
|
uint tt_isdst; // Is daylight saving time or not. Used to set tm_isdst
|
2004-06-18 08:11:31 +02:00
|
|
|
#ifdef ABBR_ARE_USED
|
2004-06-22 01:10:30 +02:00
|
|
|
uint tt_abbrind; // Index of start of abbreviation for this time type.
|
2004-06-18 08:11:31 +02:00
|
|
|
#endif
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-23 15:39:56 +02:00
|
|
|
We don't use tt_ttisstd and tt_ttisgmt members of original elsie-code
|
|
|
|
struct since we don't support POSIX-style TZ descriptions in variables.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
} TRAN_TYPE_INFO;
|
|
|
|
|
|
|
|
/* Structure describing leap-second corrections. */
|
2004-06-23 23:41:56 +02:00
|
|
|
typedef struct lsinfo
|
|
|
|
{
|
2004-06-18 08:11:31 +02:00
|
|
|
my_time_t ls_trans; // Transition time
|
|
|
|
long ls_corr; // Correction to apply
|
|
|
|
} LS_INFO;
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Structure with information describing ranges of my_time_t shifted to local
|
2007-03-23 21:08:31 +01:00
|
|
|
time (my_time_t + offset). Used for local MYSQL_TIME -> my_time_t conversion.
|
2004-06-18 08:11:31 +02:00
|
|
|
See comments for TIME_to_gmt_sec() for more info.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
typedef struct revtinfo
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
long rt_offset; // Offset of local time from UTC in seconds
|
2004-06-22 01:10:30 +02:00
|
|
|
uint rt_type; // Type of period 0 - Normal period. 1 - Spring time-gap
|
2004-06-18 08:11:31 +02:00
|
|
|
} REVT_INFO;
|
|
|
|
|
|
|
|
#ifdef TZNAME_MAX
|
|
|
|
#define MY_TZNAME_MAX TZNAME_MAX
|
|
|
|
#endif
|
|
|
|
#ifndef TZNAME_MAX
|
|
|
|
#define MY_TZNAME_MAX 255
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Structure which fully describes time zone which is
|
2004-06-18 08:11:31 +02:00
|
|
|
described in our db or in zoneinfo files.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
typedef struct st_time_zone_info
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-06-22 01:10:30 +02:00
|
|
|
uint leapcnt; // Number of leap-second corrections
|
|
|
|
uint timecnt; // Number of transitions between time types
|
|
|
|
uint typecnt; // Number of local time types
|
|
|
|
uint charcnt; // Number of characters used for abbreviations
|
|
|
|
uint revcnt; // Number of transition descr. for TIME->my_time_t conversion
|
2004-06-18 08:11:31 +02:00
|
|
|
/* The following are dynamical arrays are allocated in MEM_ROOT */
|
|
|
|
my_time_t *ats; // Times of transitions between time types
|
2006-06-19 11:45:34 +02:00
|
|
|
uchar *types; // Local time types for transitions
|
2004-06-18 08:11:31 +02:00
|
|
|
TRAN_TYPE_INFO *ttis; // Local time types descriptions
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
/* Storage for local time types abbreviations. They are stored as ASCIIZ */
|
|
|
|
char *chars;
|
|
|
|
#endif
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
Leap seconds corrections descriptions, this array is shared by
|
2004-06-18 08:11:31 +02:00
|
|
|
all time zones who use leap seconds.
|
|
|
|
*/
|
|
|
|
LS_INFO *lsis;
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
Starting points and descriptions of shifted my_time_t (my_time_t + offset)
|
2004-06-18 08:11:31 +02:00
|
|
|
ranges on which shifted my_time_t -> my_time_t mapping is linear or undefined.
|
|
|
|
Used for tm -> my_time_t conversion.
|
|
|
|
*/
|
|
|
|
my_time_t *revts;
|
|
|
|
REVT_INFO *revtis;
|
|
|
|
/*
|
|
|
|
Time type which is used for times smaller than first transition or if
|
|
|
|
there are no transitions at all.
|
|
|
|
*/
|
|
|
|
TRAN_TYPE_INFO *fallback_tti;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
} TIME_ZONE_INFO;
|
|
|
|
|
|
|
|
|
|
|
|
static my_bool prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(TZINFO2SQL) || defined(TESTTIME)
|
|
|
|
|
|
|
|
/*
|
|
|
|
Load time zone description from zoneinfo (TZinfo) file.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
tz_load()
|
|
|
|
name - path to zoneinfo file
|
2004-06-23 23:41:56 +02:00
|
|
|
sp - TIME_ZONE_INFO structure to fill
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
RETURN VALUES
|
|
|
|
0 - Ok
|
|
|
|
1 - Error
|
|
|
|
*/
|
|
|
|
static my_bool
|
|
|
|
tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
uchar *p;
|
2004-06-22 01:10:30 +02:00
|
|
|
int read_from_file;
|
|
|
|
uint i;
|
2010-01-07 06:42:07 +01:00
|
|
|
MYSQL_FILE *file;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
if (!(file= mysql_file_fopen(0, name, O_RDONLY|O_BINARY, MYF(MY_WME))))
|
2004-06-18 08:11:31 +02:00
|
|
|
return 1;
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct tzhead tzhead;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
uchar buf[sizeof(struct tzhead) + sizeof(my_time_t) * TZ_MAX_TIMES +
|
|
|
|
TZ_MAX_TIMES + sizeof(TRAN_TYPE_INFO) * TZ_MAX_TYPES +
|
2004-06-18 08:11:31 +02:00
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1))) +
|
|
|
|
#endif
|
|
|
|
sizeof(LS_INFO) * TZ_MAX_LEAPS];
|
|
|
|
} u;
|
2004-06-22 01:10:30 +02:00
|
|
|
uint ttisstdcnt;
|
|
|
|
uint ttisgmtcnt;
|
2004-06-18 08:11:31 +02:00
|
|
|
char *tzinfo_buf;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
read_from_file= mysql_file_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME));
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
if (mysql_file_fclose(file, MYF(MY_WME)) != 0)
|
2004-06-18 08:11:31 +02:00
|
|
|
return 1;
|
|
|
|
|
2004-06-22 01:10:30 +02:00
|
|
|
if (read_from_file < (int)sizeof(struct tzhead))
|
2004-06-18 08:11:31 +02:00
|
|
|
return 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
ttisstdcnt= int4net(u.tzhead.tzh_ttisgmtcnt);
|
|
|
|
ttisgmtcnt= int4net(u.tzhead.tzh_ttisstdcnt);
|
|
|
|
sp->leapcnt= int4net(u.tzhead.tzh_leapcnt);
|
|
|
|
sp->timecnt= int4net(u.tzhead.tzh_timecnt);
|
|
|
|
sp->typecnt= int4net(u.tzhead.tzh_typecnt);
|
|
|
|
sp->charcnt= int4net(u.tzhead.tzh_charcnt);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
p= u.tzhead.tzh_charcnt + sizeof(u.tzhead.tzh_charcnt);
|
2004-06-22 01:10:30 +02:00
|
|
|
if (sp->leapcnt > TZ_MAX_LEAPS ||
|
|
|
|
sp->typecnt == 0 || sp->typecnt > TZ_MAX_TYPES ||
|
|
|
|
sp->timecnt > TZ_MAX_TIMES ||
|
|
|
|
sp->charcnt > TZ_MAX_CHARS ||
|
2004-06-18 08:11:31 +02:00
|
|
|
(ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
|
|
|
|
(ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
|
|
|
|
return 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
if ((uint)(read_from_file - (p - u.buf)) <
|
2004-06-22 01:10:30 +02:00
|
|
|
sp->timecnt * 4 + /* ats */
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->timecnt + /* types */
|
|
|
|
sp->typecnt * (4 + 2) + /* ttinfos */
|
|
|
|
sp->charcnt + /* chars */
|
|
|
|
sp->leapcnt * (4 + 4) + /* lsinfos */
|
|
|
|
ttisstdcnt + /* ttisstds */
|
|
|
|
ttisgmtcnt) /* ttisgmts */
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!(tzinfo_buf= (char *)alloc_root(storage,
|
|
|
|
ALIGN_SIZE(sp->timecnt *
|
|
|
|
sizeof(my_time_t)) +
|
|
|
|
ALIGN_SIZE(sp->timecnt) +
|
|
|
|
ALIGN_SIZE(sp->typecnt *
|
|
|
|
sizeof(TRAN_TYPE_INFO)) +
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
ALIGN_SIZE(sp->charcnt) +
|
|
|
|
#endif
|
|
|
|
sp->leapcnt * sizeof(LS_INFO))))
|
|
|
|
return 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->ats= (my_time_t *)tzinfo_buf;
|
|
|
|
tzinfo_buf+= ALIGN_SIZE(sp->timecnt * sizeof(my_time_t));
|
2006-06-19 11:45:34 +02:00
|
|
|
sp->types= (uchar *)tzinfo_buf;
|
2004-06-18 08:11:31 +02:00
|
|
|
tzinfo_buf+= ALIGN_SIZE(sp->timecnt);
|
|
|
|
sp->ttis= (TRAN_TYPE_INFO *)tzinfo_buf;
|
|
|
|
tzinfo_buf+= ALIGN_SIZE(sp->typecnt * sizeof(TRAN_TYPE_INFO));
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
sp->chars= tzinfo_buf;
|
|
|
|
tzinfo_buf+= ALIGN_SIZE(sp->charcnt);
|
|
|
|
#endif
|
|
|
|
sp->lsis= (LS_INFO *)tzinfo_buf;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
for (i= 0; i < sp->timecnt; i++, p+= 4)
|
|
|
|
sp->ats[i]= int4net(p);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
for (i= 0; i < sp->timecnt; i++)
|
|
|
|
{
|
2006-06-19 11:45:34 +02:00
|
|
|
sp->types[i]= (uchar) *p++;
|
2004-06-18 08:11:31 +02:00
|
|
|
if (sp->types[i] >= sp->typecnt)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (i= 0; i < sp->typecnt; i++)
|
|
|
|
{
|
|
|
|
TRAN_TYPE_INFO * ttisp;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
ttisp= &sp->ttis[i];
|
|
|
|
ttisp->tt_gmtoff= int4net(p);
|
|
|
|
p+= 4;
|
2006-06-19 11:45:34 +02:00
|
|
|
ttisp->tt_isdst= (uchar) *p++;
|
2004-06-18 08:11:31 +02:00
|
|
|
if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
|
|
|
|
return 1;
|
2006-06-19 11:45:34 +02:00
|
|
|
ttisp->tt_abbrind= (uchar) *p++;
|
2004-06-22 01:10:30 +02:00
|
|
|
if (ttisp->tt_abbrind > sp->charcnt)
|
2004-06-18 08:11:31 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (i= 0; i < sp->charcnt; i++)
|
|
|
|
sp->chars[i]= *p++;
|
|
|
|
sp->chars[i]= '\0'; /* ensure '\0' at end */
|
|
|
|
for (i= 0; i < sp->leapcnt; i++)
|
|
|
|
{
|
|
|
|
LS_INFO *lsisp;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
lsisp= &sp->lsis[i];
|
|
|
|
lsisp->ls_trans= int4net(p);
|
|
|
|
p+= 4;
|
|
|
|
lsisp->ls_corr= int4net(p);
|
|
|
|
p+= 4;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Since we don't support POSIX style TZ definitions in variables we
|
2004-06-23 23:41:56 +02:00
|
|
|
don't read further like glibc or elsie code.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
return prepare_tz_info(sp, storage);
|
|
|
|
}
|
|
|
|
#endif /* defined(TZINFO2SQL) || defined(TESTTIME) */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Finish preparation of time zone description for use in TIME_to_gmt_sec()
|
2004-06-18 08:11:31 +02:00
|
|
|
and gmt_sec_to_TIME() functions.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
prepare_tz_info()
|
|
|
|
sp - pointer to time zone description
|
|
|
|
storage - pointer to MEM_ROOT where arrays for map allocated
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
First task of this function is to find fallback time type which will
|
|
|
|
be used if there are no transitions or we have moment in time before
|
|
|
|
any transitions.
|
|
|
|
Second task is to build "shifted my_time_t" -> my_time_t map used in
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME -> my_time_t conversion.
|
2004-06-23 23:41:56 +02:00
|
|
|
Note: See description of TIME_to_gmt_sec() function first.
|
2007-03-23 21:08:31 +01:00
|
|
|
In order to perform MYSQL_TIME -> my_time_t conversion we need to build table
|
2004-06-23 23:41:56 +02:00
|
|
|
which defines "shifted by tz offset and leap seconds my_time_t" ->
|
|
|
|
my_time_t function wich is almost the same (except ranges of ambiguity)
|
|
|
|
as reverse function to piecewise linear function used for my_time_t ->
|
2004-06-18 08:11:31 +02:00
|
|
|
"shifted my_time_t" conversion and which is also specified as table in
|
|
|
|
zoneinfo file or in our db (It is specified as start of time type ranges
|
2004-06-23 23:41:56 +02:00
|
|
|
and time type offsets). So basic idea is very simple - let us iterate
|
2004-06-18 08:11:31 +02:00
|
|
|
through my_time_t space from one point of discontinuity of my_time_t ->
|
|
|
|
"shifted my_time_t" function to another and build our approximation of
|
2004-06-23 23:41:56 +02:00
|
|
|
reverse function. (Actually we iterate through ranges on which
|
2004-06-18 08:11:31 +02:00
|
|
|
my_time_t -> "shifted my_time_t" is linear function).
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUES
|
|
|
|
0 Ok
|
2004-06-23 23:41:56 +02:00
|
|
|
1 Error
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
static my_bool
|
2004-06-18 08:11:31 +02:00
|
|
|
prepare_tz_info(TIME_ZONE_INFO *sp, MEM_ROOT *storage)
|
|
|
|
{
|
|
|
|
my_time_t cur_t= MY_TIME_T_MIN;
|
|
|
|
my_time_t cur_l, end_t, end_l;
|
|
|
|
my_time_t cur_max_seen_l= MY_TIME_T_MIN;
|
|
|
|
long cur_offset, cur_corr, cur_off_and_corr;
|
2004-06-22 01:10:30 +02:00
|
|
|
uint next_trans_idx, next_leap_idx;
|
|
|
|
uint i;
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Temporary arrays where we will store tables. Needed because
|
|
|
|
we don't know table sizes ahead. (Well we can estimate their
|
|
|
|
upper bound but this will take extra space.)
|
|
|
|
*/
|
|
|
|
my_time_t revts[TZ_MAX_REV_RANGES];
|
|
|
|
REVT_INFO revtis[TZ_MAX_REV_RANGES];
|
|
|
|
|
|
|
|
LINT_INIT(end_l);
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
Let us setup fallback time type which will be used if we have not any
|
|
|
|
transitions or if we have moment of time before first transition.
|
|
|
|
We will find first non-DST local time type and use it (or use first
|
2004-06-18 08:11:31 +02:00
|
|
|
local time type if all of them are DST types).
|
|
|
|
*/
|
|
|
|
for (i= 0; i < sp->typecnt && sp->ttis[i].tt_isdst; i++)
|
|
|
|
/* no-op */ ;
|
|
|
|
if (i == sp->typecnt)
|
|
|
|
i= 0;
|
|
|
|
sp->fallback_tti= &(sp->ttis[i]);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Let us build shifted my_time_t -> my_time_t map.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
sp->revcnt= 0;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* Let us find initial offset */
|
|
|
|
if (sp->timecnt == 0 || cur_t < sp->ats[0])
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
If we have not any transitions or t is before first transition we are using
|
|
|
|
already found fallback time type which index is already in i.
|
|
|
|
*/
|
|
|
|
next_trans_idx= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* cur_t == sp->ats[0] so we found transition */
|
|
|
|
i= sp->types[0];
|
|
|
|
next_trans_idx= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_offset= sp->ttis[i].tt_gmtoff;
|
|
|
|
|
|
|
|
|
|
|
|
/* let us find leap correction... unprobable, but... */
|
2004-06-23 23:41:56 +02:00
|
|
|
for (next_leap_idx= 0; next_leap_idx < sp->leapcnt &&
|
2004-06-18 08:11:31 +02:00
|
|
|
cur_t >= sp->lsis[next_leap_idx].ls_trans;
|
|
|
|
++next_leap_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (next_leap_idx > 0)
|
|
|
|
cur_corr= sp->lsis[next_leap_idx - 1].ls_corr;
|
|
|
|
else
|
|
|
|
cur_corr= 0;
|
|
|
|
|
|
|
|
/* Iterate trough t space */
|
|
|
|
while (sp->revcnt < TZ_MAX_REV_RANGES - 1)
|
|
|
|
{
|
|
|
|
cur_off_and_corr= cur_offset - cur_corr;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
We assuming that cur_t could be only overflowed downwards,
|
|
|
|
we also assume that end_t won't be overflowed in this case.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
if (cur_off_and_corr < 0 &&
|
2004-06-18 08:11:31 +02:00
|
|
|
cur_t < MY_TIME_T_MIN - cur_off_and_corr)
|
|
|
|
cur_t= MY_TIME_T_MIN - cur_off_and_corr;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
cur_l= cur_t + cur_off_and_corr;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Let us choose end_t as point before next time type change or leap
|
|
|
|
second correction.
|
|
|
|
*/
|
|
|
|
end_t= min((next_trans_idx < sp->timecnt) ? sp->ats[next_trans_idx] - 1:
|
|
|
|
MY_TIME_T_MAX,
|
2004-06-23 23:41:56 +02:00
|
|
|
(next_leap_idx < sp->leapcnt) ?
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->lsis[next_leap_idx].ls_trans - 1: MY_TIME_T_MAX);
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
again assuming that end_t can be overlowed only in positive side
|
|
|
|
we also assume that end_t won't be overflowed in this case.
|
|
|
|
*/
|
|
|
|
if (cur_off_and_corr > 0 &&
|
|
|
|
end_t > MY_TIME_T_MAX - cur_off_and_corr)
|
|
|
|
end_t= MY_TIME_T_MAX - cur_off_and_corr;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
end_l= end_t + cur_off_and_corr;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
if (end_l > cur_max_seen_l)
|
|
|
|
{
|
|
|
|
/* We want special handling in the case of first range */
|
|
|
|
if (cur_max_seen_l == MY_TIME_T_MIN)
|
|
|
|
{
|
|
|
|
revts[sp->revcnt]= cur_l;
|
|
|
|
revtis[sp->revcnt].rt_offset= cur_off_and_corr;
|
|
|
|
revtis[sp->revcnt].rt_type= 0;
|
|
|
|
sp->revcnt++;
|
|
|
|
cur_max_seen_l= end_l;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cur_l > cur_max_seen_l + 1)
|
|
|
|
{
|
|
|
|
/* We have a spring time-gap and we are not at the first range */
|
|
|
|
revts[sp->revcnt]= cur_max_seen_l + 1;
|
|
|
|
revtis[sp->revcnt].rt_offset= revtis[sp->revcnt-1].rt_offset;
|
|
|
|
revtis[sp->revcnt].rt_type= 1;
|
|
|
|
sp->revcnt++;
|
|
|
|
if (sp->revcnt == TZ_MAX_TIMES + TZ_MAX_LEAPS + 1)
|
|
|
|
break; /* That was too much */
|
|
|
|
cur_max_seen_l= cur_l - 1;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* Assume here end_l > cur_max_seen_l (because end_l>=cur_l) */
|
|
|
|
|
|
|
|
revts[sp->revcnt]= cur_max_seen_l + 1;
|
|
|
|
revtis[sp->revcnt].rt_offset= cur_off_and_corr;
|
|
|
|
revtis[sp->revcnt].rt_type= 0;
|
|
|
|
sp->revcnt++;
|
|
|
|
cur_max_seen_l= end_l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
if (end_t == MY_TIME_T_MAX ||
|
2009-06-10 16:04:07 +02:00
|
|
|
((cur_off_and_corr > 0) &&
|
|
|
|
(end_t >= MY_TIME_T_MAX - cur_off_and_corr)))
|
2004-06-18 08:11:31 +02:00
|
|
|
/* end of t space */
|
|
|
|
break;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
cur_t= end_t + 1;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Let us find new offset and correction. Because of our choice of end_t
|
2004-06-23 23:41:56 +02:00
|
|
|
cur_t can only be point where new time type starts or/and leap
|
2004-06-18 08:11:31 +02:00
|
|
|
correction is performed.
|
|
|
|
*/
|
|
|
|
if (sp->timecnt != 0 && cur_t >= sp->ats[0]) /* else reuse old offset */
|
2004-06-23 23:41:56 +02:00
|
|
|
if (next_trans_idx < sp->timecnt &&
|
2004-06-18 08:11:31 +02:00
|
|
|
cur_t == sp->ats[next_trans_idx])
|
|
|
|
{
|
|
|
|
/* We are at offset point */
|
|
|
|
cur_offset= sp->ttis[sp->types[next_trans_idx]].tt_gmtoff;
|
|
|
|
++next_trans_idx;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (next_leap_idx < sp->leapcnt &&
|
|
|
|
cur_t == sp->lsis[next_leap_idx].ls_trans)
|
|
|
|
{
|
|
|
|
/* we are at leap point */
|
|
|
|
cur_corr= sp->lsis[next_leap_idx].ls_corr;
|
|
|
|
++next_leap_idx;
|
|
|
|
}
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* check if we have had enough space */
|
|
|
|
if (sp->revcnt == TZ_MAX_REV_RANGES - 1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* set maximum end_l as finisher */
|
|
|
|
revts[sp->revcnt]= end_l;
|
|
|
|
|
|
|
|
/* Allocate arrays of proper size in sp and copy result there */
|
|
|
|
if (!(sp->revts= (my_time_t *)alloc_root(storage,
|
|
|
|
sizeof(my_time_t) * (sp->revcnt + 1))) ||
|
|
|
|
!(sp->revtis= (REVT_INFO *)alloc_root(storage,
|
|
|
|
sizeof(REVT_INFO) * sp->revcnt)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
memcpy(sp->revts, revts, sizeof(my_time_t) * (sp->revcnt + 1));
|
|
|
|
memcpy(sp->revtis, revtis, sizeof(REVT_INFO) * sp->revcnt);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-25 19:04:48 +02:00
|
|
|
#if !defined(TZINFO2SQL)
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
static const uint mon_lengths[2][MONS_PER_YEAR]=
|
|
|
|
{
|
|
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint mon_starts[2][MONS_PER_YEAR]=
|
|
|
|
{
|
|
|
|
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
|
|
|
|
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint year_lengths[2]=
|
|
|
|
{
|
|
|
|
DAYS_PER_NYEAR, DAYS_PER_LYEAR
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
|
|
|
|
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
Converts time from my_time_t representation (seconds in UTC since Epoch)
|
2004-06-18 08:11:31 +02:00
|
|
|
to broken down representation using given local time zone offset.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
sec_to_TIME()
|
|
|
|
tmp - pointer to structure for broken down representation
|
|
|
|
t - my_time_t value to be converted
|
|
|
|
offset - local time zone offset
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2007-03-23 21:08:31 +01:00
|
|
|
Convert my_time_t with offset to MYSQL_TIME struct. Differs from timesub
|
2004-06-23 23:41:56 +02:00
|
|
|
(from elsie code) because doesn't contain any leap correction and
|
|
|
|
TM_GMTOFF and is_dst setting and contains some MySQL specific
|
2004-06-18 08:11:31 +02:00
|
|
|
initialization. Funny but with removing of these we almost have
|
|
|
|
glibc's offtime function.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-23 21:08:31 +01:00
|
|
|
sec_to_TIME(MYSQL_TIME * tmp, my_time_t t, long offset)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
long days;
|
|
|
|
long rem;
|
|
|
|
int y;
|
|
|
|
int yleap;
|
|
|
|
const uint *ip;
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
days= (long) (t / SECS_PER_DAY);
|
|
|
|
rem= (long) (t % SECS_PER_DAY);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
We do this as separate step after dividing t, because this
|
2004-06-18 08:11:31 +02:00
|
|
|
allows us handle times near my_time_t bounds without overflows.
|
|
|
|
*/
|
|
|
|
rem+= offset;
|
|
|
|
while (rem < 0)
|
|
|
|
{
|
|
|
|
rem+= SECS_PER_DAY;
|
|
|
|
days--;
|
|
|
|
}
|
|
|
|
while (rem >= SECS_PER_DAY)
|
|
|
|
{
|
|
|
|
rem -= SECS_PER_DAY;
|
|
|
|
days++;
|
|
|
|
}
|
|
|
|
tmp->hour= (uint)(rem / SECS_PER_HOUR);
|
|
|
|
rem= rem % SECS_PER_HOUR;
|
|
|
|
tmp->minute= (uint)(rem / SECS_PER_MIN);
|
|
|
|
/*
|
|
|
|
A positive leap second requires a special
|
|
|
|
representation. This uses "... ??:59:60" et seq.
|
|
|
|
*/
|
|
|
|
tmp->second= (uint)(rem % SECS_PER_MIN);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
y= EPOCH_YEAR;
|
|
|
|
while (days < 0 || days >= (long)year_lengths[yleap= isleap(y)])
|
|
|
|
{
|
|
|
|
int newy;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
newy= y + days / DAYS_PER_NYEAR;
|
|
|
|
if (days < 0)
|
|
|
|
newy--;
|
|
|
|
days-= (newy - y) * DAYS_PER_NYEAR +
|
|
|
|
LEAPS_THRU_END_OF(newy - 1) -
|
|
|
|
LEAPS_THRU_END_OF(y - 1);
|
|
|
|
y= newy;
|
|
|
|
}
|
|
|
|
tmp->year= y;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
ip= mon_lengths[yleap];
|
|
|
|
for (tmp->month= 0; days >= (long) ip[tmp->month]; tmp->month++)
|
|
|
|
days= days - (long) ip[tmp->month];
|
|
|
|
tmp->month++;
|
|
|
|
tmp->day= (uint)(days + 1);
|
|
|
|
|
2007-03-23 21:08:31 +01:00
|
|
|
/* filling MySQL specific MYSQL_TIME members */
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp->neg= 0; tmp->second_part= 0;
|
2004-06-24 17:08:36 +02:00
|
|
|
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Find time range wich contains given my_time_t value
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
find_time_range()
|
2004-06-23 23:41:56 +02:00
|
|
|
t - my_time_t value for which we looking for range
|
2004-06-18 08:11:31 +02:00
|
|
|
range_boundaries - sorted array of range starts.
|
|
|
|
higher_bound - number of ranges
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
Performs binary search for range which contains given my_time_t value.
|
2004-06-18 08:11:31 +02:00
|
|
|
It has sense if number of ranges is greater than zero and my_time_t value
|
|
|
|
is greater or equal than beginning of first range. It also assumes that
|
|
|
|
t belongs to some range specified or end of last is MY_TIME_T_MAX.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
With this localtime_r on real data may takes less time than with linear
|
|
|
|
search (I've seen 30% speed up).
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
Index of range to which t belongs
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
static uint
|
2004-06-18 08:11:31 +02:00
|
|
|
find_time_range(my_time_t t, const my_time_t *range_boundaries,
|
|
|
|
uint higher_bound)
|
|
|
|
{
|
|
|
|
uint i, lower_bound= 0;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Function will work without this assertion but result would be meaningless.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(higher_bound > 0 && t >= range_boundaries[0]);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Do binary search for minimal interval which contain t. We preserve:
|
2004-06-23 23:41:56 +02:00
|
|
|
range_boundaries[lower_bound] <= t < range_boundaries[higher_bound]
|
|
|
|
invariant and decrease this higher_bound - lower_bound gap twice
|
2004-06-18 08:11:31 +02:00
|
|
|
times on each step.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
while (higher_bound - lower_bound > 1)
|
|
|
|
{
|
|
|
|
i= (lower_bound + higher_bound) >> 1;
|
|
|
|
if (range_boundaries[i] <= t)
|
|
|
|
lower_bound= i;
|
|
|
|
else
|
|
|
|
higher_bound= i;
|
|
|
|
}
|
|
|
|
return lower_bound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Find local time transition for given my_time_t.
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
find_transition_type()
|
|
|
|
t - my_time_t value to be converted
|
|
|
|
sp - pointer to struct with time zone description
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
Pointer to structure in time zone description describing
|
|
|
|
local time type for given my_time_t.
|
|
|
|
*/
|
|
|
|
static
|
2004-06-23 23:41:56 +02:00
|
|
|
const TRAN_TYPE_INFO *
|
2004-06-18 08:11:31 +02:00
|
|
|
find_transition_type(my_time_t t, const TIME_ZONE_INFO *sp)
|
|
|
|
{
|
|
|
|
if (unlikely(sp->timecnt == 0 || t < sp->ats[0]))
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
If we have not any transitions or t is before first transition let
|
|
|
|
us use fallback time type.
|
|
|
|
*/
|
|
|
|
return sp->fallback_tti;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Do binary search for minimal interval between transitions which
|
2004-06-23 23:41:56 +02:00
|
|
|
contain t. With this localtime_r on real data may takes less
|
2004-06-18 08:11:31 +02:00
|
|
|
time than with linear search (I've seen 30% speed up).
|
|
|
|
*/
|
|
|
|
return &(sp->ttis[sp->types[find_time_range(t, sp->ats, sp->timecnt)]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts time in my_time_t representation (seconds in UTC since Epoch) to
|
2007-03-23 21:08:31 +01:00
|
|
|
broken down MYSQL_TIME representation in local time zone.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
gmt_sec_to_TIME()
|
|
|
|
tmp - pointer to structure for broken down represenatation
|
|
|
|
sec_in_utc - my_time_t value to be converted
|
|
|
|
sp - pointer to struct with time zone description
|
|
|
|
|
|
|
|
TODO
|
2004-06-23 23:41:56 +02:00
|
|
|
We can improve this function by creating joined array of transitions and
|
2004-06-18 08:11:31 +02:00
|
|
|
leap corrections. This will require adding extra field to TRAN_TYPE_INFO
|
2004-06-23 23:41:56 +02:00
|
|
|
for storing number of "extra" seconds to minute occured due to correction
|
|
|
|
(60th and 61st second, look how we calculate them as "hit" in this
|
2004-06-18 08:11:31 +02:00
|
|
|
function).
|
2004-06-23 23:41:56 +02:00
|
|
|
Under realistic assumptions about frequency of transitions the same array
|
2007-03-23 21:08:31 +01:00
|
|
|
can be used fot MYSQL_TIME -> my_time_t conversion. For this we need to
|
2004-06-23 23:41:56 +02:00
|
|
|
implement tweaked binary search which will take into account that some
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME has two matching my_time_t ranges and some of them have none.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
static void
|
2007-03-23 21:08:31 +01:00
|
|
|
gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t sec_in_utc, const TIME_ZONE_INFO *sp)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
const TRAN_TYPE_INFO *ttisp;
|
|
|
|
const LS_INFO *lp;
|
|
|
|
long corr= 0;
|
|
|
|
int hit= 0;
|
|
|
|
int i;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Find proper transition (and its local time type) for our sec_in_utc value.
|
2004-06-23 23:41:56 +02:00
|
|
|
Funny but again by separating this step in function we receive code
|
2004-06-18 08:11:31 +02:00
|
|
|
which very close to glibc's code. No wonder since they obviously use
|
|
|
|
the same base and all steps are sensible.
|
|
|
|
*/
|
|
|
|
ttisp= find_transition_type(sec_in_utc, sp);
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Let us find leap correction for our sec_in_utc value and number of extra
|
|
|
|
secs to add to this minute.
|
2004-06-23 23:41:56 +02:00
|
|
|
This loop is rarely used because most users will use time zones without
|
|
|
|
leap seconds, and even in case when we have such time zone there won't
|
2004-06-18 08:11:31 +02:00
|
|
|
be many iterations (we have about 22 corrections at this moment (2004)).
|
|
|
|
*/
|
|
|
|
for ( i= sp->leapcnt; i-- > 0; )
|
|
|
|
{
|
|
|
|
lp= &sp->lsis[i];
|
|
|
|
if (sec_in_utc >= lp->ls_trans)
|
|
|
|
{
|
|
|
|
if (sec_in_utc == lp->ls_trans)
|
|
|
|
{
|
|
|
|
hit= ((i == 0 && lp->ls_corr > 0) ||
|
|
|
|
lp->ls_corr > sp->lsis[i - 1].ls_corr);
|
|
|
|
if (hit)
|
|
|
|
{
|
|
|
|
while (i > 0 &&
|
|
|
|
sp->lsis[i].ls_trans == sp->lsis[i - 1].ls_trans + 1 &&
|
|
|
|
sp->lsis[i].ls_corr == sp->lsis[i - 1].ls_corr + 1)
|
|
|
|
{
|
|
|
|
hit++;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
corr= lp->ls_corr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
sec_to_TIME(tmp, sec_in_utc, ttisp->tt_gmtoff - corr);
|
|
|
|
|
|
|
|
tmp->second+= hit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts local time in broken down representation to local
|
|
|
|
time zone analog of my_time_t represenation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
sec_since_epoch()
|
|
|
|
year, mon, mday, hour, min, sec - broken down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
|
|
|
Converts time in broken down representation to my_time_t representation
|
|
|
|
ignoring time zone. Note that we cannot convert back some valid _local_
|
2004-06-23 23:41:56 +02:00
|
|
|
times near ends of my_time_t range because of my_time_t overflow. But we
|
2004-06-18 08:11:31 +02:00
|
|
|
ignore this fact now since MySQL will never pass such argument.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
Seconds since epoch time representation.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
static my_time_t
|
2004-06-18 08:11:31 +02:00
|
|
|
sec_since_epoch(int year, int mon, int mday, int hour, int min ,int sec)
|
|
|
|
{
|
2007-02-23 17:33:11 +01:00
|
|
|
/* Guard against my_time_t overflow(on system with 32 bit my_time_t) */
|
|
|
|
DBUG_ASSERT(!(year == TIMESTAMP_MAX_YEAR && mon == 1 && mday > 17));
|
2004-06-18 08:11:31 +02:00
|
|
|
#ifndef WE_WANT_TO_HANDLE_UNORMALIZED_DATES
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
It turns out that only whenever month is normalized or unnormalized
|
|
|
|
plays role.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(mon > 0 && mon < 13);
|
|
|
|
long days= year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR +
|
|
|
|
LEAPS_THRU_END_OF(year - 1) -
|
|
|
|
LEAPS_THRU_END_OF(EPOCH_YEAR - 1);
|
|
|
|
days+= mon_starts[isleap(year)][mon - 1];
|
|
|
|
#else
|
|
|
|
long norm_month= (mon - 1) % MONS_PER_YEAR;
|
|
|
|
long a_year= year + (mon - 1)/MONS_PER_YEAR - (int)(norm_month < 0);
|
|
|
|
long days= a_year * DAYS_PER_NYEAR - EPOCH_YEAR * DAYS_PER_NYEAR +
|
|
|
|
LEAPS_THRU_END_OF(a_year - 1) -
|
|
|
|
LEAPS_THRU_END_OF(EPOCH_YEAR - 1);
|
|
|
|
days+= mon_starts[isleap(a_year)]
|
|
|
|
[norm_month + (norm_month < 0 ? MONS_PER_YEAR : 0)];
|
|
|
|
#endif
|
|
|
|
days+= mday - 1;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
return ((days * HOURS_PER_DAY + hour) * MINS_PER_HOUR + min) *
|
2004-06-18 08:11:31 +02:00
|
|
|
SECS_PER_MIN + sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-23 21:08:31 +01:00
|
|
|
Converts local time in broken down MYSQL_TIME representation to my_time_t
|
2004-06-18 08:11:31 +02:00
|
|
|
representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
TIME_to_gmt_sec()
|
|
|
|
t - pointer to structure for broken down represenatation
|
|
|
|
sp - pointer to struct with time zone description
|
2004-06-23 23:41:56 +02:00
|
|
|
in_dst_time_gap - pointer to bool which is set to true if datetime
|
2004-06-18 08:11:31 +02:00
|
|
|
value passed doesn't really exist (i.e. falls into
|
|
|
|
spring time-gap) and is not touched otherwise.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
This is mktime analog for MySQL. It is essentially different
|
2004-06-18 08:11:31 +02:00
|
|
|
from mktime (or hypotetical my_mktime) because:
|
2004-06-23 23:41:56 +02:00
|
|
|
- It has no idea about tm_isdst member so if it
|
2004-06-18 08:11:31 +02:00
|
|
|
has two answers it will give the smaller one
|
2004-06-23 23:41:56 +02:00
|
|
|
- If we are in spring time gap then it will return
|
2004-06-18 08:11:31 +02:00
|
|
|
beginning of the gap
|
2004-06-23 23:41:56 +02:00
|
|
|
- It can give wrong results near the ends of my_time_t due to
|
|
|
|
overflows, but we are safe since in MySQL we will never
|
2004-06-18 08:11:31 +02:00
|
|
|
call this function for such dates (its restriction for year
|
|
|
|
between 1970 and 2038 gives us several days of reserve).
|
2004-06-23 23:41:56 +02:00
|
|
|
- By default it doesn't support un-normalized input. But if
|
2004-06-18 08:11:31 +02:00
|
|
|
sec_since_epoch() function supports un-normalized dates
|
2004-06-23 23:41:56 +02:00
|
|
|
then this function should handle un-normalized input right,
|
2004-06-18 08:11:31 +02:00
|
|
|
altough it won't normalize structure TIME.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
Traditional approach to problem of conversion from broken down
|
|
|
|
representation to time_t is iterative. Both elsie's and glibc
|
|
|
|
implementation try to guess what time_t value should correspond to
|
|
|
|
this broken-down value. They perform localtime_r function on their
|
|
|
|
guessed value and then calculate the difference and try to improve
|
2004-06-18 08:11:31 +02:00
|
|
|
their guess. Elsie's code guesses time_t value in bit by bit manner,
|
2004-06-23 23:41:56 +02:00
|
|
|
Glibc's code tries to add difference between broken-down value
|
2004-06-18 08:11:31 +02:00
|
|
|
corresponding to guess and target broken-down value to current guess.
|
2004-06-23 23:41:56 +02:00
|
|
|
It also uses caching of last found correction... So Glibc's approach
|
|
|
|
is essentially faster but introduces some undetermenism (in case if
|
2004-06-18 08:11:31 +02:00
|
|
|
is_dst member of broken-down representation (tm struct) is not known
|
|
|
|
and we have two possible answers).
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
We use completely different approach. It is better since it is both
|
2004-06-18 08:11:31 +02:00
|
|
|
faster than iterative implementations and fully determenistic. If you
|
2007-03-23 21:08:31 +01:00
|
|
|
look at my_time_t to MYSQL_TIME conversion then you'll find that it consist
|
2004-06-18 08:11:31 +02:00
|
|
|
of two steps:
|
|
|
|
The first is calculating shifted my_time_t value and the second - TIME
|
2004-06-23 23:41:56 +02:00
|
|
|
calculation from shifted my_time_t value (well it is a bit simplified
|
2004-06-18 08:11:31 +02:00
|
|
|
picture). The part in which we are interested in is my_time_t -> shifted
|
|
|
|
my_time_t conversion. It is piecewise linear function which is defined
|
2004-06-23 23:41:56 +02:00
|
|
|
by combination of transition times as break points and times offset
|
|
|
|
as changing function parameter. The possible inverse function for this
|
|
|
|
converison would be ambiguos but with MySQL's restrictions we can use
|
|
|
|
some function which is the same as inverse function on unambigiuos
|
|
|
|
ranges and coincides with one of branches of inverse function in
|
|
|
|
other ranges. Thus we just need to build table which will determine
|
|
|
|
this shifted my_time_t -> my_time_t conversion similar to existing
|
|
|
|
(my_time_t -> shifted my_time_t table). We do this in
|
2004-06-18 08:11:31 +02:00
|
|
|
prepare_tz_info function.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
TODO
|
2004-06-23 23:41:56 +02:00
|
|
|
If we can even more improve this function. For doing this we will need to
|
2004-06-18 08:11:31 +02:00
|
|
|
build joined map of transitions and leap corrections for gmt_sec_to_TIME()
|
2004-06-23 23:41:56 +02:00
|
|
|
function (similar to revts/revtis). Under realistic assumptions about
|
2004-06-18 08:11:31 +02:00
|
|
|
frequency of transitions we can use the same array for TIME_to_gmt_sec().
|
|
|
|
We need to implement special version of binary search for this. Such step
|
|
|
|
will be beneficial to CPU cache since we will decrease data-set used for
|
|
|
|
conversion twice.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
2004-06-23 23:41:56 +02:00
|
|
|
Seconds in UTC since Epoch.
|
2004-06-18 08:11:31 +02:00
|
|
|
0 in case of error.
|
|
|
|
*/
|
|
|
|
static my_time_t
|
2007-03-23 21:08:31 +01:00
|
|
|
TIME_to_gmt_sec(const MYSQL_TIME *t, const TIME_ZONE_INFO *sp,
|
2005-07-31 11:49:55 +02:00
|
|
|
my_bool *in_dst_time_gap)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
my_time_t local_t;
|
|
|
|
uint saved_seconds;
|
|
|
|
uint i;
|
2006-11-01 14:47:40 +01:00
|
|
|
int shift= 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("TIME_to_gmt_sec");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2006-11-01 14:47:40 +01:00
|
|
|
if (!validate_timestamp_range(t))
|
2006-11-05 21:25:34 +01:00
|
|
|
DBUG_RETURN(0);
|
2006-11-01 14:47:40 +01:00
|
|
|
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* We need this for correct leap seconds handling */
|
|
|
|
if (t->second < SECS_PER_MIN)
|
|
|
|
saved_seconds= 0;
|
|
|
|
else
|
|
|
|
saved_seconds= t->second;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2006-11-01 14:47:40 +01:00
|
|
|
NOTE: to convert full my_time_t range we do a shift of the
|
|
|
|
boundary dates here to avoid overflow of my_time_t.
|
|
|
|
We use alike approach in my_system_gmt_sec().
|
|
|
|
|
|
|
|
However in that function we also have to take into account
|
|
|
|
overflow near 0 on some platforms. That's because my_system_gmt_sec
|
|
|
|
uses localtime_r(), which doesn't work with negative values correctly
|
|
|
|
on platforms with unsigned time_t (QNX). Here we don't use localtime()
|
|
|
|
=> we negative values of local_t are ok.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2006-11-01 14:47:40 +01:00
|
|
|
if ((t->year == TIMESTAMP_MAX_YEAR) && (t->month == 1) && t->day > 4)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We will pass (t->day - shift) to sec_since_epoch(), and
|
|
|
|
want this value to be a positive number, so we shift
|
|
|
|
only dates > 4.01.2038 (to avoid owerflow).
|
|
|
|
*/
|
|
|
|
shift= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local_t= sec_since_epoch(t->year, t->month, (t->day - shift),
|
2004-06-23 23:41:56 +02:00
|
|
|
t->hour, t->minute,
|
2004-06-18 08:11:31 +02:00
|
|
|
saved_seconds ? 0 : t->second);
|
|
|
|
|
|
|
|
/* We have at least one range */
|
|
|
|
DBUG_ASSERT(sp->revcnt >= 1);
|
|
|
|
|
|
|
|
if (local_t < sp->revts[0] || local_t > sp->revts[sp->revcnt])
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
This means that source time can't be represented as my_time_t due to
|
|
|
|
limited my_time_t range.
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* binary search for our range */
|
|
|
|
i= find_time_range(local_t, sp->revts, sp->revcnt);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2006-11-01 14:47:40 +01:00
|
|
|
/*
|
|
|
|
As there are no offset switches at the end of TIMESTAMP range,
|
|
|
|
we could simply check for overflow here (and don't need to bother
|
|
|
|
about DST gaps etc)
|
|
|
|
*/
|
|
|
|
if (shift)
|
|
|
|
{
|
2007-02-23 17:33:11 +01:00
|
|
|
if (local_t > (my_time_t) (TIMESTAMP_MAX_VALUE - shift * SECS_PER_DAY +
|
2006-11-20 21:42:06 +01:00
|
|
|
sp->revtis[i].rt_offset - saved_seconds))
|
2006-11-01 14:47:40 +01:00
|
|
|
{
|
|
|
|
DBUG_RETURN(0); /* my_time_t overflow */
|
|
|
|
}
|
2007-02-23 17:33:11 +01:00
|
|
|
local_t+= shift * SECS_PER_DAY;
|
2006-11-01 14:47:40 +01:00
|
|
|
}
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (sp->revtis[i].rt_type)
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Oops! We are in spring time gap.
|
|
|
|
May be we should return error here?
|
|
|
|
Now we are returning my_time_t value corresponding to the
|
|
|
|
beginning of the gap.
|
|
|
|
*/
|
|
|
|
*in_dst_time_gap= 1;
|
2006-11-01 14:47:40 +01:00
|
|
|
local_t= sp->revts[i] - sp->revtis[i].rt_offset + saved_seconds;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
else
|
2006-11-01 14:47:40 +01:00
|
|
|
local_t= local_t - sp->revtis[i].rt_offset + saved_seconds;
|
|
|
|
|
|
|
|
/* check for TIMESTAMP_MAX_VALUE was already done above */
|
|
|
|
if (local_t < TIMESTAMP_MIN_VALUE)
|
|
|
|
local_t= 0;
|
|
|
|
|
|
|
|
DBUG_RETURN(local_t);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
End of elsie derived code.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-25 19:04:48 +02:00
|
|
|
#endif /* !defined(TZINFO2SQL) */
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
#if !defined(TESTTIME) && !defined(TZINFO2SQL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
String with names of SYSTEM time zone.
|
|
|
|
*/
|
|
|
|
static const String tz_SYSTEM_name("SYSTEM", 6, &my_charset_latin1);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Instance of this class represents local time zone used on this system
|
2004-06-18 08:11:31 +02:00
|
|
|
(specified by TZ environment variable or via any other system mechanism).
|
2004-06-23 23:41:56 +02:00
|
|
|
It uses system functions (localtime_r, my_system_gmt_sec) for conversion
|
2004-06-18 08:11:31 +02:00
|
|
|
and is always available. Because of this it is used by default - if there
|
|
|
|
were no explicit time zone specified. On the other hand because of this
|
2004-06-23 23:41:56 +02:00
|
|
|
conversion methods provided by this class is significantly slower and
|
|
|
|
possibly less multi-threaded-friendly than corresponding Time_zone_db
|
2004-06-18 08:11:31 +02:00
|
|
|
methods so the latter should be preffered there it is possible.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
class Time_zone_system : public Time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-02-25 16:46:30 +01:00
|
|
|
Time_zone_system() {} /* Remove gcc warning */
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
|
2005-07-31 11:49:55 +02:00
|
|
|
my_bool *in_dst_time_gap) const;
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
|
2004-06-18 08:11:31 +02:00
|
|
|
virtual const String * get_name() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-03-23 21:08:31 +01:00
|
|
|
Converts local time in system time zone in MYSQL_TIME representation
|
2004-06-18 08:11:31 +02:00
|
|
|
to its my_time_t representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
TIME_to_gmt_sec()
|
2007-03-23 21:08:31 +01:00
|
|
|
t - pointer to MYSQL_TIME structure with local time in
|
2004-06-18 08:11:31 +02:00
|
|
|
broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
in_dst_time_gap - pointer to bool which is set to true if datetime
|
2004-06-18 08:11:31 +02:00
|
|
|
value passed doesn't really exist (i.e. falls into
|
|
|
|
spring time-gap) and is not touched otherwise.
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This method uses system function (localtime_r()) for conversion
|
2007-03-23 21:08:31 +01:00
|
|
|
local time in system time zone in MYSQL_TIME structure to its my_time_t
|
2004-06-18 08:11:31 +02:00
|
|
|
representation. Unlike the same function for Time_zone_db class
|
2004-06-23 23:41:56 +02:00
|
|
|
it it won't handle unnormalized input properly. Still it will
|
|
|
|
return lowest possible my_time_t in case of ambiguity or if we
|
2004-06-18 08:11:31 +02:00
|
|
|
provide time corresponding to the time-gap.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2008-04-03 17:32:00 +02:00
|
|
|
You should call my_init_time() function before using this function.
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Corresponding my_time_t value or 0 in case of error
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
my_time_t
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_system::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
long not_used;
|
|
|
|
return my_system_gmt_sec(t, ¬_used, in_dst_time_gap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts time from UTC seconds since Epoch (my_time_t) representation
|
|
|
|
to system local time zone broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
gmt_sec_to_TIME()
|
2007-03-23 21:08:31 +01:00
|
|
|
tmp - pointer to MYSQL_TIME structure to fill-in
|
2004-06-23 23:41:56 +02:00
|
|
|
t - my_time_t value to be converted
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
NOTE
|
2004-06-18 08:11:31 +02:00
|
|
|
We assume that value passed to this function will fit into time_t range
|
2004-06-23 23:41:56 +02:00
|
|
|
supported by localtime_r. This conversion is putting restriction on
|
2004-06-18 08:11:31 +02:00
|
|
|
TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
|
2004-06-23 23:41:56 +02:00
|
|
|
for interaction with client then we can extend TIMESTAMP range down to
|
2004-06-18 08:11:31 +02:00
|
|
|
the 1902 easily.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
void
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_system::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
struct tm tmp_tm;
|
|
|
|
time_t tmp_t= (time_t)t;
|
|
|
|
|
|
|
|
localtime_r(&tmp_t, &tmp_tm);
|
|
|
|
localtime_to_TIME(tmp, &tmp_tm);
|
2004-06-24 17:08:36 +02:00
|
|
|
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
|
2008-12-01 15:18:35 +01:00
|
|
|
adjust_leap_second(tmp);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get name of time zone
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
get_name()
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Name of time zone as String
|
|
|
|
*/
|
|
|
|
const String *
|
|
|
|
Time_zone_system::get_name() const
|
|
|
|
{
|
|
|
|
return &tz_SYSTEM_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Instance of this class represents UTC time zone. It uses system gmtime_r
|
|
|
|
function for conversions and is always available. It is used only for
|
2007-03-23 21:08:31 +01:00
|
|
|
my_time_t -> MYSQL_TIME conversions in various UTC_... functions, it is not
|
|
|
|
intended for MYSQL_TIME -> my_time_t conversions and shouldn't be exposed to user.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
class Time_zone_utc : public Time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2006-02-25 16:46:30 +01:00
|
|
|
Time_zone_utc() {} /* Remove gcc warning */
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
|
2005-07-31 11:49:55 +02:00
|
|
|
my_bool *in_dst_time_gap) const;
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
|
2004-06-18 08:11:31 +02:00
|
|
|
virtual const String * get_name() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-03-23 21:08:31 +01:00
|
|
|
Convert UTC time from MYSQL_TIME representation to its my_time_t representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
TIME_to_gmt_sec()
|
2007-03-23 21:08:31 +01:00
|
|
|
t - pointer to MYSQL_TIME structure with local time
|
2004-06-18 08:11:31 +02:00
|
|
|
in broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
in_dst_time_gap - pointer to bool which is set to true if datetime
|
2004-06-18 08:11:31 +02:00
|
|
|
value passed doesn't really exist (i.e. falls into
|
|
|
|
spring time-gap) and is not touched otherwise.
|
|
|
|
|
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
Since Time_zone_utc is used only internally for my_time_t -> TIME
|
|
|
|
conversions, this function of Time_zone interface is not implemented for
|
2004-06-18 08:11:31 +02:00
|
|
|
this class and should not be called.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
my_time_t
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_utc::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
/* Should be never called */
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Converts time from UTC seconds since Epoch (my_time_t) representation
|
|
|
|
to broken-down representation (also in UTC).
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
gmt_sec_to_TIME()
|
2007-03-23 21:08:31 +01:00
|
|
|
tmp - pointer to MYSQL_TIME structure to fill-in
|
2004-06-23 23:41:56 +02:00
|
|
|
t - my_time_t value to be converted
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
NOTE
|
|
|
|
See note for apropriate Time_zone_system method.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
void
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_utc::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
struct tm tmp_tm;
|
|
|
|
time_t tmp_t= (time_t)t;
|
|
|
|
gmtime_r(&tmp_t, &tmp_tm);
|
|
|
|
localtime_to_TIME(tmp, &tmp_tm);
|
2004-06-24 17:08:36 +02:00
|
|
|
tmp->time_type= MYSQL_TIMESTAMP_DATETIME;
|
2008-12-01 15:18:35 +01:00
|
|
|
adjust_leap_second(tmp);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get name of time zone
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
get_name()
|
|
|
|
|
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
Since Time_zone_utc is used only internally by SQL's UTC_* functions it
|
|
|
|
is not accessible directly, and hence this function of Time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
interface is not implemented for this class and should not be called.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
0
|
|
|
|
*/
|
|
|
|
const String *
|
|
|
|
Time_zone_utc::get_name() const
|
|
|
|
{
|
|
|
|
/* Should be never called */
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Instance of this class represents some time zone which is
|
|
|
|
described in mysql.time_zone family of tables.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
class Time_zone_db : public Time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Time_zone_db(TIME_ZONE_INFO *tz_info_arg, const String * tz_name_arg);
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
|
2005-07-31 11:49:55 +02:00
|
|
|
my_bool *in_dst_time_gap) const;
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
|
2004-06-18 08:11:31 +02:00
|
|
|
virtual const String * get_name() const;
|
|
|
|
private:
|
|
|
|
TIME_ZONE_INFO *tz_info;
|
|
|
|
const String *tz_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Initializes object representing time zone described by mysql.time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
tables.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
Time_zone_db()
|
2004-06-23 23:41:56 +02:00
|
|
|
tz_info_arg - pointer to TIME_ZONE_INFO structure which is filled
|
|
|
|
according to db or other time zone description
|
2004-06-18 08:11:31 +02:00
|
|
|
(for example by my_tz_init()).
|
2004-06-23 23:41:56 +02:00
|
|
|
Several Time_zone_db instances can share one
|
2004-06-18 08:11:31 +02:00
|
|
|
TIME_ZONE_INFO structure.
|
|
|
|
tz_name_arg - name of time zone.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
Time_zone_db::Time_zone_db(TIME_ZONE_INFO *tz_info_arg,
|
2004-06-18 08:11:31 +02:00
|
|
|
const String *tz_name_arg):
|
|
|
|
tz_info(tz_info_arg), tz_name(tz_name_arg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Converts local time in time zone described from TIME
|
2004-06-18 08:11:31 +02:00
|
|
|
representation to its my_time_t representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
TIME_to_gmt_sec()
|
2007-03-23 21:08:31 +01:00
|
|
|
t - pointer to MYSQL_TIME structure with local time
|
2004-06-18 08:11:31 +02:00
|
|
|
in broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
in_dst_time_gap - pointer to bool which is set to true if datetime
|
2004-06-18 08:11:31 +02:00
|
|
|
value passed doesn't really exist (i.e. falls into
|
|
|
|
spring time-gap) and is not touched otherwise.
|
|
|
|
|
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
Please see ::TIME_to_gmt_sec for function description and
|
2004-06-18 08:11:31 +02:00
|
|
|
parameter restrictions.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Corresponding my_time_t value or 0 in case of error
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
my_time_t
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_db::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
return ::TIME_to_gmt_sec(t, tz_info, in_dst_time_gap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts time from UTC seconds since Epoch (my_time_t) representation
|
|
|
|
to local time zone described in broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
gmt_sec_to_TIME()
|
2007-03-23 21:08:31 +01:00
|
|
|
tmp - pointer to MYSQL_TIME structure to fill-in
|
2004-06-23 23:41:56 +02:00
|
|
|
t - my_time_t value to be converted
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
void
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_db::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
::gmt_sec_to_TIME(tmp, t, tz_info);
|
2008-12-01 15:18:35 +01:00
|
|
|
adjust_leap_second(tmp);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get name of time zone
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
get_name()
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Name of time zone as ASCIIZ-string
|
|
|
|
*/
|
|
|
|
const String *
|
|
|
|
Time_zone_db::get_name() const
|
|
|
|
{
|
|
|
|
return tz_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Instance of this class represents time zone which
|
2004-06-18 08:11:31 +02:00
|
|
|
was specified as offset from UTC.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
class Time_zone_offset : public Time_zone
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Time_zone_offset(long tz_offset_arg);
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual my_time_t TIME_to_gmt_sec(const MYSQL_TIME *t,
|
2005-07-31 11:49:55 +02:00
|
|
|
my_bool *in_dst_time_gap) const;
|
2007-03-23 21:08:31 +01:00
|
|
|
virtual void gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const;
|
2004-06-18 08:11:31 +02:00
|
|
|
virtual const String * get_name() const;
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
This have to be public because we want to be able to access it from
|
|
|
|
my_offset_tzs_get_key() function
|
|
|
|
*/
|
|
|
|
long offset;
|
|
|
|
private:
|
|
|
|
/* Extra reserve because of snprintf */
|
|
|
|
char name_buff[7+16];
|
|
|
|
String name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initializes object representing time zone described by its offset from UTC.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
Time_zone_offset()
|
2004-06-23 23:41:56 +02:00
|
|
|
tz_offset_arg - offset from UTC in seconds.
|
2004-06-18 08:11:31 +02:00
|
|
|
Positive for direction to east.
|
|
|
|
*/
|
|
|
|
Time_zone_offset::Time_zone_offset(long tz_offset_arg):
|
|
|
|
offset(tz_offset_arg)
|
|
|
|
{
|
2004-06-22 01:10:30 +02:00
|
|
|
uint hours= abs((int)(offset / SECS_PER_HOUR));
|
|
|
|
uint minutes= abs((int)(offset % SECS_PER_HOUR / SECS_PER_MIN));
|
2004-06-23 23:41:56 +02:00
|
|
|
ulong length= my_snprintf(name_buff, sizeof(name_buff), "%s%02d:%02d",
|
2004-06-18 08:11:31 +02:00
|
|
|
(offset>=0) ? "+" : "-", hours, minutes);
|
|
|
|
name.set(name_buff, length, &my_charset_latin1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts local time in time zone described as offset from UTC
|
2007-03-23 21:08:31 +01:00
|
|
|
from MYSQL_TIME representation to its my_time_t representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
TIME_to_gmt_sec()
|
2007-03-23 21:08:31 +01:00
|
|
|
t - pointer to MYSQL_TIME structure with local time
|
2004-06-18 08:11:31 +02:00
|
|
|
in broken-down representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
in_dst_time_gap - pointer to bool which should be set to true if
|
|
|
|
datetime value passed doesn't really exist
|
|
|
|
(i.e. falls into spring time-gap) and is not
|
2004-06-18 08:11:31 +02:00
|
|
|
touched otherwise.
|
|
|
|
It is not really used in this class.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Corresponding my_time_t value or 0 in case of error
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
my_time_t
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_offset::TIME_to_gmt_sec(const MYSQL_TIME *t, my_bool *in_dst_time_gap) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2006-11-01 14:47:40 +01:00
|
|
|
my_time_t local_t;
|
2007-02-23 17:33:11 +01:00
|
|
|
int shift= 0;
|
2006-11-01 14:47:40 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Check timestamp range.we have to do this as calling function relies on
|
|
|
|
us to make all validation checks here.
|
|
|
|
*/
|
|
|
|
if (!validate_timestamp_range(t))
|
|
|
|
return 0;
|
|
|
|
|
2007-02-23 17:33:11 +01:00
|
|
|
/*
|
|
|
|
Do a temporary shift of the boundary dates to avoid
|
|
|
|
overflow of my_time_t if the time value is near it's
|
|
|
|
maximum range
|
|
|
|
*/
|
|
|
|
if ((t->year == TIMESTAMP_MAX_YEAR) && (t->month == 1) && t->day > 4)
|
|
|
|
shift= 2;
|
|
|
|
|
|
|
|
local_t= sec_since_epoch(t->year, t->month, (t->day - shift),
|
2006-11-01 14:47:40 +01:00
|
|
|
t->hour, t->minute, t->second) -
|
|
|
|
offset;
|
|
|
|
|
2007-02-23 17:33:11 +01:00
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
/* Add back the shifted time */
|
|
|
|
local_t+= shift * SECS_PER_DAY;
|
|
|
|
}
|
|
|
|
|
2006-11-01 14:47:40 +01:00
|
|
|
if (local_t >= TIMESTAMP_MIN_VALUE && local_t <= TIMESTAMP_MAX_VALUE)
|
|
|
|
return local_t;
|
|
|
|
|
|
|
|
/* range error*/
|
|
|
|
return 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Converts time from UTC seconds since Epoch (my_time_t) representation
|
2004-06-23 23:41:56 +02:00
|
|
|
to local time zone described as offset from UTC and in broken-down
|
2004-06-18 08:11:31 +02:00
|
|
|
representation.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
gmt_sec_to_TIME()
|
2007-03-23 21:08:31 +01:00
|
|
|
tmp - pointer to MYSQL_TIME structure to fill-in
|
2004-06-23 23:41:56 +02:00
|
|
|
t - my_time_t value to be converted
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
void
|
2007-03-23 21:08:31 +01:00
|
|
|
Time_zone_offset::gmt_sec_to_TIME(MYSQL_TIME *tmp, my_time_t t) const
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sec_to_TIME(tmp, t, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get name of time zone
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
|
|
|
get_name()
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Name of time zone as pointer to String object
|
|
|
|
*/
|
|
|
|
const String *
|
|
|
|
Time_zone_offset::get_name() const
|
|
|
|
{
|
|
|
|
return &name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Time_zone_utc tz_UTC;
|
|
|
|
static Time_zone_system tz_SYSTEM;
|
2007-07-25 09:43:49 +02:00
|
|
|
static Time_zone_offset tz_OFFSET0(0);
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2007-07-25 09:43:49 +02:00
|
|
|
Time_zone *my_tz_OFFSET0= &tz_OFFSET0;
|
2004-06-18 08:11:31 +02:00
|
|
|
Time_zone *my_tz_UTC= &tz_UTC;
|
|
|
|
Time_zone *my_tz_SYSTEM= &tz_SYSTEM;
|
|
|
|
|
|
|
|
static HASH tz_names;
|
|
|
|
static HASH offset_tzs;
|
|
|
|
static MEM_ROOT tz_storage;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
These mutex protects offset_tzs and tz_storage.
|
2004-06-23 23:41:56 +02:00
|
|
|
These protection needed only when we are trying to set
|
|
|
|
time zone which is specified as offset, and searching for existing
|
2004-06-18 08:11:31 +02:00
|
|
|
time zone in offset_tzs or creating if it didn't existed before in
|
|
|
|
tz_storage. So contention is low.
|
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
static mysql_mutex_t tz_LOCK;
|
2004-06-23 15:39:56 +02:00
|
|
|
static bool tz_inited= 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This two static variables are inteded for holding info about leap seconds
|
|
|
|
shared by all time zones.
|
|
|
|
*/
|
|
|
|
static uint tz_leapcnt= 0;
|
|
|
|
static LS_INFO *tz_lsis= 0;
|
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
/*
|
|
|
|
Shows whenever we have found time zone tables during start-up.
|
|
|
|
Used for avoiding of putting those tables to global table list
|
|
|
|
for queries that use time zone info.
|
|
|
|
*/
|
|
|
|
static bool time_zone_tables_exist= 1;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2006-04-24 16:57:00 +02:00
|
|
|
/*
|
|
|
|
Names of tables (with their lengths) that are needed
|
|
|
|
for dynamical loading of time zone descriptions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const LEX_STRING tz_tables_names[MY_TZ_TABLES_COUNT]=
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2006-08-17 18:13:45 +02:00
|
|
|
{ C_STRING_WITH_LEN("time_zone_name")},
|
|
|
|
{ C_STRING_WITH_LEN("time_zone")},
|
|
|
|
{ C_STRING_WITH_LEN("time_zone_transition_type")},
|
|
|
|
{ C_STRING_WITH_LEN("time_zone_transition")}
|
2006-04-24 16:57:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Name of database to which those tables belong. */
|
|
|
|
|
2006-08-17 18:13:45 +02:00
|
|
|
static const LEX_STRING tz_tables_db_name= { C_STRING_WITH_LEN("mysql")};
|
2006-04-24 16:57:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Tz_names_entry: public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
2004-06-18 08:11:31 +02:00
|
|
|
String name;
|
|
|
|
Time_zone *tz;
|
2006-04-24 16:57:00 +02:00
|
|
|
};
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
We are going to call both of these functions from C code so
|
|
|
|
they should obey C calling conventions.
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern "C" uchar *
|
|
|
|
my_tz_names_get_key(Tz_names_entry *entry, size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
*length= entry->name.length();
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
return (uchar*) entry->name.ptr();
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern "C" uchar *
|
|
|
|
my_offset_tzs_get_key(Time_zone_offset *entry,
|
|
|
|
size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
*length= sizeof(long);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
return (uchar*) &entry->offset;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
/*
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
Prepare table list with time zone related tables from preallocated array.
|
2004-08-10 10:42:31 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
tz_init_table_list()
|
2006-04-24 16:57:00 +02:00
|
|
|
tz_tabs - pointer to preallocated array of MY_TZ_TABLES_COUNT
|
|
|
|
TABLE_LIST objects
|
2004-08-10 10:42:31 +02:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function prepares list of TABLE_LIST objects which can be used
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
for opening of time zone tables from preallocated array.
|
2004-08-10 10:42:31 +02:00
|
|
|
*/
|
|
|
|
|
2004-09-09 05:59:26 +02:00
|
|
|
static void
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
tz_init_table_list(TABLE_LIST *tz_tabs)
|
2004-08-10 10:42:31 +02:00
|
|
|
{
|
2006-04-24 16:57:00 +02:00
|
|
|
bzero(tz_tabs, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
|
|
|
|
|
|
|
|
for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
|
|
|
|
{
|
|
|
|
tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i].str;
|
|
|
|
tz_tabs[i].table_name_length= tz_tables_names[i].length;
|
|
|
|
tz_tabs[i].db= tz_tables_db_name.str;
|
|
|
|
tz_tabs[i].db_length= tz_tables_db_name.length;
|
|
|
|
tz_tabs[i].lock_type= TL_READ;
|
|
|
|
|
|
|
|
if (i != MY_TZ_TABLES_COUNT - 1)
|
|
|
|
tz_tabs[i].next_global= tz_tabs[i].next_local= &tz_tabs[i+1];
|
|
|
|
if (i != 0)
|
|
|
|
tz_tabs[i].prev_global= &tz_tabs[i-1].next_global;
|
|
|
|
}
|
2004-08-10 10:42:31 +02:00
|
|
|
}
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
static PSI_mutex_key key_tz_LOCK;
|
|
|
|
|
|
|
|
static PSI_mutex_info all_tz_mutexes[]=
|
|
|
|
{
|
|
|
|
{ & key_tz_LOCK, "tz_LOCK", PSI_FLAG_GLOBAL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void init_tz_psi_keys(void)
|
|
|
|
{
|
|
|
|
const char* category= "sql";
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (PSI_server == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count= array_elements(all_tz_mutexes);
|
|
|
|
PSI_server->register_mutex(category, all_tz_mutexes, count);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PSI_INTERFACE */
|
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Initialize time zone support infrastructure.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_tz_init()
|
|
|
|
thd - current thread object
|
|
|
|
default_tzname - default time zone or 0 if none.
|
|
|
|
bootstrap - indicates whenever we are in bootstrap mode
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
|
|
|
This function will init memory structures needed for time zone support,
|
|
|
|
it will register mandatory SYSTEM time zone in them. It will try to open
|
2004-08-10 10:42:31 +02:00
|
|
|
mysql.time_zone* tables and load information about default time zone and
|
|
|
|
information which further will be shared among all time zones loaded.
|
|
|
|
If system tables with time zone descriptions don't exist it won't fail
|
|
|
|
(unless default_tzname is time zone from tables). If bootstrap parameter
|
|
|
|
is true then this routine assumes that we are in bootstrap mode and won't
|
|
|
|
load time zone descriptions unless someone specifies default time zone
|
|
|
|
which is supposedly stored in those tables.
|
2004-06-18 08:11:31 +02:00
|
|
|
It'll also set default time zone if it is specified.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUES
|
|
|
|
0 - ok
|
2004-06-23 23:41:56 +02:00
|
|
|
1 - Error
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
my_bool
|
2004-06-18 08:11:31 +02:00
|
|
|
my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
|
|
|
|
{
|
|
|
|
THD *thd;
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
TABLE_LIST tz_tables[1+MY_TZ_TABLES_COUNT];
|
2004-06-18 08:11:31 +02:00
|
|
|
TABLE *table;
|
2006-04-24 16:57:00 +02:00
|
|
|
Tz_names_entry *tmp_tzname;
|
2004-06-18 08:11:31 +02:00
|
|
|
my_bool return_val= 1;
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
2006-06-26 22:47:52 +02:00
|
|
|
char db[]= "mysql";
|
2004-06-18 08:11:31 +02:00
|
|
|
int res;
|
|
|
|
DBUG_ENTER("my_tz_init");
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
init_tz_psi_keys();
|
|
|
|
#endif
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
To be able to run this from boot, we allocate a temporary THD
|
|
|
|
*/
|
|
|
|
if (!(thd= new THD))
|
|
|
|
DBUG_RETURN(1);
|
2005-11-23 19:18:10 +01:00
|
|
|
thd->thread_stack= (char*) &thd;
|
2004-06-18 08:11:31 +02:00
|
|
|
thd->store_globals();
|
|
|
|
|
|
|
|
/* Init all memory structures that require explicit destruction */
|
2009-10-14 18:37:38 +02:00
|
|
|
if (my_hash_init(&tz_names, &my_charset_latin1, 20,
|
|
|
|
0, 0, (my_hash_get_key) my_tz_names_get_key, 0, 0))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: OOM while initializing time zones");
|
|
|
|
goto end;
|
|
|
|
}
|
2009-10-14 18:37:38 +02:00
|
|
|
if (my_hash_init(&offset_tzs, &my_charset_latin1, 26, 0, 0,
|
|
|
|
(my_hash_get_key)my_offset_tzs_get_key, 0, 0))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: OOM while initializing time zones");
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_free(&tz_names);
|
2004-06-18 08:11:31 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2009-11-10 21:31:28 +01:00
|
|
|
init_sql_alloc(&tz_storage, 32 * 1024, 0);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_init(key_tz_LOCK, &tz_LOCK, MY_MUTEX_INIT_FAST);
|
2004-06-23 15:39:56 +02:00
|
|
|
tz_inited= 1;
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/* Add 'SYSTEM' time zone to tz_names hash */
|
2006-04-24 16:57:00 +02:00
|
|
|
if (!(tmp_tzname= new (&tz_storage) Tz_names_entry()))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: OOM while initializing time zones");
|
|
|
|
goto end_with_cleanup;
|
|
|
|
}
|
2005-11-20 19:47:07 +01:00
|
|
|
tmp_tzname->name.set(STRING_WITH_LEN("SYSTEM"), &my_charset_latin1);
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp_tzname->tz= my_tz_SYSTEM;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (my_hash_insert(&tz_names, (const uchar *)tmp_tzname))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: OOM while initializing time zones");
|
|
|
|
goto end_with_cleanup;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (bootstrap)
|
|
|
|
{
|
|
|
|
/* If we are in bootstrap mode we should not load time zone tables */
|
2004-08-10 10:42:31 +02:00
|
|
|
return_val= time_zone_tables_exist= 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
goto end_with_setting_default_tz;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
After this point all memory structures are inited and we even can live
|
|
|
|
without time zone description tables. Now try to load information about
|
|
|
|
leap seconds shared by all time zones.
|
|
|
|
*/
|
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
2006-06-26 22:47:52 +02:00
|
|
|
thd->set_db(db, sizeof(db)-1);
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
bzero((char*) &tz_tables[0], sizeof(TABLE_LIST));
|
|
|
|
tz_tables[0].alias= tz_tables[0].table_name=
|
2004-08-10 10:42:31 +02:00
|
|
|
(char*)"time_zone_leap_second";
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
tz_tables[0].table_name_length= 21;
|
|
|
|
tz_tables[0].db= db;
|
|
|
|
tz_tables[0].db_length= sizeof(db)-1;
|
|
|
|
tz_tables[0].lock_type= TL_READ;
|
|
|
|
|
|
|
|
tz_init_table_list(tz_tables+1);
|
|
|
|
tz_tables[0].next_global= tz_tables[0].next_local= &tz_tables[1];
|
|
|
|
tz_tables[1].prev_global= &tz_tables[0].next_global;
|
2009-12-08 10:57:07 +01:00
|
|
|
init_mdl_requests(tz_tables);
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
|
2004-09-17 10:30:26 +02:00
|
|
|
/*
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
We need to open only mysql.time_zone_leap_second, but we try to
|
|
|
|
open all time zone tables to see if they exist.
|
2004-09-17 10:30:26 +02:00
|
|
|
*/
|
2010-02-24 18:04:00 +01:00
|
|
|
if (open_and_lock_tables(thd, tz_tables, FALSE,
|
|
|
|
MYSQL_LOCK_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-08-30 08:37:36 +02:00
|
|
|
sql_print_warning("Can't open and lock time zone table: %s "
|
2009-09-10 11:18:29 +02:00
|
|
|
"trying to live without them", thd->stmt_da->message());
|
2004-06-18 08:11:31 +02:00
|
|
|
/* We will try emulate that everything is ok */
|
2004-08-10 10:42:31 +02:00
|
|
|
return_val= time_zone_tables_exist= 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
goto end_with_setting_default_tz;
|
|
|
|
}
|
|
|
|
|
2010-01-21 21:43:03 +01:00
|
|
|
for (TABLE_LIST *tl= tz_tables; tl; tl= tl->next_global)
|
|
|
|
tl->table->use_all_columns();
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Now we are going to load leap seconds descriptions that are shared
|
|
|
|
between all time zones that use them. We are using index for getting
|
|
|
|
records in proper order. Since we share the same MEM_ROOT between
|
|
|
|
all time zones we just allocate enough memory for it first.
|
|
|
|
*/
|
|
|
|
if (!(tz_lsis= (LS_INFO*) alloc_root(&tz_storage,
|
|
|
|
sizeof(LS_INFO) * TZ_MAX_LEAPS)))
|
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: Out of memory while loading "
|
|
|
|
"mysql.time_zone_leap_second table");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end_with_close;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
table= tz_tables[0].table;
|
2004-08-10 10:42:31 +02:00
|
|
|
/*
|
|
|
|
It is OK to ignore ha_index_init()/ha_index_end() return values since
|
|
|
|
mysql.time_zone* tables are MyISAM and these operations always succeed
|
|
|
|
for MyISAM.
|
|
|
|
*/
|
2005-07-18 13:31:02 +02:00
|
|
|
(void)table->file->ha_index_init(0, 1);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
table->use_all_columns();
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
tz_leapcnt= 0;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
res= table->file->index_first(table->record[0]);
|
|
|
|
|
|
|
|
while (!res)
|
|
|
|
{
|
|
|
|
if (tz_leapcnt + 1 > TZ_MAX_LEAPS)
|
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: While loading mysql.time_zone_leap_second"
|
|
|
|
" table: too much leaps");
|
2004-06-23 23:41:56 +02:00
|
|
|
table->file->ha_index_end();
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end_with_close;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
tz_lsis[tz_leapcnt].ls_trans= (my_time_t)table->field[0]->val_int();
|
|
|
|
tz_lsis[tz_leapcnt].ls_corr= (long)table->field[1]->val_int();
|
|
|
|
|
|
|
|
tz_leapcnt++;
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
2006-11-30 21:00:05 +01:00
|
|
|
("time_zone_leap_second table: tz_leapcnt: %u tt_time: %lu offset: %ld",
|
|
|
|
tz_leapcnt, (ulong) tz_lsis[tz_leapcnt-1].ls_trans,
|
|
|
|
tz_lsis[tz_leapcnt-1].ls_corr));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
res= table->file->index_next(table->record[0]);
|
|
|
|
}
|
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (res != HA_ERR_END_OF_FILE)
|
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: Error while loading "
|
|
|
|
"mysql.time_zone_leap_second table");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end_with_close;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Loading of info about leap seconds succeeded
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
return_val= 0;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
end_with_setting_default_tz:
|
2004-08-10 10:42:31 +02:00
|
|
|
/* If we have default time zone try to load it */
|
|
|
|
if (default_tzname)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2006-12-14 23:51:37 +01:00
|
|
|
String tmp_tzname2(default_tzname, &my_charset_latin1);
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
/*
|
|
|
|
Time zone tables may be open here, and my_tz_find() may open
|
|
|
|
most of them once more, but this is OK for system tables open
|
|
|
|
for READ.
|
|
|
|
*/
|
|
|
|
if (!(global_system_variables.time_zone= my_tz_find(thd, &tmp_tzname2)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Fatal error: Illegal or unknown default time zone '%s'",
|
|
|
|
default_tzname);
|
|
|
|
return_val= 1;
|
|
|
|
}
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
end_with_close:
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
if (time_zone_tables_exist)
|
|
|
|
{
|
|
|
|
thd->version--; /* Force close to free memory */
|
2010-01-21 21:43:03 +01:00
|
|
|
close_thread_tables(thd);
|
|
|
|
thd->mdl_context.release_transactional_locks();
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
}
|
2004-08-10 10:42:31 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
end_with_cleanup:
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* if there were error free time zone describing structs */
|
|
|
|
if (return_val)
|
|
|
|
my_tz_free();
|
|
|
|
end:
|
|
|
|
delete thd;
|
|
|
|
if (org_thd)
|
|
|
|
org_thd->store_globals(); /* purecov: inspected */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remember that we don't have a THD */
|
|
|
|
my_pthread_setspecific_ptr(THR_THD, 0);
|
|
|
|
my_pthread_setspecific_ptr(THR_MALLOC, 0);
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
default_tz= default_tz_name ? global_system_variables.time_zone
|
|
|
|
: my_tz_SYSTEM;
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DBUG_RETURN(return_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Free resources used by time zone support infrastructure.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_tz_free()
|
|
|
|
*/
|
2004-06-23 15:39:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
void my_tz_free()
|
|
|
|
{
|
2004-06-23 15:39:56 +02:00
|
|
|
if (tz_inited)
|
|
|
|
{
|
|
|
|
tz_inited= 0;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_destroy(&tz_LOCK);
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_free(&offset_tzs);
|
|
|
|
my_hash_free(&tz_names);
|
2004-06-23 15:39:56 +02:00
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
}
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Load time zone description from system tables.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2004-08-10 10:42:31 +02:00
|
|
|
tz_load_from_open_tables()
|
|
|
|
tz_name - name of time zone that should be loaded.
|
|
|
|
tz_tables - list of tables from which time zone description
|
|
|
|
should be loaded
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2004-08-10 10:42:31 +02:00
|
|
|
This function will try to load information about time zone specified
|
|
|
|
from the list of the already opened and locked tables (first table in
|
|
|
|
tz_tables should be time_zone_name, next time_zone, then
|
|
|
|
time_zone_transition_type and time_zone_transition should be last).
|
|
|
|
It will also update information in hash used for time zones lookup.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUES
|
|
|
|
Returns pointer to newly created Time_zone object or 0 in case of error.
|
|
|
|
|
|
|
|
*/
|
2004-08-10 10:42:31 +02:00
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
static Time_zone*
|
2004-08-10 10:42:31 +02:00
|
|
|
tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
TABLE *table= 0;
|
|
|
|
TIME_ZONE_INFO *tz_info;
|
2006-04-24 16:57:00 +02:00
|
|
|
Tz_names_entry *tmp_tzname;
|
2004-06-18 08:11:31 +02:00
|
|
|
Time_zone *return_val= 0;
|
|
|
|
int res;
|
|
|
|
uint tzid, ttid;
|
|
|
|
my_time_t ttime;
|
|
|
|
char buff[MAX_FIELD_WIDTH];
|
|
|
|
String abbr(buff, sizeof(buff), &my_charset_latin1);
|
|
|
|
char *alloc_buff, *tz_name_buff;
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Temporary arrays that are used for loading of data for filling
|
|
|
|
TIME_ZONE_INFO structure
|
|
|
|
*/
|
|
|
|
my_time_t ats[TZ_MAX_TIMES];
|
2006-06-19 11:45:34 +02:00
|
|
|
uchar types[TZ_MAX_TIMES];
|
2004-06-18 08:11:31 +02:00
|
|
|
TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
|
|
|
|
#endif
|
2009-03-19 11:27:45 +01:00
|
|
|
/*
|
|
|
|
Used as a temporary tz_info until we decide that we actually want to
|
|
|
|
allocate and keep the tz info and tz name in tz_storage.
|
|
|
|
*/
|
|
|
|
TIME_ZONE_INFO tmp_tz_info;
|
|
|
|
memset(&tmp_tz_info, 0, sizeof(TIME_ZONE_INFO));
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
DBUG_ENTER("tz_load_from_open_tables");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* Prepare tz_info for loading also let us make copy of time zone name */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(alloc_buff= (char*) alloc_root(&tz_storage, sizeof(TIME_ZONE_INFO) +
|
|
|
|
tz_name->length() + 1)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-08-30 08:37:36 +02:00
|
|
|
sql_print_error("Out of memory while loading time zone description");
|
2004-06-18 08:11:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tz_info= (TIME_ZONE_INFO *)alloc_buff;
|
|
|
|
bzero(tz_info, sizeof(TIME_ZONE_INFO));
|
|
|
|
tz_name_buff= alloc_buff + sizeof(TIME_ZONE_INFO);
|
|
|
|
/*
|
|
|
|
By writing zero to the end we guarantee that we can call ptr()
|
|
|
|
instead of c_ptr() for time zone name.
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
strmake(tz_name_buff, tz_name->ptr(), tz_name->length());
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
Let us find out time zone id by its name (there is only one index
|
2004-06-18 08:11:31 +02:00
|
|
|
and it is specifically for this purpose).
|
|
|
|
*/
|
2004-08-30 08:37:36 +02:00
|
|
|
table= tz_tables->table;
|
2004-09-09 05:59:26 +02:00
|
|
|
tz_tables= tz_tables->next_local;
|
|
|
|
table->field[0]->store(tz_name->ptr(), tz_name->length(),
|
|
|
|
&my_charset_latin1);
|
2004-08-10 10:42:31 +02:00
|
|
|
/*
|
|
|
|
It is OK to ignore ha_index_init()/ha_index_end() return values since
|
|
|
|
mysql.time_zone* tables are MyISAM and these operations always succeed
|
|
|
|
for MyISAM.
|
|
|
|
*/
|
2005-07-18 13:31:02 +02:00
|
|
|
(void)table->file->ha_index_init(0, 1);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
if (table->file->index_read_map(table->record[0], table->field[0]->ptr,
|
|
|
|
HA_WHOLE_KEY, HA_READ_KEY_EXACT))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2007-01-29 10:40:26 +01:00
|
|
|
#ifdef EXTRA_DEBUG
|
2005-01-26 20:25:02 +01:00
|
|
|
/*
|
|
|
|
Most probably user has mistyped time zone name, so no need to bark here
|
|
|
|
unless we need it for debugging.
|
|
|
|
*/
|
2009-03-19 11:27:45 +01:00
|
|
|
sql_print_error("Can't find description of time zone '%.*s'",
|
|
|
|
tz_name->length(), tz_name->ptr());
|
2004-09-09 05:59:26 +02:00
|
|
|
#endif
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-23 23:08:07 +02:00
|
|
|
tzid= (uint)table->field[1]->val_int();
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Now we need to lookup record in mysql.time_zone table in order to
|
|
|
|
understand whenever this timezone uses leap seconds (again we are
|
|
|
|
using the only index in this table).
|
|
|
|
*/
|
2004-08-30 08:37:36 +02:00
|
|
|
table= tz_tables->table;
|
2004-09-09 05:59:26 +02:00
|
|
|
tz_tables= tz_tables->next_local;
|
2005-09-14 00:41:44 +02:00
|
|
|
table->field[0]->store((longlong) tzid, TRUE);
|
2005-07-18 13:31:02 +02:00
|
|
|
(void)table->file->ha_index_init(0, 1);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
if (table->file->index_read_map(table->record[0], table->field[0]->ptr,
|
|
|
|
HA_WHOLE_KEY, HA_READ_KEY_EXACT))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-12-31 02:47:56 +01:00
|
|
|
sql_print_error("Can't find description of time zone '%u'", tzid);
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* If Uses_leap_seconds == 'Y' */
|
|
|
|
if (table->field[1]->val_int() == 1)
|
|
|
|
{
|
2009-03-19 11:27:45 +01:00
|
|
|
tmp_tz_info.leapcnt= tz_leapcnt;
|
|
|
|
tmp_tz_info.lsis= tz_lsis;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Now we will iterate through records for out time zone in
|
|
|
|
mysql.time_zone_transition_type table. Because we want records
|
|
|
|
only for our time zone guess what are we doing?
|
2004-06-18 08:11:31 +02:00
|
|
|
Right - using special index.
|
|
|
|
*/
|
2004-08-30 08:37:36 +02:00
|
|
|
table= tz_tables->table;
|
2004-09-09 05:59:26 +02:00
|
|
|
tz_tables= tz_tables->next_local;
|
2005-09-14 00:41:44 +02:00
|
|
|
table->field[0]->store((longlong) tzid, TRUE);
|
2005-07-18 13:31:02 +02:00
|
|
|
(void)table->file->ha_index_init(0, 1);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
res= table->file->index_read_map(table->record[0], table->field[0]->ptr,
|
|
|
|
(key_part_map)1, HA_READ_KEY_EXACT);
|
2004-06-18 08:11:31 +02:00
|
|
|
while (!res)
|
|
|
|
{
|
2004-06-23 23:08:07 +02:00
|
|
|
ttid= (uint)table->field[1]->val_int();
|
2004-06-18 08:11:31 +02:00
|
|
|
|
2005-01-24 15:48:25 +01:00
|
|
|
if (ttid >= TZ_MAX_TYPES)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition_type table: too big "
|
|
|
|
"transition type id");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
2004-06-23 23:08:07 +02:00
|
|
|
ttis[ttid].tt_gmtoff= (long)table->field[2]->val_int();
|
2004-06-18 08:11:31 +02:00
|
|
|
ttis[ttid].tt_isdst= (table->field[3]->val_int() > 0);
|
|
|
|
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
// FIXME should we do something with duplicates here ?
|
|
|
|
table->field[4]->val_str(&abbr, &abbr);
|
2009-03-19 11:27:45 +01:00
|
|
|
if (tmp_tz_info.charcnt + abbr.length() + 1 > sizeof(chars))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition_type table: not enough "
|
|
|
|
"room for abbreviations");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2009-03-19 11:27:45 +01:00
|
|
|
ttis[ttid].tt_abbrind= tmp_tz_info.charcnt;
|
|
|
|
memcpy(chars + tmp_tz_info.charcnt, abbr.ptr(), abbr.length());
|
|
|
|
tmp_tz_info.charcnt+= abbr.length();
|
|
|
|
chars[tmp_tz_info.charcnt]= 0;
|
|
|
|
tmp_tz_info.charcnt++;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DBUG_PRINT("info",
|
|
|
|
("time_zone_transition_type table: tz_id=%u tt_id=%u tt_gmtoff=%ld "
|
2004-06-23 23:41:56 +02:00
|
|
|
"abbr='%s' tt_isdst=%u", tzid, ttid, ttis[ttid].tt_gmtoff,
|
2004-06-18 08:11:31 +02:00
|
|
|
chars + ttis[ttid].tt_abbrind, ttis[ttid].tt_isdst));
|
|
|
|
#else
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("time_zone_transition_type table: tz_id=%u tt_id=%u tt_gmtoff=%ld "
|
|
|
|
"tt_isdst=%u", tzid, ttid, ttis[ttid].tt_gmtoff, ttis[ttid].tt_isdst));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ttid is increasing because we are reading using index */
|
2009-03-19 11:27:45 +01:00
|
|
|
DBUG_ASSERT(ttid >= tmp_tz_info.typecnt);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2009-03-19 11:27:45 +01:00
|
|
|
tmp_tz_info.typecnt= ttid + 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
res= table->file->index_next_same(table->record[0],
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
table->field[0]->ptr, 4);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (res != HA_ERR_END_OF_FILE)
|
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition_type table");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
At last we are doing the same thing for records in
|
|
|
|
mysql.time_zone_transition table. Here we additionaly need records
|
2004-06-18 08:11:31 +02:00
|
|
|
in ascending order by index scan also satisfies us.
|
|
|
|
*/
|
2004-08-10 10:42:31 +02:00
|
|
|
table= tz_tables->table;
|
2005-09-14 00:41:44 +02:00
|
|
|
table->field[0]->store((longlong) tzid, TRUE);
|
2005-07-18 13:31:02 +02:00
|
|
|
(void)table->file->ha_index_init(0, 1);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
res= table->file->index_read_map(table->record[0], table->field[0]->ptr,
|
|
|
|
(key_part_map)1, HA_READ_KEY_EXACT);
|
2004-06-18 08:11:31 +02:00
|
|
|
while (!res)
|
|
|
|
{
|
|
|
|
ttime= (my_time_t)table->field[1]->val_int();
|
|
|
|
ttid= (uint)table->field[2]->val_int();
|
|
|
|
|
2009-03-19 11:27:45 +01:00
|
|
|
if (tmp_tz_info.timecnt + 1 > TZ_MAX_TIMES)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition table: "
|
|
|
|
"too much transitions");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2009-03-19 11:27:45 +01:00
|
|
|
if (ttid + 1 > tmp_tz_info.typecnt)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition table: "
|
|
|
|
"bad transition type id");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2009-03-19 11:27:45 +01:00
|
|
|
ats[tmp_tz_info.timecnt]= ttime;
|
|
|
|
types[tmp_tz_info.timecnt]= ttid;
|
|
|
|
tmp_tz_info.timecnt++;
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
2006-11-30 21:38:12 +01:00
|
|
|
("time_zone_transition table: tz_id: %u tt_time: %lu tt_id: %u",
|
2006-11-27 17:16:08 +01:00
|
|
|
tzid, (ulong) ttime, ttid));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
res= table->file->index_next_same(table->record[0],
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
table->field[0]->ptr, 4);
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
We have to allow HA_ERR_KEY_NOT_FOUND because some time zones
|
|
|
|
for example UTC have no transitons.
|
|
|
|
*/
|
|
|
|
if (res != HA_ERR_END_OF_FILE && res != HA_ERR_KEY_NOT_FOUND)
|
|
|
|
{
|
|
|
|
sql_print_error("Error while loading time zone description from "
|
|
|
|
"mysql.time_zone_transition table");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-18 08:11:31 +02:00
|
|
|
table= 0;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2009-03-19 11:27:45 +01:00
|
|
|
/*
|
|
|
|
Let us check how correct our time zone description is. We don't check for
|
|
|
|
tz->timecnt < 1 since it is ok for GMT.
|
|
|
|
*/
|
|
|
|
if (tmp_tz_info.typecnt < 1)
|
|
|
|
{
|
|
|
|
sql_print_error("loading time zone without transition types");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for the timezone info and timezone name in tz_storage. */
|
|
|
|
if (!(alloc_buff= (char*) alloc_root(&tz_storage, sizeof(TIME_ZONE_INFO) +
|
|
|
|
tz_name->length() + 1)))
|
|
|
|
{
|
|
|
|
sql_print_error("Out of memory while loading time zone description");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move the temporary tz_info into the allocated area */
|
|
|
|
tz_info= (TIME_ZONE_INFO *)alloc_buff;
|
|
|
|
memcpy(tz_info, &tmp_tz_info, sizeof(TIME_ZONE_INFO));
|
|
|
|
tz_name_buff= alloc_buff + sizeof(TIME_ZONE_INFO);
|
|
|
|
/*
|
|
|
|
By writing zero to the end we guarantee that we can call ptr()
|
|
|
|
instead of c_ptr() for time zone name.
|
|
|
|
*/
|
|
|
|
strmake(tz_name_buff, tz_name->ptr(), tz_name->length());
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Now we will allocate memory and init TIME_ZONE_INFO structure.
|
|
|
|
*/
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(alloc_buff= (char*) alloc_root(&tz_storage,
|
|
|
|
ALIGN_SIZE(sizeof(my_time_t) *
|
|
|
|
tz_info->timecnt) +
|
|
|
|
ALIGN_SIZE(tz_info->timecnt) +
|
2004-06-18 08:11:31 +02:00
|
|
|
#ifdef ABBR_ARE_USED
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
ALIGN_SIZE(tz_info->charcnt) +
|
2004-06-18 08:11:31 +02:00
|
|
|
#endif
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
sizeof(TRAN_TYPE_INFO) *
|
|
|
|
tz_info->typecnt)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-08-30 08:37:36 +02:00
|
|
|
sql_print_error("Out of memory while loading time zone description");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
tz_info->ats= (my_time_t *) alloc_buff;
|
2004-06-18 08:11:31 +02:00
|
|
|
memcpy(tz_info->ats, ats, tz_info->timecnt * sizeof(my_time_t));
|
|
|
|
alloc_buff+= ALIGN_SIZE(sizeof(my_time_t) * tz_info->timecnt);
|
2006-06-19 11:45:34 +02:00
|
|
|
tz_info->types= (uchar *)alloc_buff;
|
2004-06-18 08:11:31 +02:00
|
|
|
memcpy(tz_info->types, types, tz_info->timecnt);
|
|
|
|
alloc_buff+= ALIGN_SIZE(tz_info->timecnt);
|
|
|
|
#ifdef ABBR_ARE_USED
|
|
|
|
tz_info->chars= alloc_buff;
|
|
|
|
memcpy(tz_info->chars, chars, tz_info->charcnt);
|
|
|
|
alloc_buff+= ALIGN_SIZE(tz_info->charcnt);
|
|
|
|
#endif
|
|
|
|
tz_info->ttis= (TRAN_TYPE_INFO *)alloc_buff;
|
|
|
|
memcpy(tz_info->ttis, ttis, tz_info->typecnt * sizeof(TRAN_TYPE_INFO));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2009-03-19 11:27:45 +01:00
|
|
|
/* Build reversed map. */
|
2004-06-18 08:11:31 +02:00
|
|
|
if (prepare_tz_info(tz_info, &tz_storage))
|
|
|
|
{
|
2004-08-30 08:37:36 +02:00
|
|
|
sql_print_error("Unable to build mktime map for time zone");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
|
|
|
|
2006-04-24 16:57:00 +02:00
|
|
|
if (!(tmp_tzname= new (&tz_storage) Tz_names_entry()) ||
|
2004-06-23 23:41:56 +02:00
|
|
|
!(tmp_tzname->tz= new (&tz_storage) Time_zone_db(tz_info,
|
2004-06-18 08:11:31 +02:00
|
|
|
&(tmp_tzname->name))) ||
|
2004-06-23 23:41:56 +02:00
|
|
|
(tmp_tzname->name.set(tz_name_buff, tz_name->length(),
|
2004-06-18 08:11:31 +02:00
|
|
|
&my_charset_latin1),
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_hash_insert(&tz_names, (const uchar *)tmp_tzname)))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-08-30 08:37:36 +02:00
|
|
|
sql_print_error("Out of memory while loading time zone");
|
2004-08-10 10:42:31 +02:00
|
|
|
goto end;
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Loading of time zone succeeded
|
|
|
|
*/
|
|
|
|
return_val= tmp_tzname->tz;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-08-10 10:42:31 +02:00
|
|
|
end:
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
if (table)
|
2004-08-10 10:42:31 +02:00
|
|
|
(void)table->file->ha_index_end();
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(return_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Parse string that specifies time zone as offset from UTC.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
str_to_offset()
|
2004-06-23 23:41:56 +02:00
|
|
|
str - pointer to string which contains offset
|
2004-06-18 08:11:31 +02:00
|
|
|
length - length of string
|
|
|
|
offset - out parameter for storing found offset in seconds.
|
|
|
|
|
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
This function parses string which contains time zone offset
|
|
|
|
in form similar to '+10:00' and converts found value to
|
2004-06-18 08:11:31 +02:00
|
|
|
seconds from UTC form (east is positive).
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
0 - Ok
|
|
|
|
1 - String doesn't contain valid time zone offset
|
|
|
|
*/
|
|
|
|
my_bool
|
|
|
|
str_to_offset(const char *str, uint length, long *offset)
|
|
|
|
{
|
|
|
|
const char *end= str + length;
|
|
|
|
my_bool negative;
|
|
|
|
ulong number_tmp;
|
|
|
|
long offset_tmp;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (length < 4)
|
|
|
|
return 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (*str == '+')
|
|
|
|
negative= 0;
|
|
|
|
else if (*str == '-')
|
|
|
|
negative= 1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
str++;
|
|
|
|
|
|
|
|
number_tmp= 0;
|
|
|
|
|
|
|
|
while (str < end && my_isdigit(&my_charset_latin1, *str))
|
|
|
|
{
|
|
|
|
number_tmp= number_tmp*10 + *str - '0';
|
|
|
|
str++;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (str + 1 >= end || *str != ':')
|
|
|
|
return 1;
|
|
|
|
str++;
|
|
|
|
|
|
|
|
offset_tmp = number_tmp * MINS_PER_HOUR; number_tmp= 0;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
while (str < end && my_isdigit(&my_charset_latin1, *str))
|
|
|
|
{
|
|
|
|
number_tmp= number_tmp * 10 + *str - '0';
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str != end)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
offset_tmp= (offset_tmp + number_tmp) * SECS_PER_MIN;
|
|
|
|
|
|
|
|
if (negative)
|
|
|
|
offset_tmp= -offset_tmp;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
Check if offset is in range prescribed by standard
|
|
|
|
(from -12:59 to 13:00).
|
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (number_tmp > 59 || offset_tmp < -13 * SECS_PER_HOUR + 1 ||
|
|
|
|
offset_tmp > 13 * SECS_PER_HOUR)
|
|
|
|
return 1;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
*offset= offset_tmp;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get Time_zone object for specified time zone.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
my_tz_find()
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
thd - pointer to thread THD structure
|
2004-06-18 08:11:31 +02:00
|
|
|
name - time zone specification
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function checks if name is one of time zones described in db,
|
2004-06-23 23:41:56 +02:00
|
|
|
predefined SYSTEM time zone or valid time zone specification as
|
2004-06-18 08:11:31 +02:00
|
|
|
offset from UTC (In last case it will create proper Time_zone_offset
|
|
|
|
object if there were not any.). If name is ok it returns corresponding
|
|
|
|
Time_zone object.
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
Clients of this function are not responsible for releasing resources
|
|
|
|
occupied by returned Time_zone object so they can just forget pointers
|
2004-06-18 08:11:31 +02:00
|
|
|
to Time_zone object if they are not needed longer.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
Other important property of this function: if some Time_zone found once
|
|
|
|
it will be for sure found later, so this function can also be used for
|
|
|
|
checking if proper Time_zone object exists (and if there will be error
|
|
|
|
it will be reported during first call).
|
|
|
|
|
|
|
|
If name pointer is 0 then this function returns 0 (this allows to pass 0
|
2004-06-23 23:41:56 +02:00
|
|
|
values as parameter without additional external check and this property
|
2004-06-18 08:11:31 +02:00
|
|
|
is used by @@time_zone variable handling code).
|
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
It will perform lookup in system tables (mysql.time_zone*),
|
|
|
|
opening and locking them, and closing afterwards. It won't perform
|
|
|
|
such lookup if no time zone describing tables were found during
|
|
|
|
server start up.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
2004-06-23 23:41:56 +02:00
|
|
|
Pointer to corresponding Time_zone object. 0 - in case of bad time zone
|
2004-06-18 08:11:31 +02:00
|
|
|
specification or other error.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
2004-06-23 23:41:56 +02:00
|
|
|
Time_zone *
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
my_tz_find(THD *thd, const String *name)
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2006-04-24 16:57:00 +02:00
|
|
|
Tz_names_entry *tmp_tzname;
|
2004-06-18 08:11:31 +02:00
|
|
|
Time_zone *result_tz= 0;
|
|
|
|
long offset;
|
|
|
|
DBUG_ENTER("my_tz_find");
|
2004-06-23 23:41:56 +02:00
|
|
|
DBUG_PRINT("enter", ("time zone name='%s'",
|
2006-03-29 13:27:36 +02:00
|
|
|
name ? ((String *)name)->c_ptr_safe() : "NULL"));
|
2004-08-10 10:42:31 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!name)
|
|
|
|
DBUG_RETURN(0);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&tz_LOCK);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!str_to_offset(name->ptr(), name->length(), &offset))
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2009-10-14 18:37:38 +02:00
|
|
|
if (!(result_tz= (Time_zone_offset *)my_hash_search(&offset_tzs,
|
|
|
|
(const uchar *)&offset,
|
|
|
|
sizeof(long))))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Creating new Time_zone_offset object"));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!(result_tz= new (&tz_storage) Time_zone_offset(offset)) ||
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_hash_insert(&offset_tzs, (const uchar *) result_tz))
|
2004-06-18 08:11:31 +02:00
|
|
|
{
|
2004-08-26 17:26:38 +02:00
|
|
|
result_tz= 0;
|
2004-06-18 08:11:31 +02:00
|
|
|
sql_print_error("Fatal error: Out of memory "
|
|
|
|
"while setting new time zone");
|
|
|
|
}
|
|
|
|
}
|
2004-08-26 17:26:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result_tz= 0;
|
2009-10-14 18:37:38 +02:00
|
|
|
if ((tmp_tzname= (Tz_names_entry *)my_hash_search(&tz_names,
|
|
|
|
(const uchar *)
|
|
|
|
name->ptr(),
|
|
|
|
name->length())))
|
2004-06-18 08:11:31 +02:00
|
|
|
result_tz= tmp_tzname->tz;
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
else if (time_zone_tables_exist)
|
|
|
|
{
|
|
|
|
TABLE_LIST tz_tables[MY_TZ_TABLES_COUNT];
|
2010-01-21 21:43:03 +01:00
|
|
|
Open_tables_backup open_tables_state_backup;
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
|
|
|
|
tz_init_table_list(tz_tables);
|
2009-12-08 10:57:07 +01:00
|
|
|
init_mdl_requests(tz_tables);
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
if (!open_system_tables_for_read(thd, tz_tables,
|
|
|
|
&open_tables_state_backup))
|
|
|
|
{
|
|
|
|
result_tz= tz_load_from_open_tables(name, tz_tables);
|
|
|
|
close_system_tables(thd, &open_tables_state_backup);
|
|
|
|
}
|
|
|
|
}
|
2004-06-18 08:11:31 +02:00
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&tz_LOCK);
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(result_tz);
|
|
|
|
}
|
|
|
|
|
2005-03-22 00:26:12 +01:00
|
|
|
|
2008-12-01 15:18:35 +01:00
|
|
|
/**
|
|
|
|
Convert leap seconds into non-leap
|
|
|
|
|
|
|
|
This function will convert the leap seconds added by the OS to
|
|
|
|
non-leap seconds, e.g. 23:59:59, 23:59:60 -> 23:59:59, 00:00:01 ...
|
|
|
|
This check is not checking for years on purpose : although it's not a
|
|
|
|
complete check this way it doesn't require looking (and having installed)
|
|
|
|
the leap seconds table.
|
|
|
|
|
|
|
|
@param[in,out] broken down time structure as filled in by the OS
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Time_zone::adjust_leap_second(MYSQL_TIME *t)
|
|
|
|
{
|
|
|
|
if (t->second == 60 || t->second == 61)
|
|
|
|
t->second= 59;
|
|
|
|
}
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
#endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TZINFO2SQL
|
|
|
|
/*
|
|
|
|
This code belongs to mysql_tzinfo_to_sql converter command line utility.
|
|
|
|
This utility should be used by db admin for populating mysql.time_zone
|
|
|
|
tables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Print info about time zone described by TIME_ZONE_INFO struct as
|
2004-06-18 08:11:31 +02:00
|
|
|
SQL statements populating mysql.time_zone* tables.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
print_tz_as_sql()
|
|
|
|
tz_name - name of time zone
|
2004-06-23 23:41:56 +02:00
|
|
|
sp - structure describing time zone
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_tz_as_sql(const char* tz_name, const TIME_ZONE_INFO *sp)
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
/* Here we assume that all time zones have same leap correction tables */
|
2004-06-23 23:41:56 +02:00
|
|
|
printf("INSERT INTO time_zone (Use_leap_seconds) VALUES ('%s');\n",
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->leapcnt ? "Y" : "N");
|
|
|
|
printf("SET @time_zone_id= LAST_INSERT_ID();\n");
|
|
|
|
printf("INSERT INTO time_zone_name (Name, Time_zone_id) VALUES \
|
|
|
|
('%s', @time_zone_id);\n", tz_name);
|
|
|
|
|
|
|
|
if (sp->timecnt)
|
|
|
|
{
|
|
|
|
printf("INSERT INTO time_zone_transition \
|
|
|
|
(Time_zone_id, Transition_time, Transition_type_id) VALUES\n");
|
|
|
|
for (i= 0; i < sp->timecnt; i++)
|
|
|
|
printf("%s(@time_zone_id, %ld, %u)\n", (i == 0 ? " " : ","), sp->ats[i],
|
|
|
|
(uint)sp->types[i]);
|
|
|
|
printf(";\n");
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("INSERT INTO time_zone_transition_type \
|
|
|
|
(Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES\n");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
for (i= 0; i < sp->typecnt; i++)
|
|
|
|
printf("%s(@time_zone_id, %u, %ld, %d, '%s')\n", (i == 0 ? " " : ","), i,
|
2004-06-23 23:41:56 +02:00
|
|
|
sp->ttis[i].tt_gmtoff, sp->ttis[i].tt_isdst,
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->chars + sp->ttis[i].tt_abbrind);
|
|
|
|
printf(";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Print info about leap seconds in time zone as SQL statements
|
|
|
|
populating mysql.time_zone_leap_second table.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
print_tz_leaps_as_sql()
|
2004-06-23 23:41:56 +02:00
|
|
|
sp - structure describing time zone
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_tz_leaps_as_sql(const TIME_ZONE_INFO *sp)
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
|
|
|
We are assuming that there are only one list of leap seconds
|
2004-06-18 08:11:31 +02:00
|
|
|
For all timezones.
|
|
|
|
*/
|
|
|
|
printf("TRUNCATE TABLE time_zone_leap_second;\n");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (sp->leapcnt)
|
|
|
|
{
|
|
|
|
printf("INSERT INTO time_zone_leap_second \
|
|
|
|
(Transition_time, Correction) VALUES\n");
|
|
|
|
for (i= 0; i < sp->leapcnt; i++)
|
2004-06-23 23:41:56 +02:00
|
|
|
printf("%s(%ld, %ld)\n", (i == 0 ? " " : ","),
|
2004-06-18 08:11:31 +02:00
|
|
|
sp->lsis[i].ls_trans, sp->lsis[i].ls_corr);
|
|
|
|
printf(";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("ALTER TABLE time_zone_leap_second ORDER BY Transition_time;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-06-23 23:41:56 +02:00
|
|
|
Some variables used as temporary or as parameters
|
2004-06-18 08:11:31 +02:00
|
|
|
in recursive scan_tz_dir() code.
|
|
|
|
*/
|
|
|
|
TIME_ZONE_INFO tz_info;
|
|
|
|
MEM_ROOT tz_storage;
|
|
|
|
char fullname[FN_REFLEN + 1];
|
|
|
|
char *root_name_end;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Recursively scan zoneinfo directory and print all found time zone
|
|
|
|
descriptions as SQL.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
SYNOPSIS
|
2004-06-23 23:41:56 +02:00
|
|
|
scan_tz_dir()
|
2004-06-18 08:11:31 +02:00
|
|
|
name_end - pointer to end of path to directory to be searched.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
DESCRIPTION
|
2004-06-23 23:41:56 +02:00
|
|
|
This auxiliary recursive function also uses several global
|
2004-06-18 08:11:31 +02:00
|
|
|
variables as in parameters and for storing temporary values.
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
fullname - path to directory that should be scanned.
|
2004-06-23 23:41:56 +02:00
|
|
|
root_name_end - pointer to place in fullname where part with
|
2004-06-18 08:11:31 +02:00
|
|
|
path to initial directory ends.
|
|
|
|
current_tz_id - last used time zone id
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
RETURN VALUE
|
|
|
|
0 - Ok, 1 - Fatal error
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
*/
|
|
|
|
my_bool
|
|
|
|
scan_tz_dir(char * name_end)
|
|
|
|
{
|
|
|
|
MY_DIR *cur_dir;
|
|
|
|
char *name_end_tmp;
|
|
|
|
uint i;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!(cur_dir= my_dir(fullname, MYF(MY_WANT_STAT))))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
name_end= strmake(name_end, "/", FN_REFLEN - (name_end - fullname));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
for (i= 0; i < cur_dir->number_off_files; i++)
|
|
|
|
{
|
|
|
|
if (cur_dir->dir_entry[i].name[0] != '.')
|
|
|
|
{
|
|
|
|
name_end_tmp= strmake(name_end, cur_dir->dir_entry[i].name,
|
|
|
|
FN_REFLEN - (name_end - fullname));
|
|
|
|
|
|
|
|
if (MY_S_ISDIR(cur_dir->dir_entry[i].mystat->st_mode))
|
|
|
|
{
|
|
|
|
if (scan_tz_dir(name_end_tmp))
|
|
|
|
{
|
|
|
|
my_dirend(cur_dir);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MY_S_ISREG(cur_dir->dir_entry[i].mystat->st_mode))
|
|
|
|
{
|
|
|
|
init_alloc_root(&tz_storage, 32768, 0);
|
|
|
|
if (!tz_load(fullname, &tz_info, &tz_storage))
|
|
|
|
print_tz_as_sql(root_name_end + 1, &tz_info);
|
|
|
|
else
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: Unable to load '%s' as time zone. Skipping it.\n",
|
|
|
|
fullname);
|
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Warning: '%s' is not regular file or directory\n",
|
|
|
|
fullname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my_dirend(cur_dir);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2005-12-13 17:30:10 +01:00
|
|
|
#ifndef __NETWARE__
|
2004-06-18 08:11:31 +02:00
|
|
|
MY_INIT(argv[0]);
|
|
|
|
|
|
|
|
if (argc != 2 && argc != 3)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage:\n");
|
|
|
|
fprintf(stderr, " %s timezonedir\n", argv[0]);
|
|
|
|
fprintf(stderr, " %s timezonefile timezonename\n", argv[0]);
|
|
|
|
fprintf(stderr, " %s --leap timezonefile\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
root_name_end= strmake(fullname, argv[1], FN_REFLEN);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("TRUNCATE TABLE time_zone;\n");
|
|
|
|
printf("TRUNCATE TABLE time_zone_name;\n");
|
|
|
|
printf("TRUNCATE TABLE time_zone_transition;\n");
|
|
|
|
printf("TRUNCATE TABLE time_zone_transition_type;\n");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (scan_tz_dir(root_name_end))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "There were fatal errors during processing "
|
|
|
|
"of zoneinfo directory\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("ALTER TABLE time_zone_transition "
|
|
|
|
"ORDER BY Time_zone_id, Transition_time;\n");
|
|
|
|
printf("ALTER TABLE time_zone_transition_type "
|
|
|
|
"ORDER BY Time_zone_id, Transition_type_id;\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
init_alloc_root(&tz_storage, 32768, 0);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (strcmp(argv[1], "--leap") == 0)
|
|
|
|
{
|
|
|
|
if (tz_load(argv[2], &tz_info, &tz_storage))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Problems with zoneinfo file '%s'\n", argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
print_tz_leaps_as_sql(&tz_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tz_load(argv[1], &tz_info, &tz_storage))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Problems with zoneinfo file '%s'\n", argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
print_tz_as_sql(argv[2], &tz_info);
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
}
|
|
|
|
|
2005-12-13 17:30:10 +01:00
|
|
|
#else
|
|
|
|
fprintf(stderr, "This tool has not been ported to NetWare\n");
|
|
|
|
#endif /* __NETWARE__ */
|
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(TZINFO2SQL) */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TESTTIME
|
|
|
|
|
|
|
|
/*
|
|
|
|
Some simple brute-force test wich allowed to catch a pair of bugs.
|
|
|
|
Also can provide interesting facts about system's time zone support
|
|
|
|
implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CHAR_BIT
|
|
|
|
#define CHAR_BIT 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef TYPE_BIT
|
|
|
|
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
|
2004-06-23 23:41:56 +02:00
|
|
|
#endif
|
2004-06-18 08:11:31 +02:00
|
|
|
|
|
|
|
#ifndef TYPE_SIGNED
|
|
|
|
#define TYPE_SIGNED(type) (((type) -1) < 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
my_bool
|
|
|
|
is_equal_TIME_tm(const TIME* time_arg, const struct tm * tm_arg)
|
|
|
|
{
|
|
|
|
return (time_arg->year == (uint)tm_arg->tm_year+TM_YEAR_BASE) &&
|
|
|
|
(time_arg->month == (uint)tm_arg->tm_mon+1) &&
|
|
|
|
(time_arg->day == (uint)tm_arg->tm_mday) &&
|
|
|
|
(time_arg->hour == (uint)tm_arg->tm_hour) &&
|
|
|
|
(time_arg->minute == (uint)tm_arg->tm_min) &&
|
|
|
|
(time_arg->second == (uint)tm_arg->tm_sec) &&
|
|
|
|
time_arg->second_part == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
my_bool localtime_negative;
|
|
|
|
TIME_ZONE_INFO tz_info;
|
|
|
|
struct tm tmp;
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME time_tmp;
|
2004-06-22 01:10:30 +02:00
|
|
|
time_t t, t1, t2;
|
2004-06-18 08:11:31 +02:00
|
|
|
char fullname[FN_REFLEN+1];
|
|
|
|
char *str_end;
|
|
|
|
MEM_ROOT tz_storage;
|
|
|
|
|
|
|
|
MY_INIT(argv[0]);
|
|
|
|
|
|
|
|
init_alloc_root(&tz_storage, 32768, 0);
|
|
|
|
|
|
|
|
/* let us set some well known timezone */
|
|
|
|
setenv("TZ", "MET", 1);
|
|
|
|
tzset();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/* Some initial time zone related system info */
|
|
|
|
printf("time_t: %s %u bit\n", TYPE_SIGNED(time_t) ? "signed" : "unsigned",
|
|
|
|
(uint)TYPE_BIT(time_t));
|
|
|
|
if (TYPE_SIGNED(time_t))
|
|
|
|
{
|
|
|
|
t= -100;
|
|
|
|
localtime_negative= test(localtime_r(&t, &tmp) != 0);
|
|
|
|
printf("localtime_r %s negative params \
|
2004-06-23 23:41:56 +02:00
|
|
|
(time_t=%d is %d-%d-%d %d:%d:%d)\n",
|
2004-06-18 08:11:31 +02:00
|
|
|
(localtime_negative ? "supports" : "doesn't support"), (int)t,
|
2004-06-23 23:41:56 +02:00
|
|
|
TM_YEAR_BASE + tmp.tm_year, tmp.tm_mon + 1, tmp.tm_mday,
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("mktime %s negative results (%d)\n",
|
2004-06-23 23:41:56 +02:00
|
|
|
(t == mktime(&tmp) ? "doesn't support" : "supports"),
|
2004-06-18 08:11:31 +02:00
|
|
|
(int)mktime(&tmp));
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.tm_year= 103; tmp.tm_mon= 2; tmp.tm_mday= 30;
|
|
|
|
tmp.tm_hour= 2; tmp.tm_min= 30; tmp.tm_sec= 0; tmp.tm_isdst= -1;
|
|
|
|
t= mktime(&tmp);
|
|
|
|
printf("mktime returns %s for spring time gap (%d)\n",
|
|
|
|
(t != (time_t)-1 ? "something" : "error"), (int)t);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp.tm_year= 103; tmp.tm_mon= 8; tmp.tm_mday= 1;
|
|
|
|
tmp.tm_hour= 0; tmp.tm_min= 0; tmp.tm_sec= 0; tmp.tm_isdst= 0;
|
|
|
|
t= mktime(&tmp);
|
|
|
|
printf("mktime returns %s for non existing date (%d)\n",
|
|
|
|
(t != (time_t)-1 ? "something" : "error"), (int)t);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp.tm_year= 103; tmp.tm_mon= 8; tmp.tm_mday= 1;
|
|
|
|
tmp.tm_hour= 25; tmp.tm_min=0; tmp.tm_sec=0; tmp.tm_isdst=1;
|
|
|
|
t= mktime(&tmp);
|
|
|
|
printf("mktime %s unnormalized input (%d)\n",
|
|
|
|
(t != (time_t)-1 ? "handles" : "doesn't handle"), (int)t);
|
|
|
|
|
|
|
|
tmp.tm_year= 103; tmp.tm_mon= 9; tmp.tm_mday= 26;
|
|
|
|
tmp.tm_hour= 0; tmp.tm_min= 30; tmp.tm_sec= 0; tmp.tm_isdst= 1;
|
|
|
|
mktime(&tmp);
|
|
|
|
tmp.tm_hour= 2; tmp.tm_isdst= -1;
|
2004-06-22 01:10:30 +02:00
|
|
|
t= mktime(&tmp);
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp.tm_hour= 4; tmp.tm_isdst= 0;
|
|
|
|
mktime(&tmp);
|
|
|
|
tmp.tm_hour= 2; tmp.tm_isdst= -1;
|
2004-06-22 01:10:30 +02:00
|
|
|
t1= mktime(&tmp);
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("mktime is %s (%d %d)\n",
|
2004-06-23 23:41:56 +02:00
|
|
|
(t == t1 ? "determenistic" : "is non-determenistic"),
|
2004-06-18 08:11:31 +02:00
|
|
|
(int)t, (int)t1);
|
|
|
|
|
|
|
|
/* Let us load time zone description */
|
|
|
|
str_end= strmake(fullname, TZDIR, FN_REFLEN);
|
|
|
|
strmake(str_end, "/MET", FN_REFLEN - (str_end - fullname));
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (tz_load(fullname, &tz_info, &tz_storage))
|
|
|
|
{
|
|
|
|
printf("Unable to load time zone info from '%s'\n", fullname);
|
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Testing our implementation\n");
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (TYPE_SIGNED(time_t) && localtime_negative)
|
|
|
|
{
|
|
|
|
for (t= -40000; t < 20000; t++)
|
|
|
|
{
|
2004-06-22 01:10:30 +02:00
|
|
|
localtime_r(&t, &tmp);
|
|
|
|
gmt_sec_to_TIME(&time_tmp, (my_time_t)t, &tz_info);
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!is_equal_TIME_tm(&time_tmp, &tmp))
|
|
|
|
{
|
|
|
|
printf("Problem with negative time_t = %d\n", (int)t);
|
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("gmt_sec_to_TIME = localtime for time_t in [-40000,20000) range\n");
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
for (t= 1000000000; t < 1100000000; t+= 13)
|
|
|
|
{
|
|
|
|
localtime_r(&t,&tmp);
|
2004-06-22 01:10:30 +02:00
|
|
|
gmt_sec_to_TIME(&time_tmp, (my_time_t)t, &tz_info);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
if (!is_equal_TIME_tm(&time_tmp, &tmp))
|
|
|
|
{
|
|
|
|
printf("Problem with time_t = %d\n", (int)t);
|
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("gmt_sec_to_TIME = localtime for time_t in [1000000000,1100000000) range\n");
|
|
|
|
|
2008-04-03 17:32:00 +02:00
|
|
|
my_init_time();
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
/*
|
|
|
|
Be careful here! my_system_gmt_sec doesn't fully handle unnormalized
|
|
|
|
dates.
|
|
|
|
*/
|
|
|
|
for (time_tmp.year= 1980; time_tmp.year < 2010; time_tmp.year++)
|
2005-07-31 11:49:55 +02:00
|
|
|
{
|
2004-06-18 08:11:31 +02:00
|
|
|
for (time_tmp.month= 1; time_tmp.month < 13; time_tmp.month++)
|
2005-07-31 11:49:55 +02:00
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
for (time_tmp.day= 1;
|
2004-06-18 08:11:31 +02:00
|
|
|
time_tmp.day < mon_lengths[isleap(time_tmp.year)][time_tmp.month-1];
|
|
|
|
time_tmp.day++)
|
2005-07-31 11:49:55 +02:00
|
|
|
{
|
2004-06-18 08:11:31 +02:00
|
|
|
for (time_tmp.hour= 0; time_tmp.hour < 24; time_tmp.hour++)
|
2005-07-31 11:49:55 +02:00
|
|
|
{
|
2004-06-18 08:11:31 +02:00
|
|
|
for (time_tmp.minute= 0; time_tmp.minute < 60; time_tmp.minute+= 5)
|
2005-07-31 11:49:55 +02:00
|
|
|
{
|
2004-06-18 08:11:31 +02:00
|
|
|
for (time_tmp.second=0; time_tmp.second<60; time_tmp.second+=25)
|
|
|
|
{
|
2005-07-31 11:49:55 +02:00
|
|
|
long not_used;
|
|
|
|
my_bool not_used_2;
|
2004-06-22 01:10:30 +02:00
|
|
|
t= (time_t)my_system_gmt_sec(&time_tmp, ¬_used, ¬_used_2);
|
|
|
|
t1= (time_t)TIME_to_gmt_sec(&time_tmp, &tz_info, ¬_used_2);
|
2004-06-18 08:11:31 +02:00
|
|
|
if (t != t1)
|
|
|
|
{
|
2004-06-23 23:41:56 +02:00
|
|
|
/*
|
2004-06-18 08:11:31 +02:00
|
|
|
We need special handling during autumn since my_system_gmt_sec
|
|
|
|
prefers greater time_t values (in MET) for ambiguity.
|
|
|
|
And BTW that is a bug which should be fixed !!!
|
2004-06-23 23:41:56 +02:00
|
|
|
*/
|
2004-06-18 08:11:31 +02:00
|
|
|
tmp.tm_year= time_tmp.year - TM_YEAR_BASE;
|
|
|
|
tmp.tm_mon= time_tmp.month - 1;
|
|
|
|
tmp.tm_mday= time_tmp.day;
|
|
|
|
tmp.tm_hour= time_tmp.hour;
|
|
|
|
tmp.tm_min= time_tmp.minute;
|
|
|
|
tmp.tm_sec= time_tmp.second;
|
|
|
|
tmp.tm_isdst= 1;
|
|
|
|
|
|
|
|
t2= mktime(&tmp);
|
|
|
|
|
|
|
|
if (t1 == t2)
|
|
|
|
continue;
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("Problem: %u/%u/%u %u:%u:%u with times t=%d, t1=%d\n",
|
|
|
|
time_tmp.year, time_tmp.month, time_tmp.day,
|
|
|
|
time_tmp.hour, time_tmp.minute, time_tmp.second,
|
|
|
|
(int)t,(int)t1);
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2005-07-31 11:49:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-06-23 23:41:56 +02:00
|
|
|
|
2004-06-18 08:11:31 +02:00
|
|
|
printf("TIME_to_gmt_sec = my_system_gmt_sec for test range\n");
|
|
|
|
|
|
|
|
free_root(&tz_storage, MYF(0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(TESTTIME) */
|