Commit 7c7e0b8e authored by monty@narttu.mysql.fi's avatar monty@narttu.mysql.fi

Merge bk-internal.mysql.com:/home/bk/mysql-4.0

into narttu.mysql.fi:/my/mysql-4.0
parents fa08fdfa 3e1afec6
drop table if exists t1;
create table t1 (a date, b date, c date not null, d date);
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',';
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
SELECT * from t1;
a b c d
0000-00-00 NULL 0000-00-00 0000-00-00
0000-00-00 0000-00-00 0000-00-00 0000-00-00
2003-03-03 2003-03-03 2003-03-03 NULL
2003-03-03 2003-03-03 2003-03-03 NULL
drop table t1;
,\N,NULL,,
00,0,000000,,
2003-03-03, 20030303,030303,\N
#
# Some simple test of load data
#
drop table if exists t1;
create table t1 (a date, b date, c date not null, d date);
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',';
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
SELECT * from t1;
drop table t1;
...@@ -251,144 +251,6 @@ void get_date_from_daynr(long daynr,uint *ret_year,uint *ret_month, ...@@ -251,144 +251,6 @@ void get_date_from_daynr(long daynr,uint *ret_year,uint *ret_month,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* find date from string and put it in vektor
Input: pos = "YYMMDD" OR "YYYYMMDD" in any order or
"xxxxx YYxxxMMxxxDD xxxx" where xxx is anything exept
a number. Month or day mustn't exeed 2 digits, year may be 4 digits.
*/
#ifdef NOT_NEEDED
void find_date(string pos,uint *vek,uint flag)
{
uint length,value;
string start;
DBUG_ENTER("find_date");
DBUG_PRINT("enter",("pos: '%s' flag: %d",pos,flag));
bzero((char*) vek,sizeof(int)*4);
while (*pos && !isdigit(*pos))
pos++;
length=(uint) strlen(pos);
for (uint i=0 ; i< 3; i++)
{
start=pos; value=0;
while (isdigit(pos[0]) &&
((pos-start) < 2 || ((pos-start) < 4 && length >= 8 &&
!(flag & 3))))
{
value=value*10 + (uint) (uchar) (*pos - '0');
pos++;
}
vek[flag & 3]=value; flag>>=2;
while (*pos && (ispunct(*pos) || isspace(*pos)))
pos++;
}
DBUG_PRINT("exit",("year: %d month: %d day: %d",vek[0],vek[1],vek[2]));
DBUG_VOID_RETURN;
} /* find_date */
/* Outputs YYMMDD if input year < 100 or YYYYMMDD else */
static long calc_daynr_from_week(uint year,uint week,uint day)
{
long daynr;
int weekday;
daynr=calc_daynr(year,1,1);
if ((weekday= calc_weekday(daynr,0)) >= 3)
daynr+= (7-weekday);
else
daynr-=weekday;
return (daynr+week*7+day-8);
}
void convert_week_to_date(string date,uint flag,uint *res_length)
{
string format;
uint year,vek[4];
find_date(date,vek,(uint) (1*4+2*16)); /* YY-WW-DD */
year=vek[0];
get_date_from_daynr(calc_daynr_from_week(vek[0],vek[1],vek[2]),
&vek[0],&vek[1],&vek[2]);
*res_length=8;
format="%04d%02d%02d";
if (year < 100)
{
vek[0]= vek[0]%100;
*res_length=6;
format="%02d%02d%02d";
}
sprintf(date,format,vek[flag & 3],vek[(flag >> 2) & 3],
vek[(flag >> 4) & 3]);
return;
}
/* returns YYWWDD or YYYYWWDD according to input year */
/* flag only reflects format of input date */
void convert_date_to_week(string date,uint flag,uint *res_length)
{
uint vek[4],weekday,days,year,week,day;
long daynr,first_daynr;
char buff[256],*format;
if (! date[0])
{
get_date(buff,0,0L); /* Use current date */
find_date(buff+2,vek,(uint) (1*4+2*16)); /* YY-MM-DD */
}
else
find_date(date,vek,flag);
year= vek[0];
daynr= calc_daynr(year,vek[1],vek[2]);
first_daynr=calc_daynr(year,1,1);
/* Caculate year and first daynr of year */
if (vek[1] == 1 && (weekday=calc_weekday(first_daynr,0)) >= 3 &&
vek[2] <= 7-weekday)
{
if (!year--)
year=99;
first_daynr=first_daynr-calc_days_in_year(year);
}
else if (vek[1] == 12 &&
(weekday=calc_weekday(first_daynr+calc_days_in_year(year)),0) < 3 &&
vek[2] > 31-weekday)
{
first_daynr=first_daynr+calc_days_in_year(year);
if (year++ == 99)
year=0;
}
/* Calulate daynr of first day of week 1 */
if ((weekday= calc_weekday(first_daynr,0)) >= 3)
first_daynr+= (7-weekday);
else
first_daynr-=weekday;
days=(int) (daynr-first_daynr);
week=days/7+1 ; day=calc_weekday(daynr,0)+1;
*res_length=8;
format="%04d%02d%02d";
if (year < 100)
{
*res_length=6;
format="%02d%02d%02d";
}
sprintf(date,format,year,week,day);
return;
}
#endif
/* Functions to handle periods */ /* Functions to handle periods */
ulong convert_period_to_month(ulong period) ulong convert_period_to_month(ulong period)
...@@ -486,14 +348,14 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) ...@@ -486,14 +348,14 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
else else
date[6]=0; date[6]=0;
if (year_length == 2) if (year_length == 2 && i >=2 && (date[1] || date[2]))
date[0]+= (date[0] < YY_PART_YEAR ? 2000 : 1900); date[0]+= (date[0] < YY_PART_YEAR ? 2000 : 1900);
number_of_fields=i; number_of_fields=i;
while (i < 6) while (i < 6)
date[i++]=0; date[i++]=0;
if (number_of_fields < 3 || date[1] > 12 || if (number_of_fields < 3 || date[1] > 12 ||
date[2] > 31 || date[3] > 23 || date[4] > 59 || date[5] > 59 || date[2] > 31 || date[3] > 23 || date[4] > 59 || date[5] > 59 ||
!fuzzy_date && (date[1] == 0 || date[2] == 0)) (!fuzzy_date && (date[1] == 0 || date[2] == 0)))
{ {
/* Only give warning for a zero date if there is some garbage after */ /* Only give warning for a zero date if there is some garbage after */
if (!not_zero_date) // If zero date if (!not_zero_date) // If zero date
......
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