summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-08-21 13:44:01 +0300
committerunknown <monty@hundin.mysql.fi>2001-08-21 13:44:01 +0300
commit023cbef04c5bec28e939d5076c5f329ab7f3994f (patch)
tree4e64a1ec67abe449474688af7b06340fac1019d7
parentf3171b49b3507b84b5f26bdaf73932495741d7fc (diff)
downloadmariadb-git-023cbef04c5bec28e939d5076c5f329ab7f3994f.tar.gz
Remove usage of my_dup(), as this casued error 127 when reading MyISAM tables
New definition of WEEK(). Docs/manual.texi: Changelog myisam/mi_cache.c: Better logging on error myisam/mi_open.c: Remove usage of my_dup(), as this casued error 127 when reading tables mysql-test/r/func_time.result: More tests for the WEEK/YEARWEEK function mysql-test/t/func_time.test: More tests for the WEEK/YEARWEEK function sql/time.cc: New definition of WEEK
-rw-r--r--Docs/manual.texi2
-rw-r--r--myisam/mi_cache.c6
-rw-r--r--myisam/mi_open.c16
-rw-r--r--mysql-test/r/func_time.result24
-rw-r--r--mysql-test/t/func_time.test12
-rw-r--r--sql/time.cc7
6 files changed, 53 insertions, 14 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 1d5e668bc8f..e5569264ddc 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -45712,6 +45712,8 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet
@item
+Changed WEEK(#,0) to match the calender in the USA.
+@item
Cleaned up global lock handling for @code{FLUSH TABLES WITH READ LOCK}
@item
Fixed problem with @code{DATETIME = constant} in @code{WHERE} optimization.
diff --git a/myisam/mi_cache.c b/myisam/mi_cache.c
index 0e630cae22b..0aae316f23d 100644
--- a/myisam/mi_cache.c
+++ b/myisam/mi_cache.c
@@ -73,6 +73,9 @@ int _mi_read_cache(IO_CACHE *info, byte *buff, my_off_t pos, uint length,
if (!(flag & READING_HEADER) || info->error == -1 ||
(uint) info->error+in_buff_length < 3)
{
+ DBUG_PRINT("error",
+ ("Error %d reading next-multi-part block (Got %d bytes)",
+ my_errno, info->error));
if (!my_errno)
my_errno=HA_ERR_WRONG_IN_RECORD;
DBUG_RETURN(1);
@@ -87,6 +90,9 @@ int _mi_read_cache(IO_CACHE *info, byte *buff, my_off_t pos, uint length,
if (!(flag & READING_HEADER) || (int) read_length == -1 ||
read_length+in_buff_length < 3)
{
+ DBUG_PRINT("error",
+ ("Error %d reading new block (Got %d bytes)",
+ my_errno, (int) read_length));
if (!my_errno)
my_errno=HA_ERR_WRONG_IN_RECORD;
DBUG_RETURN(1);
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index 36cf8cfd6bd..4e98148663b 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -1009,8 +1009,13 @@ char *mi_recinfo_read(char *ptr, MI_COLUMNDEF *recinfo)
}
/**************************************************************************
- ** Help functions for recover
- *************************************************************************/
+Open data file with or without RAID
+We can't use dup() here as the data file descriptors need to have different
+active seek-positions.
+
+The argument file_to_dup is here for the future if there would on some OS
+exist a dup()-like call that would give us two different file descriptors.
+*************************************************************************/
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup)
{
@@ -1026,11 +1031,8 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup)
}
else
#endif
- if (file_to_dup >= 0)
- info->dfile=my_dup(file_to_dup,MYF(MY_WME));
- else
- info->dfile=my_open(share->data_file_name, share->mode | O_SHARE,
- MYF(MY_WME));
+ info->dfile=my_open(share->data_file_name, share->mode | O_SHARE,
+ MYF(MY_WME));
return info->dfile >= 0 ? 0 : 1;
}
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index fd7c6897574..86d2c3932ba 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -27,19 +27,35 @@ DAYOFYEAR("1997-03-03") WEEK("1998-03-03") QUARTER(980303)
HOUR("1997-03-03 23:03:22") MINUTE("23:03:22") SECOND(230322)
23 3 22
week(19980101) week(19970101) week(19980101,1) week(19970101,1)
-0 1 1 1
+0 0 1 1
week(19981231) week(19971231) week(19981231,1) week(19971231,1)
-52 53 53 53
+52 52 53 53
week(19950101) week(19950101,1)
1 0
yearweek('1981-12-31',1) yearweek('1982-01-01',1) yearweek('1982-12-31',1) yearweek('1983-01-01',1)
198153 198153 198252 198252
+yearweek('1987-01-01',1) yearweek('1987-01-01')
+198701 198652
+2000 2001 2002 2003 2004 2005 2006
+0 0 0 0 0 0 1
+2000 2001 2002 2003 2004 2005 2006
+1 0 1 1 1 1 1
+2000 2001 2002 2003 2004 2005 2006
+0 1 1 1 1 0 0
+2000 2001 2002 2003 2004 2005 2006
+1 1 1 2 2 1 1
+2000 2001 2002 2003 2004 2005 2006
+199952 200053 200152 200252 200352 200452 200601
+2000 2001 2002 2003 2004 2005 2006
+200001 200053 200201 200301 200401 200501 200601
+2000 2001 2002 2003 2004 2005 2006
+199952 200101 200201 200301 200401 200453 200552
+2000 2001 2002 2003 2004 2005 2006
+200001 200101 200201 200302 200402 200501 200601
date_format('1998-12-31','%x-%v') date_format('1999-01-01','%x-%v')
1998-53 1998-53
date_format('1999-12-31','%x-%v') date_format('2000-01-01','%x-%v')
1999-52 1999-52
-yearweek('1987-01-01',1) yearweek('1987-01-01')
-198701 198653
dayname("1962-03-03") dayname("1962-03-03")+0
Saturday 5
monthname("1972-03-04") monthname("1972-03-04")+0
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index a91844ab986..ff44bc1ce1c 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -17,13 +17,23 @@ select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31");
select month("2001-02-00"),year("2001-00-00");
select DAYOFYEAR("1997-03-03"), WEEK("1998-03-03"), QUARTER(980303);
select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322);
+
+# Test of week and yearweek
select week(19980101),week(19970101),week(19980101,1),week(19970101,1);
select week(19981231),week(19971231),week(19981231,1),week(19971231,1);
select week(19950101),week(19950101,1);
select yearweek('1981-12-31',1),yearweek('1982-01-01',1),yearweek('1982-12-31',1),yearweek('1983-01-01',1);
+select yearweek('1987-01-01',1),yearweek('1987-01-01');
+select week("2000-01-01",0) as '2000', week("2001-01-01",0) as '2001', week("2002-01-01",0) as '2002',week("2003-01-01",0) as '2003', week("2004-01-01",0) as '2004', week("2005-01-01",0) as '2005', week("2006-01-01",0) as '2006';
+select week("2000-01-06",0) as '2000', week("2001-01-06",0) as '2001', week("2002-01-06",0) as '2002',week("2003-01-06",0) as '2003', week("2004-01-06",0) as '2004', week("2005-01-06",0) as '2005', week("2006-01-06",0) as '2006';
+select week("2000-01-01",1) as '2000', week("2001-01-01",1) as '2001', week("2002-01-01",1) as '2002',week("2003-01-01",1) as '2003', week("2004-01-01",1) as '2004', week("2005-01-01",1) as '2005', week("2006-01-01",1) as '2006';
+select week("2000-01-06",1) as '2000', week("2001-01-06",1) as '2001', week("2002-01-06",1) as '2002',week("2003-01-06",1) as '2003', week("2004-01-06",1) as '2004', week("2005-01-06",1) as '2005', week("2006-01-06",1) as '2006';
+select yearweek("2000-01-01",0) as '2000', yearweek("2001-01-01",0) as '2001', yearweek("2002-01-01",0) as '2002',yearweek("2003-01-01",0) as '2003', yearweek("2004-01-01",0) as '2004', yearweek("2005-01-01",0) as '2005', yearweek("2006-01-01",0) as '2006';
+select yearweek("2000-01-06",0) as '2000', yearweek("2001-01-06",0) as '2001', yearweek("2002-01-06",0) as '2002',yearweek("2003-01-06",0) as '2003', yearweek("2004-01-06",0) as '2004', yearweek("2005-01-06",0) as '2005', yearweek("2006-01-06",0) as '2006';
+select yearweek("2000-01-01",1) as '2000', yearweek("2001-01-01",1) as '2001', yearweek("2002-01-01",1) as '2002',yearweek("2003-01-01",1) as '2003', yearweek("2004-01-01",1) as '2004', yearweek("2005-01-01",1) as '2005', yearweek("2006-01-01",1) as '2006';
+select yearweek("2000-01-06",1) as '2000', yearweek("2001-01-06",1) as '2001', yearweek("2002-01-06",1) as '2002',yearweek("2003-01-06",1) as '2003', yearweek("2004-01-06",1) as '2004', yearweek("2005-01-06",1) as '2005', yearweek("2006-01-06",1) as '2006';
select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v');
select date_format('1999-12-31','%x-%v'),date_format('2000-01-01','%x-%v');
-select yearweek('1987-01-01',1),yearweek('1987-01-01');
select dayname("1962-03-03"),dayname("1962-03-03")+0;
select monthname("1972-03-04"),monthname("1972-03-04")+0;
diff --git a/sql/time.cc b/sql/time.cc
index e0b74fc9d25..d1e0aee0fa4 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -176,7 +176,9 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week,
ulong first_daynr=calc_daynr(l_time->year,1,1);
uint weekday=calc_weekday(first_daynr,sunday_first_day_of_week);
*year=l_time->year;
- if (l_time->month == 1 && weekday >= 4 && l_time->day <= 7-weekday)
+ if (l_time->month == 1 && l_time->day <= 7-weekday &&
+ ((!sunday_first_day_of_week && weekday >= 4) ||
+ (sunday_first_day_of_week && weekday != 0)))
{
/* Last week of the previous year */
if (!with_year)
@@ -186,7 +188,8 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week,
first_daynr-= (days=calc_days_in_year(*year));
weekday= (weekday + 53*7- days) % 7;
}
- if (weekday >= 4)
+ if ((sunday_first_day_of_week && weekday != 0) ||
+ (!sunday_first_day_of_week && weekday >= 4))
days= daynr - (first_daynr+ (7-weekday));
else
days= daynr - (first_daynr - weekday);