type_date.test
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #
  2. # test of problem with date fields
  3. #
  4. --disable_warnings
  5. drop table if exists t1,t2;
  6. --enable_warnings
  7. create table t1 (a char(16), b date, c datetime);
  8. insert into t1 SET a='test 2000-01-01', b='2000-01-01', c='2000-01-01';
  9. select * from t1 where c = '2000-01-01';
  10. select * from t1 where b = '2000-01-01';
  11. drop table t1;
  12. #
  13. # problem with date conversions
  14. #
  15. CREATE TABLE t1 (name char(6),cdate date);
  16. INSERT INTO t1 VALUES ('name1','1998-01-01');
  17. INSERT INTO t1 VALUES ('name2','1998-01-01');
  18. INSERT INTO t1 VALUES ('name1','1998-01-02');
  19. INSERT INTO t1 VALUES ('name2','1998-01-02');
  20. CREATE TABLE t2 (cdate date, note char(6));
  21. INSERT INTO t2 VALUES ('1998-01-01','note01');
  22. INSERT INTO t2 VALUES ('1998-01-02','note02');
  23. select name,t1.cdate,note from t1,t2 where t1.cdate=t2.cdate and t1.cdate='1998-01-01';
  24. drop table t1,t2;
  25. #
  26. # Date and BETWEEN
  27. #
  28. CREATE TABLE t1 ( datum DATE );
  29. INSERT INTO t1 VALUES ( "2000-1-1" );
  30. INSERT INTO t1 VALUES ( "2000-1-2" );
  31. INSERT INTO t1 VALUES ( "2000-1-3" );
  32. INSERT INTO t1 VALUES ( "2000-1-4" );
  33. INSERT INTO t1 VALUES ( "2000-1-5" );
  34. SELECT * FROM t1 WHERE datum BETWEEN "2000-1-2" AND "2000-1-4";
  35. SELECT * FROM t1 WHERE datum BETWEEN "2000-1-2" AND datum - INTERVAL 100 DAY;
  36. DROP TABLE t1;
  37. #
  38. # test of max(date) and having
  39. #
  40. CREATE TABLE t1 (
  41.   user_id char(10),
  42.   summa int(11),
  43.   rdate date
  44. );
  45. INSERT INTO t1 VALUES ('aaa',100,'1998-01-01');
  46. INSERT INTO t1 VALUES ('aaa',200,'1998-01-03');
  47. INSERT INTO t1 VALUES ('bbb',50,'1998-01-02');
  48. INSERT INTO t1 VALUES ('bbb',200,'1998-01-04');
  49. select max(rdate) as s from t1 where rdate < '1998-01-03' having s> "1998-01-01";
  50. select max(rdate) as s from t1 having s="1998-01-04";
  51. select max(rdate+0) as s from t1 having s="19980104";
  52. drop table t1;
  53. #
  54. # Test of date and not null
  55. #
  56. create table t1 (date date);  
  57. insert into t1 values ("2000-08-10"),("2000-08-11");
  58. select date_add(date,INTERVAL 1 DAY),date_add(date,INTERVAL 1 SECOND) from t1;
  59. drop table t1;
  60. #
  61. # Test problem with DATE_FORMAT
  62. #
  63. CREATE TABLE t1(AFIELD INT);
  64. INSERT INTO t1 VALUES(1);
  65. CREATE TABLE t2(GMT  VARCHAR(32));
  66. INSERT INTO t2 VALUES('GMT-0800');
  67. SELECT DATE_FORMAT("2002-03-06 10:11:12", CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)) FROM t1, t2 GROUP BY t1.AFIELD;
  68. INSERT INTO t1 VALUES(1);
  69. SELECT DATE_FORMAT("2002-03-06 10:11:12", CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)), DATE_FORMAT("2002-03-06 10:11:12",  CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)) FROM t1,t2 GROUP BY t1.AFIELD;
  70. drop table t1,t2;
  71. #
  72. # Multiple SELECT DATE_FORMAT gave incorrect results (Bug #4036)
  73. #
  74. CREATE TABLE t1 (f1 time default NULL, f2 time default NULL);
  75. INSERT INTO t1 (f1, f2) VALUES ('09:00', '12:00');
  76. SELECT DATE_FORMAT(f1, "%l.%i %p") , DATE_FORMAT(f2, "%l.%i %p") FROM t1;
  77. DROP TABLE t1;
  78. #
  79. # Bug 4937: different date -> string conversion when using SELECT ... UNION
  80. # and INSERT ... SELECT ... UNION
  81. #
  82. CREATE TABLE t1 (f1 DATE);
  83. CREATE TABLE t2 (f2 VARCHAR(8));
  84. CREATE TABLE t3 (f2 CHAR(8));
  85. INSERT INTO t1 VALUES ('1978-11-26');
  86. INSERT INTO t2 SELECT f1+0 FROM t1;
  87. INSERT INTO t2 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
  88. INSERT INTO t3 SELECT f1+0 FROM t1;
  89. INSERT INTO t3 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
  90. SELECT * FROM t2;
  91. SELECT * FROM t3;
  92. DROP TABLE t1, t2, t3;
  93. # Test that setting YEAR to invalid string results in default value, not
  94. # 2000. (Bug #6067)
  95. CREATE TABLE t1 (y YEAR);
  96. INSERT INTO t1 VALUES ('abc');
  97. SELECT * FROM t1;
  98. DROP TABLE t1;
  99. # End of 4.1 tests