~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of cast function
3
#
4
5
#
6
# Bug #28250: Run-Time Check Failure #3 - The variable 'value' is being used 
7
# without being def
8
# 
9
# The following line causes Run-Time Check Failure on 
10
# binaries built with Visual C++ 2005
11
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
12
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
13
select cast("1:2:3" as TIME);
14
select CONVERT("2004-01-22 21:45:33",DATE);
15
select 10+'10';
16
select 10.0+'10';
17
select 10E+0+'10';
18
19
# The following cast creates warnings
20
21
select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
22
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
23
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
24
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
25
select 10+'a';
26
select 10.0+cast('a' as decimal);
27
select 10E+0+'a';
28
29
#
30
# CAST to CHAR with/without length
31
#
32
select
685.2.5 by Monty Taylor
Fixed up the cast test.
33
  cast('ab'  AS char)    as c1,
34
  cast('a '  AS char)    as c2,
35
  cast('abc' AS char(2)) as c3,
36
  cast('a  ' AS char(2)) as c4,
37
  hex(cast('a'   AS char(2))) as c5;
1 by brian
clean slate
38
select cast(1000 as CHAR(3));
39
685.2.5 by Monty Taylor
Fixed up the cast test.
40
# Should throw an error about 'abc' being too large for a char(2)
41
--error 1292
1 by brian
clean slate
42
create table t1 select
685.2.5 by Monty Taylor
Fixed up the cast test.
43
  cast('ab'  AS char)    as c1,
44
  cast('a '  AS char)    as c2,
45
  cast('abc' AS char(2)) as c3,
46
  cast('a  ' AS char(2)) as c4,
47
  cast('a'   AS char(2)) as c5;
1 by brian
clean slate
48
49
#
50
# CAST to NCHAR with/without length
51
#
52
select
685.2.5 by Monty Taylor
Fixed up the cast test.
53
  cast('ÆÇ'  AS char)    as c1,
54
  cast('Æ '  AS char)    as c2,
55
  cast('ÆÇÈ' AS char(2)) as c3,
56
  cast('Æ  ' AS char(2)) as c4,
57
  cast('Æ'   AS char(2)) as c5;
58
59
# BUG in drizzletest - can't handle these chars right
60
# # Should throw an error about incorrect
61
#--error 1292
62
#create table t1 select
63
#  cast('ÆÇ'  AS char)    as c1,
64
#  cast('Æ '  AS char)    as c2,
65
#  cast('ÆÇÈ' AS char(2)) as c3,
66
#  cast('Æ  ' AS char(2)) as c4,
67
#  cast('Æ'   AS char(2)) as c5;
1 by brian
clean slate
68
69
#
70
# The following should be fixed in 4.1
71
#
72
73
select cast("2001-1-1" as date) = "2001-01-01";
74
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
75
select cast("1:2:3" as TIME) = "1:02:03";
76
select cast(NULL as DATE);
77
select cast(NULL as BINARY);
78
79
#
80
# Bug #5228 ORDER BY CAST(enumcol) sorts incorrectly under certain conditions
81
#
82
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
83
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
685.2.5 by Monty Taylor
Fixed up the cast test.
84
# should be in enum order
1 by brian
clean slate
85
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
685.2.5 by Monty Taylor
Fixed up the cast test.
86
# should be in alphabetic order
1 by brian
clean slate
87
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
88
DROP TABLE t1;
89
90
#
91
# Test for bug #6914 "Problems using time()/date() output in expressions".
92
# When we are casting datetime value to DATE/TIME we should throw away
93
# time/date parts (correspondingly).
94
#
95
select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour);
96
select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');
97
# Still we should not throw away "days" part of time value
98
select timediff(cast('1 12:00:00' as time), '12:00:00');
99
100
#
101
# Bug #23938: cast(NULL as DATE)
102
#
103
104
select isnull(date(NULL)), isnull(cast(NULL as DATE));
105
106
107
108
#decimal-related additions
109
select cast('1.2' as decimal(3,2));
110
select 1e18 * cast('1.2' as decimal(3,2));
111
set @v1=1e18;
112
select cast(@v1 as decimal(22, 2));
113
select cast(-1e18 as decimal(22,2));
114
115
create table t1(s1 time);
116
insert into t1 values ('11:11:11');
117
select cast(s1 as decimal(7,2)) from t1;
118
drop table t1;
119
120
#
121
# Test for bug #11283: field conversion from varchar, and text types to decimal
122
#
123
124
CREATE TABLE t1 (v varchar(10), tt tinytext, t text,
125
                 mt mediumtext, lt longtext);
126
INSERT INTO t1 VALUES ('1.01', '2.02', '3.03', '4.04', '5.05');
127
128
SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL),
129
       CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1;
130
131
DROP TABLE t1;
132
133
#
134
# Bug #10237 (CAST(NULL DECIMAL) crashes server)
135
#
136
select cast(NULL as decimal(6)) as t1;
137
138
139
#
140
# Bug #17903: cast to char results in binary
141
#
142
select hex(cast('a' as char(2) binary));
143
select hex(cast('a' as binary(2)));
144
select hex(cast('a' as char(2) binary));
145
146
147
#
148
# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
149
#
150
151
# Show that HH:MM:SS of a DATE are 0, and that it's the same for columns
152
# and typecasts (NULL in, NULL out).
153
CREATE TABLE t1 (f1 DATE);
154
INSERT INTO t1 VALUES ('2007-07-19'), (NULL);
155
SELECT HOUR(f1),
156
       MINUTE(f1),
157
       SECOND(f1) FROM t1;
158
SELECT HOUR(CAST('2007-07-19' AS DATE)),
159
       MINUTE(CAST('2007-07-19' AS DATE)),
160
       SECOND(CAST('2007-07-19' AS DATE));
161
SELECT HOUR(CAST(NULL AS DATE)),
162
       MINUTE(CAST(NULL AS DATE)),
163
       SECOND(CAST(NULL AS DATE));
164
SELECT HOUR(NULL),
165
       MINUTE(NULL),
166
       SECOND(NULL);
167
DROP TABLE t1;
168
169
--echo End of 5.0 tests