⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 type_datetime.test

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 TEST
字号:
## testing different DATETIME ranges#--disable_warningsdrop table if exists t1;--enable_warningscreate table t1 (t datetime);insert into t1 values (101),(691231),(700101),(991231),(10000101),(99991231),(101000000),(691231000000),(700101000000),(991231235959),(10000101000000),(99991231235959),(20030100000000),(20030000000000);select * from t1;delete from t1 where t > 0;optimize table t1;check table t1;delete from t1;insert into t1 values("000101"),("691231"),("700101"),("991231"),("00000101"),("00010101"),("99991231"),("00101000000"),("691231000000"),("700101000000"),("991231235959"),("10000101000000"),("99991231235959"),("20030100000000"),("20030000000000");# Strange datesinsert into t1 values ("2003-003-03");# Bug #7308: ISO-8601 date format not handled correctlyinsert into t1 values ("20030102T131415"),("2001-01-01T01:01:01"), ("2001-1-1T1:01:01");select * from t1;# Test some wrong datestruncate table t1;insert into t1 values("2003-0303 12:13:14");select * from t1;drop table t1;## Test insert of now() and curtime()#CREATE TABLE t1 (a timestamp, b date, c time, d datetime);insert into t1 (b,c,d) values(now(),curtime(),now());select date_format(a,"%Y-%m-%d")=b,right(a+0,6)=c+0,a=d+0 from t1;drop table t1;## Test of datetime and not null#CREATE TABLE t1 (a datetime not null);insert into t1 values (0);select * from t1 where a is null;drop table t1;## Test with bug when propagating DATETIME to integer and WHERE optimization#create table t1 (id int, dt datetime);insert into t1 values (1,"2001-08-14 00:00:00"),(2,"2001-08-15 00:00:00"),(3,"2001-08-16 00:00:00"),(4,"2003-09-15 01:20:30");select * from t1 where dt='2001-08-14 00:00:00' and dt =  if(id=1,'2001-08-14 00:00:00','1999-08-15');create index dt on t1 (dt);select * from t1 where dt > 20021020;select * from t1 ignore index (dt) where dt > 20021020;drop table t1;## Test of datetime optimization#CREATE TABLE `t1` (  `date` datetime NOT NULL default '0000-00-00 00:00:00',  `numfacture` int(6) unsigned NOT NULL default '0',  `expedition` datetime NOT NULL default '0000-00-00 00:00:00',  PRIMARY KEY  (`numfacture`),  KEY `date` (`date`),  KEY `expedition` (`expedition`)) ENGINE=MyISAM;INSERT INTO t1 (expedition) VALUES ('0001-00-00 00:00:00');SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';INSERT INTO t1 (numfacture,expedition) VALUES ('1212','0001-00-00 00:00:00');SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';drop table t1;create table t1 (a datetime not null, b datetime not null);insert into t1 values (now(), now());insert into t1 values (now(), now());select * from t1 where a is null or b is null;drop table t1;## Let us check if we properly treat wrong datetimes and produce proper# warnings (for both strings and numbers)#create table t1 (t datetime);insert into t1 values (20030102030460),(20030102036301),(20030102240401),                      (20030132030401),(20031302030401),(100001202030401);select * from t1;delete from t1;insert into t1 values  ("2003-01-02 03:04:60"),("2003-01-02 03:63:01"),("2003-01-02 24:04:01"),  ("2003-01-32 03:04:01"),("2003-13-02 03:04:01"), ("10000-12-02 03:04:00");select * from t1;delete from t1;insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");select * from t1;drop table t1;## Test for bug #7297 "Two digit year should be interpreted correctly even# with zero month and day"#create table t1 (dt datetime);# These dates should be treated as dates in 21st centuryinsert into t1 values ("12-00-00"), ("00-00-00 01:00:00");# Zero dates are still special :/insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");select * from t1;drop table t1;## Bug #16546 DATETIME+0 not always coerced the same way #select cast('2006-12-05 22:10:10' as datetime) + 0;# End of 4.1 tests## Bug#21475: Wrongly applied constant propagation leads to a false comparison.#CREATE TABLE t1(a DATETIME NOT NULL);INSERT INTO t1 VALUES ('20060606155555');SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555");PREPARE s FROM 'SELECT a FROM t1 WHERE a=(SELECT MAX(a) FROM t1) AND (a="20060606155555")';EXECUTE s;DROP PREPARE s;DROP TABLE t1;## Bug 19491 (CAST DATE AS DECIMAL returns incorrect result#SELECT CAST(CAST('2006-08-10' AS DATE) AS DECIMAL(20,6));SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) AS DECIMAL(20,6));SELECT CAST(CAST('2006-08-10 10:11:12' AS DATETIME) + INTERVAL 14 MICROSECOND AS DECIMAL(20,6));SELECT CAST(CAST('10:11:12.098700' AS TIME) AS DECIMAL(20,6));## Test of storing datetime into date fields#set @org_mode=@@sql_mode;create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03');show create table t1;insert into t1 values ();insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');set @@sql_mode='ansi,traditional';insert into t1 values ('2007-03-23 13:49:38','2007-03-23 13:49:38');insert into t1 set dt='2007-03-23 13:49:38',da=dt;# Test error handling--error 1292insert into t1 values ('2007-03-32','2007-03-23 13:49:38');select * from t1;drop table t1;--error 1067create table t1 (da date default '1962-03-32 23:33:34', dt datetime default '1962-03-03');--error 1067create table t1 (t time default '916:00:00 a');set @@sql_mode= @org_mode;## Bug#27590: Wrong DATE/DATETIME comparison.  #create table t1 (f1 date, f2 datetime, f3 timestamp);insert into t1(f1) values(curdate());select curdate() < now(), f1 < now(), cast(f1 as date) < now() from t1;delete from t1;insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');select f1, f3 from t1 where f1 >= '2001-02-05 00:00:00' and f3 <= '2001-04-15';select f1, f3 from t1 where f1 >= '2001-2-5 0:0:0' and f2 <= '2001-4-15';select f1, f2 from t1 where if(1, f1, 0) >= f2;select 1 from dual where cast('2001-1-1 2:3:4' as date) = cast('2001-01-01' as datetime);select f1, f2, f1 > f2, f1 = f2, f1 < f2 from t1;drop table t1;## Bug#16377: Wrong DATE/DATETIME comparison in BETWEEN function.#create table t1 (f1 date, f2 datetime, f3 timestamp);insert into t1 values('2001-01-01','2001-01-01 01:01:01','2001-01-01 01:01:01');insert into t1 values('2001-02-05','2001-02-05 00:00:00','2001-02-05 01:01:01');insert into t1 values('2001-03-10','2001-03-09 01:01:01','2001-03-10 01:01:01');insert into t1 values('2001-04-15','2001-04-15 00:00:00','2001-04-15 00:00:00');insert into t1 values('2001-05-20','2001-05-20 01:01:01','2001-05-20 01:01:01');select f2 from t1 where f2 between '2001-2-5' and '01-04-14';select f1, f2, f3 from t1 where f1 between f2 and f3;select f1, f2, f3 from t1 where cast(f1 as datetime) between f2 and  cast(f3 as date);select f2 from t1 where '2001-04-10 12:34:56' between f2 and '01-05-01';select f2, f3 from t1 where '01-03-10' between f2 and f3;select f2 from t1 where DATE(f2) between "2001-4-15" AND "01-4-15";SELECT 1 from dual where NOW() BETWEEN CURRENT_DATE() - INTERVAL 1 DAY AND CURRENT_DATE();drop table t1;## Bug#28133: Wrong DATE/DATETIME comparison in IN() function.#create table t1 (f1 date);insert into t1 values('01-01-01'),('01-01-02'),('01-01-03');select * from t1 where f1 in ('01-01-01','2001-01-02','2001-01-03 00:00:00');create table t2(f2 datetime);insert into t2 values('01-01-01 00:00:00'),('01-02-03 12:34:56'),('02-04-06 11:22:33');select * from t2 where f2 in ('01-01-01','01-02-03 12:34:56','01-02-03');select * from t1,t2 where '01-01-02' in (f1, cast(f2 as date));select * from t1,t2 where '01-01-01' in (f1, '01-02-03');select * from t1,t2 where if(1,'01-02-03 12:34:56','') in (f1, f2);create table t3(f3 varchar(20));insert into t3 select * from t2;select * from t2,t3 where f2 in (f3,'03-04-05');select f1,f2,f3 from t1,t2,t3 where (f1,'1') in ((f2,'1'),(f3,'1'));select f1 from t1 where ('1',f1) in (('1','01-01-01'),('1','2001-1-1 0:0:0'),('1','02-02-02'));drop table t1,t2,t3;## Bug#27759: Wrong DATE/DATETIME comparison in LEAST()/GREATEST() functions.#select least(cast('01-01-01' as date), '01-01-02');select greatest(cast('01-01-01' as date), '01-01-02');select least(cast('01-01-01' as date), '01-01-02') + 0;select greatest(cast('01-01-01' as date), '01-01-02') + 0;select least(cast('01-01-01' as datetime), '01-01-02') + 0;select cast(least(cast('01-01-01' as datetime), '01-01-02') as signed);select cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(20,2));--disable_warningsDROP PROCEDURE IF EXISTS test27759 ;--enable_warningsDELIMITER |;CREATE PROCEDURE test27759()BEGINdeclare v_a date default '2007-4-10';declare v_b date default '2007-4-11';declare v_c datetime default '2004-4-9 0:0:0';select v_a as a,v_b as b,       least( v_a, v_b ) as a_then_b,       least( v_b, v_a ) as b_then_a,       least( v_c, v_a ) as c_then_a;END;|DELIMITER ;|call test27759();drop procedure test27759;## Bug#28208: Wrong result of a non-const STRING function with a const#            DATETIME function.#create table t1 (f1 date);insert into t1 values (curdate());select left(f1,10) = curdate() from t1;drop table t1;## Bug#28261: Wrong DATETIME comparison result when the GET_USER_VAR function#            is involved.#create table t1(f1 date);insert into t1 values('01-01-01'),('02-02-02'),('01-01-01'),('02-02-02');set @bug28261='';select if(@bug28261 = f1, '', @bug28261:= f1) from t1;select if(@bug28261 = f1, '', @bug28261:= f1) from t1;select if(@bug28261 = f1, '', @bug28261:= f1) from t1;drop table t1;## Bug#28778: Wrong result of BETWEEN when comparing a DATETIME field with an#            integer constants.#create table t1(f1 datetime);insert into t1 values('2001-01-01'),('2002-02-02');select * from t1 where f1 between 20020101 and 20070101000000;select * from t1 where f1 between 2002010 and 20070101000000;select * from t1 where f1 between 20020101 and 2007010100000;drop table t1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -