Commit b79d01d4 authored by jan@hundin.mysql.fi's avatar jan@hundin.mysql.fi

Merge jlindstrom@build.mysql.com:/home/bk/mysql-4.1

into hundin.mysql.fi:/home/jan/mysql-4.1
parents 9d615368 3262c287
...@@ -7,11 +7,6 @@ extra_flags="$pentium_cflags $fast_cflags -g" ...@@ -7,11 +7,6 @@ extra_flags="$pentium_cflags $fast_cflags -g"
extra_configs="$pentium_configs" extra_configs="$pentium_configs"
#strip=yes #strip=yes
#extra_configs="$extra_configs --with-innodb --with-berkeley-db \
# --with-embedded-server --enable-thread-safe-client \
# --with-openssl --with-vio --with-raid --with-ndbcluster"
# removed per discussion with Brian and Sanja because it makes Bootstrap
# fail
extra_configs="$extra_configs --with-innodb --with-berkeley-db \ extra_configs="$extra_configs --with-innodb --with-berkeley-db \
--with-embedded-server --enable-thread-safe-client \ --with-embedded-server --enable-thread-safe-client \
--with-openssl --with-vio --with-raid --with-ndbcluster" --with-openssl --with-vio --with-raid --with-ndbcluster"
......
...@@ -9,7 +9,7 @@ cxx_warnings="$cxx_warnings $debug_extra_warnings" ...@@ -9,7 +9,7 @@ cxx_warnings="$cxx_warnings $debug_extra_warnings"
extra_configs="$pentium_configs $debug_configs" extra_configs="$pentium_configs $debug_configs"
# We want to test isam when building with valgrind # We want to test isam when building with valgrind
extra_configs="$extra_configs --with-berkeley-db --with-innodb --with-isam --with-embedded-server --with-openssl" extra_configs="$extra_configs --with-berkeley-db --with-innodb --with-isam --with-embedded-server --with-openssl --with-vio --with-raid --with-ndbcluster"
. "$path/FINISH.sh" . "$path/FINISH.sh"
......
...@@ -43,5 +43,6 @@ enum options_client ...@@ -43,5 +43,6 @@ enum options_client
OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION,OPT_MYSQL_PROTOCOL, OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION,OPT_MYSQL_PROTOCOL,
OPT_SHARED_MEMORY_BASE_NAME, OPT_FRM, OPT_SKIP_OPTIMIZATION, OPT_SHARED_MEMORY_BASE_NAME, OPT_FRM, OPT_SKIP_OPTIMIZATION,
OPT_COMPATIBLE, OPT_RECONNECT, OPT_DELIMITER, OPT_SECURE_AUTH, OPT_COMPATIBLE, OPT_RECONNECT, OPT_DELIMITER, OPT_SECURE_AUTH,
OPT_OPEN_FILES_LIMIT, OPT_SET_CHARSET, OPT_CREATE_OPTIONS OPT_OPEN_FILES_LIMIT, OPT_SET_CHARSET, OPT_CREATE_OPTIONS,
OPT_START_POSITION, OPT_STOP_POSITION, OPT_START_DATETIME, OPT_STOP_DATETIME
}; };
This diff is collapsed.
...@@ -41,6 +41,13 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ...@@ -41,6 +41,13 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time,
int *was_cut); int *was_cut);
long calc_daynr(uint year,uint month,uint day);
void init_time(void);
my_time_t
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap);
C_MODE_END C_MODE_END
#endif /* _my_time_h_ */ #endif /* _my_time_h_ */
...@@ -34,4 +34,13 @@ typedef struct st_mysql_time ...@@ -34,4 +34,13 @@ typedef struct st_mysql_time
enum enum_mysql_timestamp_type time_type; enum enum_mysql_timestamp_type time_type;
} MYSQL_TIME; } MYSQL_TIME;
/*
Portable time_t replacement.
Should be signed and hold seconds for 1902-2038 range.
*/
typedef long my_time_t;
#define MY_TIME_T_MAX LONG_MAX
#define MY_TIME_T_MIN LONG_MIN
#endif /* _mysql_time_h_ */ #endif /* _mysql_time_h_ */
This diff is collapsed.
# Test for the new options --start-datetime, stop-datetime,
# and a few others.
--disable_warnings
drop table if exists t1;
--enable_warnings
reset master;
# We need this for getting fixed timestamps inside of this test.
# I use a date in the future to keep a growing timestamp along the
# binlog (including the Start_log_event). This test will work
# unchanged everywhere, because mysql-test-run has fixed TZ, which it
# exports (so mysqlbinlog has same fixed TZ).
set @a=UNIX_TIMESTAMP("2020-01-21 15:32:22");
set timestamp=@a;
create table t1 (a int auto_increment not null primary key, b char(3));
insert into t1 values(null, "a");
insert into t1 values(null, "b");
set timestamp=@a+2;
insert into t1 values(null, "c");
set timestamp=@a+4;
insert into t1 values(null, "d");
insert into t1 values(null, "e");
flush logs;
set timestamp=@a+1; # this could happen on a slave
insert into t1 values(null, "f");
# delimiters are for easier debugging in future
--disable_query_log
select "--- Local --" as "";
--enable_query_log
#
# We should use --short-form everywhere because in other case output will
# be time dependent (the Start events). Better than nothing.
#
--exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- offset --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --offset=2 $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- start-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --start-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- stop-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --stop-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- start-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- stop-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001
--disable_query_log
select "--- Local with 2 binlogs on command line --" as "";
--enable_query_log
# This is to verify that some options apply only to first, or last binlog
--exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- offset --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --offset=2 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- start-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --start-position=497 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- stop-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --stop-position=32 $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- start-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- stop-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQL_TEST_DIR/var/log/master-bin.000001 $MYSQL_TEST_DIR/var/log/master-bin.000002
--disable_query_log
select "--- Remote --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- offset --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --offset=2 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- start-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --start-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- stop-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --stop-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- start-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- stop-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
--disable_query_log
select "--- Remote with 2 binlogs on command line --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- offset --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --offset=2 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- start-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --start-position=497 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- stop-position --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --stop-position=32 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- start-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--start-datetime=20200121153224" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- stop-datetime --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form "--stop-datetime=2020/01/21 15@32@24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
--disable_query_log
select "--- to-last-log --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --to-last-log master-bin.000001
# clean up
--disable_query_log
select "--- end of test --" as "";
--enable_query_log
drop table t1;
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
# The slave is started with max_binlog_size=16384 bytes, # The slave is started with max_binlog_size=16384 bytes,
# to force many rotations (approximately 30 rotations) # to force many rotations (approximately 30 rotations)
# If the master or slave does not support InnoDB, this test will pass source include/have_innodb.inc;
source include/master-slave.inc; source include/master-slave.inc;
connection slave; connection slave;
stop slave; stop slave;
......
...@@ -461,17 +461,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags) ...@@ -461,17 +461,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
else else
finfo.mystat= NULL; finfo.mystat= NULL;
/*
If the directory is the root directory of the drive, Windows sometimes
creates hidden or system files there (like RECYCLER); do not show
them. We would need to see how this can be achieved with a Borland
compiler.
*/
#ifndef __BORLANDC__
if (attrib & (_A_HIDDEN | _A_SYSTEM))
continue;
#endif
if (push_dynamic(dir_entries_storage, (gptr)&finfo)) if (push_dynamic(dir_entries_storage, (gptr)&finfo))
goto error; goto error;
......
...@@ -35,6 +35,16 @@ static uchar internal_format_positions[]= ...@@ -35,6 +35,16 @@ static uchar internal_format_positions[]=
static char time_separator=':'; static char time_separator=':';
static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */
uchar days_in_month[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
/*
Offset of system time zone from UTC in seconds used to speed up
work of my_system_gmt_sec() function.
*/
static long my_time_zone=0;
/* /*
Convert a timestamp string to a MYSQL_TIME value. Convert a timestamp string to a MYSQL_TIME value.
...@@ -559,3 +569,148 @@ fractional: ...@@ -559,3 +569,148 @@ fractional:
} }
/*
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
SYNOPSIS
init_time()
*/
void init_time(void)
{
time_t seconds;
struct tm *l_time,tm_tmp;;
MYSQL_TIME my_time;
bool not_used;
seconds= (time_t) time((time_t*) 0);
localtime_r(&seconds,&tm_tmp);
l_time= &tm_tmp;
my_time_zone= 3600; /* Comp. for -3600 in my_gmt_sec */
my_time.year= (uint) l_time->tm_year+1900;
my_time.month= (uint) l_time->tm_mon+1;
my_time.day= (uint) l_time->tm_mday;
my_time.hour= (uint) l_time->tm_hour;
my_time.minute= (uint) l_time->tm_min;
my_time.second= (uint) l_time->tm_sec;
my_system_gmt_sec(&my_time, &my_time_zone, &not_used); /* Init my_time_zone */
}
/* Calculate nr of day since year 0 in new date-system (from 1615) */
long calc_daynr(uint year,uint month,uint day)
{
long delsum;
int temp;
DBUG_ENTER("calc_daynr");
if (year == 0 && month == 0 && day == 0)
DBUG_RETURN(0); /* Skip errors */
if (year < 200)
{
if ((year=year+1900) < 1900+YY_PART_YEAR)
year+=100;
}
delsum= (long) (365L * year+ 31*(month-1) +day);
if (month <= 2)
year--;
else
delsum-= (long) (month*4+23)/10;
temp=(int) ((year/100+1)*3)/4;
DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld",
year+(month <= 2),month,day,delsum+year/4-temp));
DBUG_RETURN(delsum+(int) year/4-temp);
} /* calc_daynr */
/*
Convert time in MYSQL_TIME representation in system time zone to its
my_time_t form (number of seconds in UTC since begginning of Unix Epoch).
SYNOPSIS
my_system_gmt_sec()
t - time value to be converted
my_timezone - pointer to long where offset of system time zone
from UTC will be stored for caching
in_dst_time_gap - set to true if time falls into spring time-gap
NOTES
The idea is to cache the time zone offset from UTC (including daylight
saving time) for the next call to make things faster. But currently we
just calculate this offset during startup (by calling init_time()
function) and use it all the time.
Time value provided should be legal time value (e.g. '2003-01-01 25:00:00'
is not allowed).
RETURN VALUE
Time in UTC seconds since Unix Epoch representation.
*/
my_time_t
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap)
{
uint loop;
time_t tmp;
struct tm *l_time,tm_tmp;
long diff, current_timezone;
/*
Calculate the gmt time based on current time and timezone
The -1 on the end is to ensure that if have a date that exists twice
(like 2002-10-27 02:00:0 MET), we will find the initial date.
By doing -3600 we will have to call localtime_r() several times, but
I couldn't come up with a better way to get a repeatable result :(
We can't use mktime() as it's buggy on many platforms and not thread safe.
*/
tmp=(time_t) (((calc_daynr((uint) t->year,(uint) t->month,(uint) t->day) -
(long) days_at_timestart)*86400L + (long) t->hour*3600L +
(long) (t->minute*60 + t->second)) + (time_t) my_time_zone -
3600);
current_timezone= my_time_zone;
localtime_r(&tmp,&tm_tmp);
l_time=&tm_tmp;
for (loop=0;
loop < 2 &&
(t->hour != (uint) l_time->tm_hour ||
t->minute != (uint) l_time->tm_min);
loop++)
{ /* One check should be enough ? */
/* Get difference in days */
int days= t->day - l_time->tm_mday;
if (days < -1)
days= 1; // Month has wrapped
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) +
(long) (60*((int) t->minute - (int) l_time->tm_min)));
current_timezone+= diff+3600; // Compensate for -3600 above
tmp+= (time_t) diff;
localtime_r(&tmp,&tm_tmp);
l_time=&tm_tmp;
}
/*
Fix that if we are in the not existing daylight saving time hour
we move the start of the next real hour
*/
if (loop == 2 && t->hour != (uint) l_time->tm_hour)
{
int days= t->day - l_time->tm_mday;
if (days < -1)
days=1; // Month has wrapped
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+
(long) (60*((int) t->minute - (int) l_time->tm_min)));
if (diff == 3600)
tmp+=3600 - t->minute*60 - t->second; // Move to next hour
else if (diff == -3600)
tmp-=t->minute*60 + t->second; // Move to previous hour
*in_dst_time_gap= 1;
}
*my_timezone= current_timezone;
return (my_time_t) tmp;
} /* my_system_gmt_sec */
...@@ -333,11 +333,11 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field, ...@@ -333,11 +333,11 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field,
- TODO allocate blob part aligned buffers - TODO allocate blob part aligned buffers
*/ */
NdbBlob::ActiveHook get_ndb_blobs_value; NdbBlob::ActiveHook g_get_ndb_blobs_value;
int get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg) int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg)
{ {
DBUG_ENTER("get_ndb_blobs_value [callback]"); DBUG_ENTER("g_get_ndb_blobs_value");
if (ndb_blob->blobsNextBlob() != NULL) if (ndb_blob->blobsNextBlob() != NULL)
DBUG_RETURN(0); DBUG_RETURN(0);
ha_ndbcluster *ha= (ha_ndbcluster *)arg; ha_ndbcluster *ha= (ha_ndbcluster *)arg;
...@@ -428,7 +428,7 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field, ...@@ -428,7 +428,7 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field,
{ {
// Set callback // Set callback
void *arg= (void *)this; void *arg= (void *)this;
DBUG_RETURN(ndb_blob->setActiveHook(::get_ndb_blobs_value, arg) != 0); DBUG_RETURN(ndb_blob->setActiveHook(g_get_ndb_blobs_value, arg) != 0);
} }
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
...@@ -184,7 +184,7 @@ class ha_ndbcluster: public handler ...@@ -184,7 +184,7 @@ class ha_ndbcluster: public handler
uint fieldnr, const byte* field_ptr); uint fieldnr, const byte* field_ptr);
int set_ndb_value(NdbOperation*, Field *field, uint fieldnr); int set_ndb_value(NdbOperation*, Field *field, uint fieldnr);
int get_ndb_value(NdbOperation*, Field *field, uint fieldnr); int get_ndb_value(NdbOperation*, Field *field, uint fieldnr);
friend int ::get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg); friend int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg);
int get_ndb_blobs_value(NdbBlob *last_ndb_blob); int get_ndb_blobs_value(NdbBlob *last_ndb_blob);
int set_primary_key(NdbOperation *op, const byte *key); int set_primary_key(NdbOperation *op, const byte *key);
int set_primary_key(NdbOperation *op); int set_primary_key(NdbOperation *op);
......
...@@ -828,7 +828,7 @@ extern Gt_creator gt_creator; ...@@ -828,7 +828,7 @@ extern Gt_creator gt_creator;
extern Lt_creator lt_creator; extern Lt_creator lt_creator;
extern Ge_creator ge_creator; extern Ge_creator ge_creator;
extern Le_creator le_creator; extern Le_creator le_creator;
extern uchar *days_in_month; extern uchar days_in_month[];
extern char language[LIBLEN],reg_ext[FN_EXTLEN]; extern char language[LIBLEN],reg_ext[FN_EXTLEN];
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
...@@ -994,12 +994,9 @@ void free_blobs(TABLE *table); ...@@ -994,12 +994,9 @@ void free_blobs(TABLE *table);
int set_zone(int nr,int min_zone,int max_zone); int set_zone(int nr,int min_zone,int max_zone);
ulong convert_period_to_month(ulong period); ulong convert_period_to_month(ulong period);
ulong convert_month_to_period(ulong month); ulong convert_month_to_period(ulong month);
long calc_daynr(uint year,uint month,uint day);
uint calc_days_in_year(uint year); uint calc_days_in_year(uint year);
void get_date_from_daynr(long daynr,uint *year, uint *month, void get_date_from_daynr(long daynr,uint *year, uint *month,
uint *day); uint *day);
void init_time(void);
my_time_t my_system_gmt_sec(const TIME *, long *current_timezone, bool *not_exist);
my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *not_exist); my_time_t TIME_to_timestamp(THD *thd, const TIME *t, bool *not_exist);
bool str_to_time_with_warn(const char *str,uint length,TIME *l_time); bool str_to_time_with_warn(const char *str,uint length,TIME *l_time);
timestamp_type str_to_datetime_with_warn(const char *str, uint length, timestamp_type str_to_datetime_with_warn(const char *str, uint length,
......
...@@ -20,166 +20,9 @@ ...@@ -20,166 +20,9 @@
#include "mysql_priv.h" #include "mysql_priv.h"
#include <m_ctype.h> #include <m_ctype.h>
static ulong const days_at_timestart=719528; /* daynr at 1970.01.01 */
uchar *days_in_month= (uchar*) "\037\034\037\036\037\036\037\037\036\037\036\037";
/*
Offset of system time zone from UTC in seconds used to speed up
work of my_system_gmt_sec() function.
*/
static long my_time_zone=0;
/*
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
SYNOPSIS
init_time()
*/
void init_time(void)
{
time_t seconds;
struct tm *l_time,tm_tmp;;
TIME my_time;
bool not_used;
seconds= (time_t) time((time_t*) 0);
localtime_r(&seconds,&tm_tmp);
l_time= &tm_tmp;
my_time_zone= 3600; /* Comp. for -3600 in my_gmt_sec */
my_time.year= (uint) l_time->tm_year+1900;
my_time.month= (uint) l_time->tm_mon+1;
my_time.day= (uint) l_time->tm_mday;
my_time.hour= (uint) l_time->tm_hour;
my_time.minute= (uint) l_time->tm_min;
my_time.second= (uint) l_time->tm_sec;
my_system_gmt_sec(&my_time, &my_time_zone, &not_used); /* Init my_time_zone */
}
/*
Convert time in TIME representation in system time zone to its
my_time_t form (number of seconds in UTC since begginning of Unix Epoch).
SYNOPSIS
my_system_gmt_sec()
t - time value to be converted
my_timezone - pointer to long where offset of system time zone
from UTC will be stored for caching
in_dst_time_gap - set to true if time falls into spring time-gap
NOTES
The idea is to cache the time zone offset from UTC (including daylight
saving time) for the next call to make things faster. But currently we
just calculate this offset during startup (by calling init_time()
function) and use it all the time.
Time value provided should be legal time value (e.g. '2003-01-01 25:00:00'
is not allowed).
RETURN VALUE
Time in UTC seconds since Unix Epoch representation.
*/
my_time_t
my_system_gmt_sec(const TIME *t, long *my_timezone, bool *in_dst_time_gap)
{
uint loop;
time_t tmp;
struct tm *l_time,tm_tmp;
long diff, current_timezone;
/*
Calculate the gmt time based on current time and timezone
The -1 on the end is to ensure that if have a date that exists twice
(like 2002-10-27 02:00:0 MET), we will find the initial date.
By doing -3600 we will have to call localtime_r() several times, but
I couldn't come up with a better way to get a repeatable result :(
We can't use mktime() as it's buggy on many platforms and not thread safe.
*/
tmp=(time_t) (((calc_daynr((uint) t->year,(uint) t->month,(uint) t->day) -
(long) days_at_timestart)*86400L + (long) t->hour*3600L +
(long) (t->minute*60 + t->second)) + (time_t) my_time_zone -
3600);
current_timezone= my_time_zone;
localtime_r(&tmp,&tm_tmp);
l_time=&tm_tmp;
for (loop=0;
loop < 2 &&
(t->hour != (uint) l_time->tm_hour ||
t->minute != (uint) l_time->tm_min);
loop++)
{ /* One check should be enough ? */
/* Get difference in days */
int days= t->day - l_time->tm_mday;
if (days < -1)
days= 1; // Month has wrapped
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) +
(long) (60*((int) t->minute - (int) l_time->tm_min)));
current_timezone+= diff+3600; // Compensate for -3600 above
tmp+= (time_t) diff;
localtime_r(&tmp,&tm_tmp);
l_time=&tm_tmp;
}
/*
Fix that if we are in the not existing daylight saving time hour
we move the start of the next real hour
*/
if (loop == 2 && t->hour != (uint) l_time->tm_hour)
{
int days= t->day - l_time->tm_mday;
if (days < -1)
days=1; // Month has wrapped
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+
(long) (60*((int) t->minute - (int) l_time->tm_min)));
if (diff == 3600)
tmp+=3600 - t->minute*60 - t->second; // Move to next hour
else if (diff == -3600)
tmp-=t->minute*60 + t->second; // Move to previous hour
*in_dst_time_gap= 1;
}
*my_timezone= current_timezone;
return (my_time_t) tmp;
} /* my_system_gmt_sec */
/* Some functions to calculate dates */ /* Some functions to calculate dates */
/* Calculate nr of day since year 0 in new date-system (from 1615) */
long calc_daynr(uint year,uint month,uint day)
{
long delsum;
int temp;
DBUG_ENTER("calc_daynr");
if (year == 0 && month == 0 && day == 0)
DBUG_RETURN(0); /* Skip errors */
if (year < 200)
{
if ((year=year+1900) < 1900+YY_PART_YEAR)
year+=100;
}
delsum= (long) (365L * year+ 31*(month-1) +day);
if (month <= 2)
year--;
else
delsum-= (long) (month*4+23)/10;
temp=(int) ((year/100+1)*3)/4;
DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld",
year+(month <= 2),month,day,delsum+year/4-temp));
DBUG_RETURN(delsum+(int) year/4-temp);
} /* calc_daynr */
#ifndef TESTTIME #ifndef TESTTIME
/* Calc weekday from daynr */ /* Calc weekday from daynr */
/* Returns 0 for monday, 1 for tuesday .... */ /* Returns 0 for monday, 1 for tuesday .... */
......
...@@ -19,15 +19,10 @@ ...@@ -19,15 +19,10 @@
#pragma interface /* gcc class interface */ #pragma interface /* gcc class interface */
#endif #endif
/* #include <mysql_time.h>
Portable time_t replacement.
Should be signed and hold seconds for 1902-2038 range.
*/
typedef long my_time_t;
#define MY_TIME_T_MAX LONG_MAX
#define MY_TIME_T_MIN LONG_MIN
#if !defined(TESTTIME) && !defined(TZINFO2SQL) #if !defined(TESTTIME) && !defined(TZINFO2SQL)
/* /*
This class represents abstract time zone and provides This class represents abstract time zone and provides
basic interface for TIME <-> my_time_t conversion. basic interface for TIME <-> my_time_t conversion.
......
...@@ -75,7 +75,7 @@ bool mysql_create_frm(THD *thd, my_string file_name, ...@@ -75,7 +75,7 @@ bool mysql_create_frm(THD *thd, my_string file_name,
uchar fileinfo[64],forminfo[288],*keybuff; uchar fileinfo[64],forminfo[288],*keybuff;
TYPELIB formnames; TYPELIB formnames;
uchar *screen_buff; uchar *screen_buff;
DBUG_ENTER("rea_create_table"); DBUG_ENTER("mysql_create_frm");
formnames.type_names=0; formnames.type_names=0;
if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,0))) if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,0)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment