diff options
author | monty@narttu.mysql.fi <> | 2003-11-03 14:01:59 +0200 |
---|---|---|
committer | monty@narttu.mysql.fi <> | 2003-11-03 14:01:59 +0200 |
commit | a444a3449f87ad4c8060fe5769c0bae7a1b64eaf (patch) | |
tree | f9406690fb9f579e21f4877826d439fb785d6902 /mysql-test/t/date_formats.test | |
parent | d9eca0e1271a5d8c9305ca1b7b9eada084cb61dc (diff) | |
download | mariadb-git-a444a3449f87ad4c8060fe5769c0bae7a1b64eaf.tar.gz |
Simplified 'wrong xxx name' error messages by introducing 'general' ER_WRONG_NAME error
Cleaned up (and disabled part of) date/time/datetime format patch. One can't anymore change default read/write date/time/formats.
This is becasue the non standard datetime formats can't be compared as strings and MySQL does still a lot of datetime comparisons as strings
Changed flag argument to str_to_TIME() and get_date() from bool to uint
Removed THD from str_to_xxxx functions and Item class.
Fixed core dump when doing --print-defaults
Move some common string functions to strfunc.cc
Dates as strings are now of type my_charset_bin instead of default_charset()
Introduce IDENT_QUOTED to not have to create an extra copy of simple identifiers (all chars < 128)
Removed xxx_FORMAT_TYPE enums and replaced them with the old TIMESTAMP_xxx enums
Renamed some TIMESTAMP_xxx enums to more appropriate names
Use defines instead of integers for date/time/datetime string lengths
Added to build system and use the new my_strtoll10() function.
Diffstat (limited to 'mysql-test/t/date_formats.test')
-rw-r--r-- | mysql-test/t/date_formats.test | 253 |
1 files changed, 186 insertions, 67 deletions
diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 9551efaa648..f174e61d164 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -1,82 +1,201 @@ +# +# Test of date format functions +# + +--disable-warnings +drop table if exists t1; +--enable-warnings + SHOW GLOBAL VARIABLES LIKE "%_format%"; SHOW SESSION VARIABLES LIKE "%_format%"; -SET date_format="%d.%m.%Y"; -select CAST("01.01.2001" as DATE) as a; -SET datetime_format="%d.%m.%Y %H.%i.%s"; -select CAST("01.01.2001 05.12.06" as DATETIME) as a; -SET time_format="%H.%i.%s"; -select CAST("05.12.06" as TIME) as a; - -SET datetime_format="%d.%m.%Y %h:%i:%s %p"; -select CAST("01.01.2001 05:12:06AM" as DATETIME) as a; -select CAST("01.01.2001 05:12:06 PM" as DATETIME) as a; - -SET time_format="%h:%i:%s %p"; -select CAST("05:12:06 AM" as TIME) as a; -select CAST("05:12:06.1234PM" as TIME) as a; - -SET time_format="%h.%i.%s %p"; -SET date_format='%d.%m.%y'; -SET datetime_format="%d.%m.%y %h.%i.%s %p"; -select CAST("12-12-06" as DATE) as a; - -select adddate("01.01.97 11.59.59.000001 PM", 10); -select datediff("31.12.97 11.59:59.000001 PM","01.01.98"); -select weekofyear("31.11.97 11:59:59.000001 PM"); -select makedate(1997,1); -select addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"); -select maketime(23,11,12); -select timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"); - -SET time_format="%H%i%s"; ---error 1105 -SET time_format="%h%i%s"; ---error 1105 +# +# Test setting a lot of different formats to see which formats are accepted and +# which aren't +# + +SET time_format='%H%i%s'; +SET time_format='%H:%i:%s.%f'; +SET time_format='%h-%i-%s.%f%p'; +SET time_format='%h:%i:%s.%f %p'; +SET time_format='%h:%i:%s%p'; + +SET date_format='%Y%m%d'; +SET date_format='%Y.%m.%d'; +SET date_format='%d.%m.%Y'; +SET date_format='%m-%d-%Y'; + +set datetime_format= '%Y%m%d%H%i%s'; +set datetime_format= '%Y-%m-%d %H:%i:%s'; +set datetime_format= '%m-%d-%y %H:%i:%s.%f'; +set datetime_format= '%d-%m-%Y %h:%i:%s%p'; +set datetime_format= '%H:%i:%s %Y-%m-%d'; +set datetime_format= '%H:%i:%s.%f %m-%d-%Y'; +set datetime_format= '%h:%i:%s %p %Y-%m-%d'; +set datetime_format= '%h:%i:%s.%f %p %Y-%m-%d'; + +SHOW SESSION VARIABLES LIKE "%format"; + +--error 1231 +SET time_format='%h:%i:%s'; +--error 1231 +SET time_format='%H %i:%s'; +--error 1231 +SET time_format='%H::%i:%s'; +--error 1231 +SET time_format='%H:%i:%s%f'; +--error 1231 +SET time_format='%H:%i.%f:%s'; +--error 1231 +SET time_format='%H:%i:%s%p'; +--error 1231 +SET time_format='%h:%i:%s.%f %p %Y-%m-%d'; +--error 1231 +SET time_format='%H%i%s.%f'; +--error 1231 +SET time_format='%H:%i-%s.%f'; +--error 1231 SET date_format='%d.%m.%d'; ---error 1105 -SET datetime_format="%d.%m.%y %h.%i.%s"; +--error 1231 +SET datetime_format='%h.%m.%y %d.%i.%s'; +--error 1231 +set datetime_format= '%H:%i:%s.%f %p %Y-%m-%d'; + +# +# Test GLOBAL values + +set GLOBAL datetime_format= '%H:%i:%s %Y-%m-%d'; +SET SESSION datetime_format=default; +select @@global.datetime_format, @@session.datetime_format; +SET GLOBAL datetime_format=default; +SET SESSION datetime_format=default; +select @@global.datetime_format, @@session.datetime_format; SET GLOBAL date_format=default; -SHOW GLOBAL VARIABLES LIKE "date_format%"; SET GLOBAL time_format=default; -SHOW GLOBAL VARIABLES LIKE "time_format%"; SET GLOBAL datetime_format=default; -SHOW GLOBAL VARIABLES LIKE "datetime_format%"; - -SET date_format=default; -SHOW SESSION VARIABLES LIKE "date_format%"; SET time_format=default; -SHOW SESSION VARIABLES LIKE "time_format%"; +SET date_format=default; SET datetime_format=default; -SHOW SESSION VARIABLES LIKE "datetime_format%"; - -SET time_format='%i:%s:%H'; -select cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME); - -SET GLOBAL date_format='%Y-%m-%d'; -SET GLOBAL time_format='%H:%i:%s'; -SET GLOBAL datetime_format='%Y-%m-%d %H:%i:%s'; -SET date_format='%Y-%m-%d'; -SET time_format='%H:%i:%s'; -SET datetime_format='%Y-%m-%d %H:%i:%s'; - -select str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S"); -select str_to_date("15 September 2001", "%d %M %Y"); -select str_to_date("15 Septembeb 2001", "%d %M %Y"); -select str_to_date("15 MAY 2001", "%d %b %Y"); -select str_to_date("Sunday 15 MAY 2001", "%W %d %b %Y"); -select str_to_date("Sundai 15 MAY 2001", "%W %d %b %Y"); -select str_to_date("Sundai 15 MA", "%W %d %b %Y"); -select str_to_date("Tuesday 52 2001", "%W %V %X"); -select str_to_date("Sunday 01 2001", "%W %V %X"); -select str_to_date("Tuesday 00 2002", "%W %U %Y"); -select str_to_date("Thursday 53 1998", "%W %u %Y"); -select str_to_date("15-01-2001", "%d-%m-%Y %H:%i:%S"); -select str_to_date("15-01-20", "%d-%m-%Y"); -select str_to_date("15-2001-1", "%d-%Y-%c"); + +# +# The following tests will work only when we at some point will enable +# dynamic changing of formats +# + +# SET date_format='%d.%m.%Y'; +# select CAST('01.01.2001' as DATE) as a; +# SET datetime_format='%d.%m.%Y %H.%i.%s'; +# select CAST('01.01.2001 05.12.06' as DATETIME) as a; +# SET time_format='%H.%i.%s'; +# select CAST('05.12.06' as TIME) as a; +# +# SET datetime_format='%d.%m.%Y %h:%i:%s %p'; +# select CAST('01.01.2001 05:12:06AM' as DATETIME) as a; +# select CAST('01.01.2001 05:12:06 PM' as DATETIME) as a; +# +# SET time_format='%h:%i:%s %p'; +# select CAST('05:12:06 AM' as TIME) as a; +# select CAST('05:12:06.1234PM' as TIME) as a; +# +# SET time_format='%h.%i.%s %p'; +# SET date_format='%d.%m.%y'; +# SET datetime_format='%d.%m.%y %h.%i.%s %p'; +# select CAST('12-12-06' as DATE) as a; +# +# select adddate('01.01.97 11.59.59.000001 PM', 10); +# select datediff('31.12.97 11.59:59.000001 PM','01.01.98'); +# select weekofyear('31.11.97 11:59:59.000001 PM'); +# select makedate(1997,1); +# select addtime('31.12.97 11.59.59.999999 PM', '1 1.1.1.000002'); +# select maketime(23,11,12); +# select timediff('01.01.97 11:59:59.000001 PM','31.12.95 11:59:59.000002 PM'); +# +# SET time_format='%i:%s:%H'; +# select cast(str_to_date('15-01-2001 12:59:59', '%d-%m-%Y %H:%i:%S') as TIME); + +# +# Test of str_to_date +# + +select str_to_date(concat('15-01-2001',' 2:59:58.999'), + concat('%d-%m-%Y',' ','%H:%i:%s.%f')); + +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'), +('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'), +('2003-01-02 12:11:12.12345 am', '%Y-%m-%d %h:%i:%S.%f%p'), +('2003-01-02 11:11:12Pm', '%Y-%m-%d %h:%i:%S%p'), +('10:20:10', '%H:%i:%s'), +('10:20:10', '%h:%i:%s.%f'), +('10:20:10AM', '%h:%i:%s%p'), +('10:20:10.44AM', '%h:%i:%s.%f%p'), +('15-01-2001 12:59:58', '%d-%m-%Y %H:%i:%S'), +('15 September 2001', '%d %M %Y'), +('15 SEPTEMB 2001', '%d %M %Y'), +('15 MAY 2001', '%d %b %Y'), +('Sunday 15 MAY 2001', '%W %d %b %Y'), +('Sund 15 MAY 2001', '%W %d %b %Y'), +('Tuesday 00 2002', '%W %U %Y'), +('Thursday 53 1998', '%W %u %Y'), +('15-01-2001', '%d-%m-%Y %H:%i:%S'), +('15-01-20', '%d-%m-%y'), +('15-2001-1', '%d-%Y-%c'); + +# Use through protocol functions +select date,format,str_to_date(date, format) as str_to_date from t1; +# Use as a string +select date,format,concat('',str_to_date(date, format)) as con from t1; +# Use as datetime +select date,format,cast(str_to_date(date, format) as datetime) as datetime from t1; +select date,format,DATE(str_to_date(date, format)) as date2 from t1; +select date,format,TIME(str_to_date(date, format)) as time from t1; +select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1; + +# Test wrong dates + +truncate table t1; +insert into t1 values +('2003-01-02 10:11:12 PM', '%Y-%m-%d %H:%i:%S %p'), +('2003-01-02 10:11:12.123456', '%Y-%m-%d %h:%i:%S %p'), +('2003-01-02 10:11:12AM', '%Y-%m-%d %h:%i:%S.%f %p'), +('2003-01-02 10:11:12AN', '%Y-%m-%d %h:%i:%S%p'), +('2003-01-02 10:11:12 PM', '%y-%m-%d %H:%i:%S %p'), +('10:20:10AM', '%H:%i:%s%p'), +('15 Septembei 2001', '%d %M %Y'), +('15 Ju 2001', '%d %M %Y'), +('Sund 15 MA', '%W %d %b %Y'), +('Sunday 01 2001', '%W %V %X'), +('Thursdai 12 1998', '%W %u %Y'), +(NULL, get_format(DATE,'USA')), +('Tuesday 52 2001', '%W %V %X'); +select date,format,str_to_date(date, format) as str_to_date from t1; +select date,format,concat(str_to_date(date, format),'') as con from t1; + +# Test 'maybe' date formats and 'strange but correct' results + +truncate table t1; +insert into t1 values +('10:20:10AM', '%h:%i:%s'), +('2003-01-02 10:11:12', '%Y-%m-%d %h:%i:%S'), +('03-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'); + +select date,format,str_to_date(date, format) as str_to_date from t1; +select date,format,concat(str_to_date(date, format),'') as con from t1; + +drop table t1; + +# +# Test of get_format +# select get_format(DATE, 'USA') as a; select get_format(TIME, 'internal') as a; select get_format(DATETIME, 'eur') as a; +select get_format(DATE, 'TEST') as a; +select str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA')); |