~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/cast.test

pandora-build v0.72 - Moved remaining hard-coded tests into pandora-build
macros.
Add PANDORA_DRIZZLE_BUILD to run the extra checks that drizzle needs that 
plugins would also need to run so we can just use that macro in generated
external plugin builds.
Added support to register_plugins for external plugin building.
Renamed register_plugins.py to pandora-plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# Test of cast function
3
3
#
4
4
 
5
 
select CAST(1-2 AS UNSIGNED);
6
 
select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER);
7
 
select CAST('10 ' as unsigned integer);
8
 
select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1;
9
 
select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1;
10
 
select ~5, cast(~5 as signed);
11
 
explain extended select ~5, cast(~5 as signed);
12
 
select cast(5 as unsigned) -6.0;
13
 
select cast(NULL as signed), cast(1/0 as signed);
14
5
#
15
6
# Bug #28250: Run-Time Check Failure #3 - The variable 'value' is being used 
16
7
# without being def
17
8
18
9
# The following line causes Run-Time Check Failure on 
19
10
# binaries built with Visual C++ 2005
20
 
select cast(NULL as unsigned), cast(1/0 as unsigned); 
21
11
select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
22
12
select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME);
23
 
select cast("1:2:3" as TIME);
24
13
select CONVERT("2004-01-22 21:45:33",DATE);
25
14
select 10+'10';
26
15
select 10.0+'10';
28
17
 
29
18
# The following cast creates warnings
30
19
 
31
 
select CONVERT(DATE "2004-01-22 21:45:33" USING latin1);
32
20
select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
33
21
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
34
22
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
35
23
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
36
 
select CAST(0xb3 as signed);
37
 
select CAST(0x8fffffffffffffff as signed);
38
 
select CAST(0xffffffffffffffff as unsigned);
39
 
select CAST(0xfffffffffffffffe as signed);
40
 
select cast('-10a' as signed integer);
41
 
select cast('a10' as unsigned integer);
42
24
select 10+'a';
43
25
select 10.0+cast('a' as decimal);
44
26
select 10E+0+'a';
45
27
 
46
 
# out-of-range cases
47
 
select cast('18446744073709551616' as unsigned);
48
 
select cast('18446744073709551616' as signed);
49
 
select cast('9223372036854775809' as signed);
50
 
select cast('-1' as unsigned);
51
 
select cast('abc' as signed);
52
 
select cast('1a' as signed);
53
 
select cast('' as signed);
54
 
 
55
 
#
56
 
# Character set conversion
57
 
#
58
 
set names binary;
59
 
select cast(_latin1'test' as char character set latin2);
60
 
select cast(_koi8r'����' as char character set cp1251);
61
 
create table t1 select cast(_koi8r'����' as char character set cp1251) as t;
62
 
show create table t1;
63
 
drop table t1;
64
 
 
65
28
#
66
29
# CAST to CHAR with/without length
67
30
#
68
31
select
69
 
  cast(_latin1'ab'  AS char)    as c1,
70
 
  cast(_latin1'a '  AS char)    as c2,
71
 
  cast(_latin1'abc' AS char(2)) as c3,
72
 
  cast(_latin1'a  ' AS char(2)) as c4,
73
 
  hex(cast(_latin1'a'   AS char(2))) as c5;
 
32
  cast('ab'  AS char)    as c1,
 
33
  cast('a '  AS char)    as c2,
 
34
  cast('abc' AS char(2)) as c3,
 
35
  cast('a  ' AS char(2)) as c4,
 
36
  hex(cast('a'   AS char(2))) as c5;
74
37
select cast(1000 as CHAR(3));
75
38
 
 
39
# Should throw an error about 'abc' being too large for a char(2)
 
40
--error 1292
76
41
create table t1 select
77
 
  cast(_latin1'ab'  AS char)    as c1,
78
 
  cast(_latin1'a '  AS char)    as c2,
79
 
  cast(_latin1'abc' AS char(2)) as c3,
80
 
  cast(_latin1'a  ' AS char(2)) as c4,
81
 
  cast(_latin1'a'   AS char(2)) as c5;
82
 
select c1,c2,c3,c4,hex(c5) from t1;
83
 
show create table t1;
84
 
drop table t1;
 
42
  cast('ab'  AS char)    as c1,
 
43
  cast('a '  AS char)    as c2,
 
44
  cast('abc' AS char(2)) as c3,
 
45
  cast('a  ' AS char(2)) as c4,
 
46
  cast('a'   AS char(2)) as c5;
85
47
 
86
48
#
87
49
# CAST to NCHAR with/without length
88
50
#
89
51
select
90
 
  cast(_koi8r'��'  AS nchar)    as c1,
91
 
  cast(_koi8r'� '  AS nchar)    as c2,
92
 
  cast(_koi8r'���' AS nchar(2)) as c3,
93
 
  cast(_koi8r'�  ' AS nchar(2)) as c4,
94
 
  cast(_koi8r'�'   AS nchar(2)) as c5;
95
 
 
96
 
create table t1 select
97
 
  cast(_koi8r'��'  AS nchar)    as c1,
98
 
  cast(_koi8r'� '  AS nchar)    as c2,
99
 
  cast(_koi8r'���' AS nchar(2)) as c3,
100
 
  cast(_koi8r'�  ' AS nchar(2)) as c4,
101
 
  cast(_koi8r'�'   AS nchar(2)) as c5;
102
 
select * from t1;
103
 
show create table t1;
104
 
drop table t1;
105
 
 
106
 
#
107
 
# Bug 2202
108
 
# CAST from BINARY to non-BINARY and from non-BINARY to BINARY
109
 
#
110
 
create table t1 (a binary(4), b char(4) character set koi8r);
111
 
insert into t1 values (_binary'����',_binary'����');
112
 
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
113
 
set names koi8r;
114
 
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
115
 
set names cp1251;
116
 
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
117
 
drop table t1;
118
 
set names binary;
 
52
  cast('��'  AS char)    as c1,
 
53
  cast('� '  AS char)    as c2,
 
54
  cast('���' AS char(2)) as c3,
 
55
  cast('�  ' AS char(2)) as c4,
 
56
  cast('�'   AS char(2)) as c5;
 
57
 
 
58
# BUG in drizzletest - can't handle these chars right
 
59
# # Should throw an error about incorrect
 
60
#--error 1292
 
61
#create table t1 select
 
62
#  cast('��'  AS char)    as c1,
 
63
#  cast('� '  AS char)    as c2,
 
64
#  cast('���' AS char(2)) as c3,
 
65
#  cast('�  ' AS char(2)) as c4,
 
66
#  cast('�'   AS char(2)) as c5;
119
67
 
120
68
#
121
69
# The following should be fixed in 4.1
123
71
 
124
72
select cast("2001-1-1" as date) = "2001-01-01";
125
73
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
126
 
select cast("1:2:3" as TIME) = "1:02:03";
127
74
select cast(NULL as DATE);
128
75
select cast(NULL as BINARY);
129
76
 
132
79
#
133
80
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
134
81
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
135
 
# these two should be in enum order
136
 
SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ;
 
82
# should be in enum order
137
83
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
138
 
# these two should be in alphabetic order
139
 
SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ;
 
84
# should be in alphabetic order
140
85
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
141
86
DROP TABLE t1;
142
87
 
146
91
# time/date parts (correspondingly).
147
92
#
148
93
select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour);
149
 
select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');
150
94
# Still we should not throw away "days" part of time value
151
 
select timediff(cast('1 12:00:00' as time), '12:00:00');
152
 
 
153
 
#
154
 
# Bug #7036: Casting from string to unsigned would cap value of result at
155
 
# maximum signed value instead of maximum unsigned value
156
 
#
157
 
select cast(18446744073709551615 as unsigned);
158
 
select cast(18446744073709551615 as signed);
159
 
select cast('18446744073709551615' as unsigned);
160
 
select cast('18446744073709551615' as signed);
161
 
select cast('9223372036854775807' as signed);
162
 
 
163
 
select cast(concat('184467440','73709551615') as unsigned);
164
 
select cast(concat('184467440','73709551615') as signed);
165
 
 
166
 
select cast(repeat('1',20) as unsigned);
167
 
select cast(repeat('1',20) as signed);
168
 
 
169
 
#
170
 
# Bug #13344: cast of large decimal to signed int not handled correctly
171
 
#
172
 
select cast(1.0e+300 as signed int);
173
 
 
174
 
#
175
 
# Bugs: #15098: CAST(column double TO signed int), wrong result
176
 
#
177
 
CREATE TABLE t1 (f1 double);
178
 
INSERT INTO t1 SET f1 = -1.0e+30 ;
179
 
INSERT INTO t1 SET f1 = +1.0e+30 ;
180
 
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
181
 
DROP TABLE t1;                                     
182
95
 
183
96
#
184
97
# Bug #23938: cast(NULL as DATE)
186
99
 
187
100
select isnull(date(NULL)), isnull(cast(NULL as DATE));
188
101
 
189
 
#
190
 
# Bug#23656: Wrong result of CAST from DATE to int
191
 
#
192
 
SELECT CAST(cast('01-01-01' as date) AS UNSIGNED);
193
 
SELECT CAST(cast('01-01-01' as date) AS SIGNED);
194
 
 
195
 
--echo End of 4.1 tests
196
102
 
197
103
 
198
104
#decimal-related additions
199
105
select cast('1.2' as decimal(3,2));
200
106
select 1e18 * cast('1.2' as decimal(3,2));
201
 
select cast(cast('1.2' as decimal(3,2)) as signed);
202
107
set @v1=1e18;
203
108
select cast(@v1 as decimal(22, 2));
204
109
select cast(-1e18 as decimal(22,2));
205
110
 
206
 
create table t1(s1 time);
207
 
insert into t1 values ('11:11:11');
208
 
select cast(s1 as decimal(7,2)) from t1;
209
 
drop table t1;
210
 
 
211
 
#
212
111
# Test for bug #11283: field conversion from varchar, and text types to decimal
213
112
#
214
113
 
230
129
#
231
130
# Bug #17903: cast to char results in binary
232
131
#
233
 
set names latin1;
234
 
select hex(cast('a' as char(2) binary));
235
132
select hex(cast('a' as binary(2)));
236
 
select hex(cast('a' as char(2) binary));
237
133
 
238
 
#
239
 
# Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag.
240
 
#
241
 
CREATE TABLE t1 (d1 datetime);
242
 
INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL),
243
 
  ('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00');
244
 
SELECT cast(date(d1) as signed) FROM t1;
245
 
drop table t1;
246
134
 
247
135
#
248
136
# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE