1792
1792
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
1793
1793
CREATE TABLE t2 ( hmid int default NULL, volid int default NULL, sampletid int default NULL, sampletime datetime default NULL, samplevalue bigint default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
1794
1794
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
1795
# Disable PS becasue we get more warnings from PS than from normal execution
1796
--disable_ps_protocol
1795
--error 1686 # bad datetime
1797
1796
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1798
--enable_ps_protocol
1799
1797
# Testing the same select with NULL's instead of invalid datetime values
1800
1798
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1801
1799
DROP TABLE t1,t2;
3296
3299
# Bug#31800: Date comparison fails with timezone and slashes for greater
3297
3300
# than comparison
3303
# @TODO Commenting all str_to_date out for now...should move to a plugin.
3300
3305
# On DATETIME-like literals with trailing garbage, BETWEEN fudged in a
3301
3306
# DATETIME comparator, while greater/less-than used bin-string comparisons.
3302
3307
# Should correctly be compared as DATE or DATETIME, but throw a warning:
3304
select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3305
and '2007/10/20 00:00:00 GMT';
3306
select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3307
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
3309
#select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3310
# and '2007/10/20 00:00:00 GMT';
3311
#select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3312
#select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
3309
3314
# We have all we need -- and trailing garbage:
3310
3315
# (leaving out a leading zero in first example to prove it's a
3311
3316
# value-comparison, not a string-comparison!)
3312
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3313
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3314
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3315
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
3317
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3318
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3319
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3320
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
3316
3321
# no time at all:
3317
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3322
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3318
3323
# partial time:
3319
select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3324
#select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3320
3325
# fail, different second part:
3321
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3326
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3322
3327
# correct syntax, no trailing nonsense -- this one must throw no warning:
3323
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3328
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3324
3329
# no warning, but failure (different hour parts):
3325
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3330
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3327
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3332
#select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3328
3333
# succeed, but warn for "trailing garbage" (":34"):
3329
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3334
#select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3330
3335
# invalid date (Feb 30) succeeds
3331
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3336
#select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3332
3337
# 0-day for both, just works in default SQL mode.
3333
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3338
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3334
3339
# 0-day, succeed
3335
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3336
and '2007/10/20 00:00:00';
3337
select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3338
select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3339
select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3340
select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3341
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
3340
#select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3341
# and '2007/10/20 00:00:00';
3342
#select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3343
#select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3344
#select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3345
#select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3346
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
3343
select str_to_date('1','%Y-%m-%d') = '1';
3344
select str_to_date('1','%Y-%m-%d') = '1';
3345
select str_to_date('','%Y-%m-%d') = '';
3348
#select str_to_date('1','%Y-%m-%d') = '1';
3349
#select str_to_date('1','%Y-%m-%d') = '1';
3350
#select str_to_date('','%Y-%m-%d') = '';
3347
3352
# these three should work!
3348
select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3349
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3350
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
3353
#select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3354
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3355
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
3351
3356
###########################################################################