Commit afedd9f8 authored by unknown's avatar unknown

Task #835: additional changes fot str_to_date


include/mysqld_error.h:
  Task #835: additional changes fot str_to_date
  New error message
mysql-test/r/date_formats.result:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/r/func_sapdb.result:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/r/func_time.result:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/r/type_time.result:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/t/date_formats.test:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/t/func_sapdb.test:
  Task #835: additional changes fot str_to_date
  tests
mysql-test/t/func_time.test:
  Task #835: additional changes fot str_to_date
  tests
sql/share/czech/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/danish/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/dutch/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/english/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/estonian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/french/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/german/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/greek/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/hungarian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/italian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/japanese/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/korean/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/norwegian-ny/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/norwegian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/polish/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/portuguese/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/romanian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/russian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/serbian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/slovak/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/spanish/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/swedish/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
sql/share/ukrainian/errmsg.txt:
  Task #835: additional changes fot str_to_date
  New error message
parent 1b81fcf8
......@@ -308,4 +308,5 @@
#define ER_FEATURE_DISABLED 1289
#define ER_OPTION_PREVENTS_STATEMENT 1290
#define ER_DUPLICATED_VALUE_IN_TYPE 1291
#define ER_ERROR_MESSAGES 292
#define ER_TRUNCATED_WRONG_VALUE 1292
#define ER_ERROR_MESSAGES 293
This diff is collapsed.
......@@ -198,3 +198,18 @@ NULL NULL
NULL NULL
00:00:00 -24:00:00
drop table t1, test;
select addtime("-01:01:01.01", "-23:59:59.1") as a;
a
-25:01:00.110000
select microsecond("1997-12-31 23:59:59.01") as a;
a
10000
select microsecond(19971231235959.01) as a;
a
10000
select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a;
a
1997-12-31 00:00:10.090000
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f");
str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f")
2003-01-02 10:11:12.001200
......@@ -506,17 +506,32 @@ last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
f1 f2 f3 f4 f5 last_day(NULL) last_day('2001-02-12')
2000-02-29 2002-12-31 NULL 2003-04-30 2001-01-31 NULL 2001-02-28
create table t1 select last_day('2000-02-05') as a;
create table t1 select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
describe t1;
Field Type Null Key Default Extra
a date 0000-00-00
b date YES NULL
select * from t1;
a
2000-02-29
a b
2000-02-29 1996-01-01
drop table t1;
select last_day('2000-02-05');
last_day('2000-02-05')
2000-02-29
select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
a b
2000-02-29 1996-01-01
select date_add(last_day("1997-12-1"), INTERVAL 1 DAY);
date_add(last_day("1997-12-1"), INTERVAL 1 DAY)
1998-01-01
select length(last_day("1997-12-1"));
length(last_day("1997-12-1"))
10
select last_day("1997-12-1")+0;
last_day("1997-12-1")+0
19971231
select last_day("1997-12-1")+0.0;
last_day("1997-12-1")+0.0
19971231.0
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0
1
......
......@@ -25,9 +25,11 @@ t
36:30:31
insert into t1 values("10.22.22"),(1234567),(123456789),(123456789.10),("10 22:22"),("12.45a");
Warnings:
Note 1292 Truncated wrong time value: '10.22.22'
Warning 1264 Data truncated, out of range for column 't' at row 2
Warning 1264 Data truncated, out of range for column 't' at row 3
Warning 1264 Data truncated, out of range for column 't' at row 4
Note 1292 Truncated wrong time value: '12.45a'
select * from t1;
t
10:22:33
......
......@@ -124,7 +124,7 @@ select str_to_date(concat('15-01-2001',' 2:59:58.999'),
create table t1 (date char(30), format char(30) not null);
insert into t1 values
('2003-01-02 10:11:12', '%Y-%m-%d %H:%i:%S'),
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S'),
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S.%#'),
('2003-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'),
('2003-01-02 01:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f%p'),
('2003-01-02 02:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f %p'),
......@@ -209,3 +209,32 @@ create table t1 (d date);
insert into t1 values ('2004-07-14'),('2005-07-14');
select date_format(d,"%d") from t1 order by 1;
drop table t1;
select str_to_date("2003-....01ABCD-02 10:11:12.0012", "%Y-%.%m%@-%d %H:%i:%S.%f") as a;
create table t1 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
str_to_date("10:11:12.0012", "%H:%i:%S.%f") as f2,
str_to_date("2003-01-02", "%Y-%m-%d") as f3,
str_to_date("02", "%d") as f4, str_to_date("02 10", "%d %H") as f5;
describe t1;
select * from t1;
drop table t1;
create table t1 select "02 10" as a, "%d %H" as b;
select str_to_date(a,b) from t1;
create table t2 select str_to_date(a,b) from t1;
describe t2;
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
str_to_date("2003-01-02", "%Y-%m-%d") as f3,
str_to_date("02 10:11:12", "%d %H:%i:%S.%f") as f4,
str_to_date("02 10:11:12", "%d %H:%i:%S") as f5,
str_to_date("02 10", "%d %f") as f6;
drop table t1, t2;
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
microsecond("1997-12-31 23:59:59.01XXXX") as f3;
select str_to_date("2003-04-05 g", "%Y-%m-%d") as f1,
str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
......@@ -97,3 +97,9 @@ SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test;
SELECT TIMEDIFF(t1,t4) As ttt, TIMEDIFF(t2, t3) As qqq from test;
drop table t1, test;
select addtime("-01:01:01.01", "-23:59:59.1") as a;
select microsecond("1997-12-31 23:59:59.01") as a;
select microsecond(19971231235959.01) as a;
select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a;
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f");
......@@ -249,12 +249,18 @@ select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
create table t1 select last_day('2000-02-05') as a;
create table t1 select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
describe t1;
select * from t1;
drop table t1;
select last_day('2000-02-05');
select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
select date_add(last_day("1997-12-1"), INTERVAL 1 DAY);
select length(last_day("1997-12-1"));
select last_day("1997-12-1")+0;
select last_day("1997-12-1")+0.0;
# Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that
# TZ variable set to GMT-3
......
This diff is collapsed.
......@@ -21,6 +21,11 @@
#pragma interface /* gcc class implementation */
#endif
enum date_time_format_types
{
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
};
class Item_func_period_add :public Item_int_func
{
public:
......@@ -318,6 +323,7 @@ public:
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
String *val_str(String *str);
longlong val_int();
double val() { return (double) val_int(); }
const char *func_name() const { return "date"; }
void fix_length_and_dec()
......@@ -407,6 +413,7 @@ public:
Item_func_curdate() :Item_date() {}
void set_result_from_tm(struct tm *now);
longlong val_int() { return (value) ; }
String *val_str(String *str);
void fix_length_and_dec();
bool get_date(TIME *res, uint fuzzy_date);
virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0;
......@@ -477,8 +484,8 @@ class Item_func_from_days :public Item_date
{
public:
Item_func_from_days(Item *a) :Item_date(a) {}
longlong val_int();
const char *func_name() const { return "from_days"; }
bool get_date(TIME *res, uint fuzzy_date);
};
......@@ -806,37 +813,29 @@ public:
};
class Item_func_str_to_date :public Item_date_func
class Item_func_str_to_date :public Item_str_func
{
enum_field_types cached_field_type;
date_time_format_types cached_format_type;
timestamp_type cached_timestamp_type;
bool const_item;
public:
Item_func_str_to_date(Item *a, Item *b)
:Item_date_func(a, b)
:Item_str_func(a, b)
{}
String *val_str(String *str);
bool get_date(TIME *ltime, uint fuzzy_date);
const char *func_name() const { return "str_to_date"; }
void fix_length_and_dec()
{
maybe_null= 1;
decimals=0;
max_length=MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
enum_field_types field_type() const { return cached_field_type; }
void fix_length_and_dec();
Field *tmp_table_field(TABLE *t_arg);
};
class Item_func_last_day :public Item_str_func
class Item_func_last_day :public Item_date
{
public:
Item_func_last_day(Item *a) :Item_str_func(a) {}
String *val_str(String *str);
Item_func_last_day(Item *a) :Item_date(a) {}
const char *func_name() const { return "last_day"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
void fix_length_and_dec()
{
decimals=0;
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
}
bool get_date(TIME *res, uint fuzzy_date);
};
......@@ -799,6 +799,7 @@ extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file;
extern char log_error_file[FN_REFLEN];
extern double log_10[32];
extern ulonglong log_10_int[20];
extern ulonglong keybuff_size;
extern ulong refresh_version,flush_version, thread_id,query_id,opened_tables;
extern ulong created_tmp_tables, created_tmp_disk_tables, bytes_sent;
......@@ -958,6 +959,8 @@ timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time,
void localtime_to_TIME(TIME *to, struct tm *from);
void calc_time_from_sec(TIME *to, long seconds, long microseconds);
void make_truncated_value_warning(THD *thd, const char *str_val,
uint str_length, timestamp_type time_type);
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
const char *format_str,
uint format_length);
......
......@@ -305,6 +305,14 @@ ulong my_bind_addr; /* the address we bind to */
volatile ulong cached_thread_count= 0;
double log_10[32]; /* 10 potences */
ulonglong log_10_int[20]=
{
1, 10, 100, 1000, 10000UL, 100000UL, 1000000UL, 10000000UL,
100000000UL, 1000000000UL, 10000000000UL, 100000000000UL,
1000000000000UL, 10000000000000UL, 100000000000000UL,
1000000000000000UL, 10000000000000000UL, 100000000000000000UL,
1000000000000000000UL, 10000000000000000000UL
};
time_t start_time;
......
......@@ -304,3 +304,4 @@ character-set=latin2
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -298,3 +298,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -306,3 +306,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -300,3 +300,4 @@ character-set=latin7
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -307,3 +307,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=greek
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=latin2
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=ujis
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=euckr
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -299,3 +299,4 @@ character-set=latin2
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -296,3 +296,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -299,3 +299,4 @@ character-set=latin2
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=koi8r
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -289,3 +289,4 @@ character-set=cp1250
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working"
"The MySQL server is running with the %s option so it cannot execute this statement"
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -303,3 +303,4 @@ character-set=latin2
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -297,3 +297,4 @@ character-set=latin1
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -295,3 +295,4 @@ character-set=latin1
"MySQL är started i --skip-grant-tables mod. Pga av detta kan du inte använda detta program",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -300,3 +300,4 @@ character-set=koi8u
"The '%s' feature was disabled; you need MySQL built with '%s' to have it working",
"The MySQL server is running with the %s option so it cannot execute this statement",
"Column '%-.100s' has duplicated value '%-.64s' in %s"
"Truncated wrong %-.32s value: '%-.128s'"
......@@ -391,9 +391,11 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
ulong not_zero_date, allow_space;
bool is_internal_format;
const char *pos, *last_field_pos;
const char *str_begin= str;
const char *end=str+length;
const uchar *format_position;
bool found_delimitier= 0, found_space= 0;
uint frac_pos, frac_len;
DBUG_ENTER("str_to_TIME");
DBUG_PRINT("ENTER",("str: %.*s",length,str));
......@@ -482,7 +484,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
tmp_value=tmp_value*10 + (ulong) (uchar) (*str - '0');
str++;
}
date_len[i]+= (uint) (str - start);
date_len[i]= (uint) (str - start);
if (tmp_value > 999999) // Impossible date part
DBUG_RETURN(TIMESTAMP_NONE);
date[i]=tmp_value;
......@@ -535,9 +537,9 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
{
if (str+2 <= end && (str[1] == 'M' || str[1] == 'm'))
{
if (str[1] == 'p' || str[1] == 'P')
if (str[0] == 'p' || str[0] == 'P')
add_hours= 12;
else if (str[1] != 'a' || str[1] != 'A')
else if (str[0] != 'a' || str[0] != 'A')
continue; // Not AM/PM
str+= 2; // Skip AM/PM
/* Skip space after AM/PM */
......@@ -569,7 +571,13 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
l_time->hour= date[(uint) format_position[3]];
l_time->minute= date[(uint) format_position[4]];
l_time->second= date[(uint) format_position[5]];
l_time->second_part= date[(uint) format_position[6]];
frac_pos= (uint) format_position[6];
frac_len= date_len[frac_pos];
if (frac_len < 6)
date[frac_pos]*= (uint) log_10_int[6 - frac_len];
l_time->second_part= date[frac_pos];
if (format_position[7] != (uchar) 255)
{
if (l_time->hour > 12)
......@@ -585,6 +593,8 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
l_time->hour= date[3];
l_time->minute= date[4];
l_time->second= date[5];
if (date_len[6] < 6)
date[6]*= (uint) log_10_int[6 - date_len[6]];
l_time->second_part=date[6];
}
l_time->neg= 0;
......@@ -614,17 +624,19 @@ str_to_TIME(const char *str, uint length, TIME *l_time, uint flags)
current_thd->cuted_fields++;
goto err;
}
if (str != end && current_thd->count_cuted_fields)
{
l_time->time_type= (number_of_fields <= 3 ?
TIMESTAMP_DATE : TIMESTAMP_DATETIME);
for (; str != end ; str++)
{
if (!my_isspace(&my_charset_latin1,*str))
{
current_thd->cuted_fields++;
make_truncated_value_warning(current_thd, str_begin, length,
l_time->time_type);
break;
}
}
}
DBUG_RETURN(l_time->time_type=
(number_of_fields <= 3 ? TIMESTAMP_DATE : TIMESTAMP_DATETIME));
......@@ -686,6 +698,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
{
long date[5],value;
const char *end=str+length, *end_of_days;
const char *str_begin= str;
bool found_days,found_hours;
uint state;
......@@ -784,6 +797,8 @@ fractional:
my_isdigit(&my_charset_latin1,str[0]) &&
field_length--)
value=value*10 + (uint) (uchar) (*str - '0');
if (field_length)
value*= (long) log_10_int[field_length];
date[4]=value;
}
else
......@@ -796,12 +811,12 @@ fractional:
str++;
if (str+2 <= end && (str[1] == 'M' || str[1] == 'm'))
{
if (str[1] == 'p' || str[1] == 'P')
if (str[0] == 'p' || str[0] == 'P')
{
str+= 2;
date[1]= date[1]%12 + 12;
}
else if (str[1] == 'a' || str[1] == 'A')
else if (str[0] == 'a' || str[0] == 'A')
str+=2;
}
}
......@@ -822,13 +837,14 @@ fractional:
l_time->time_type= TIMESTAMP_TIME;
/* Check if there is garbage at end of the TIME specification */
if (str != end && current_thd->count_cuted_fields)
if (str != end)
{
do
{
if (!my_isspace(&my_charset_latin1,*str))
{
current_thd->cuted_fields++;
make_truncated_value_warning(current_thd, str_begin, length,
TIMESTAMP_TIME);
break;
}
} while (++str != end);
......@@ -1265,3 +1281,35 @@ void make_datetime(DATE_TIME_FORMAT *format, TIME *l_time, String *str)
str->length(length);
str->set_charset(&my_charset_bin);
}
void make_truncated_value_warning(THD *thd, const char *str_val,
uint str_length, timestamp_type time_type)
{
char warn_buff[MYSQL_ERRMSG_SIZE];
const char *type_str;
char buff[128];
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
str.append(str_val, str_length);
str.append('\0');
switch (time_type) {
case TIMESTAMP_DATE:
type_str= "date";
break;
case TIMESTAMP_DATETIME:
type_str= "datetime";
break;
case TIMESTAMP_TIME:
type_str= "time";
break;
default:
type_str= "string";
break;
}
sprintf(warn_buff, ER(ER_TRUNCATED_WRONG_VALUE),
type_str, str.ptr());
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TRUNCATED_WRONG_VALUE, warn_buff);
}
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