~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/cast.test

  • Committer: Brian Aker
  • Date: 2008-07-28 18:01:38 UTC
  • Revision ID: brian@tangent.org-20080728180138-q2pxlq0qiapvqsdn
Remove YEAR field type

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 CONVERT("2004-01-22 21:45:33",DATE);
14
 
select 10+'10';
15
 
select 10.0+'10';
16
 
select 10E+0+'10';
17
 
 
18
 
# The following cast creates warnings
19
 
 
20
 
select CONVERT(DATE "2004-01-22 21:45:33",CHAR);
21
 
select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4));
22
 
select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4));
23
 
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
24
 
select 10+'a';
25
 
select 10.0+cast('a' as decimal);
26
 
select 10E+0+'a';
27
 
 
28
 
#
29
 
# CAST to CHAR with/without length
30
 
#
31
 
select
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;
37
 
select cast(1000 as CHAR(3));
38
 
 
39
 
# Should throw an error about 'abc' being too large for a char(2)
40
 
--error 1292
41
 
create table t1 select
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;
47
 
 
48
 
#
49
 
# CAST to NCHAR with/without length
50
 
#
51
 
select
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;
67
 
 
68
 
#
69
 
# The following should be fixed in 4.1
70
 
#
71
 
 
72
 
select cast("2001-1-1" as date) = "2001-01-01";
73
 
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
74
 
select cast(NULL as DATE);
75
 
select cast(NULL as BINARY);
76
 
 
77
 
#
78
 
# Bug #5228 ORDER BY CAST(enumcol) sorts incorrectly under certain conditions
79
 
#
80
 
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
81
 
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
82
 
# should be in enum order
83
 
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
84
 
# should be in alphabetic order
85
 
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
86
 
DROP TABLE t1;
87
 
 
88
 
#
89
 
# Test for bug #6914 "Problems using time()/date() output in expressions".
90
 
# When we are casting datetime value to DATE/TIME we should throw away
91
 
# time/date parts (correspondingly).
92
 
#
93
 
select date_add(cast('2004-12-30 12:00:00' as date), interval 0 hour);
94
 
# Still we should not throw away "days" part of time value
95
 
 
96
 
#
97
 
# Bug #23938: cast(NULL as DATE)
98
 
#
99
 
 
100
 
select isnull(date(NULL)), isnull(cast(NULL as DATE));
101
 
 
102
 
 
103
 
 
104
 
#decimal-related additions
105
 
select cast('1.2' as decimal(3,2));
106
 
select 1e18 * cast('1.2' as decimal(3,2));
107
 
set @v1=1e18;
108
 
select cast(@v1 as decimal(22, 2));
109
 
select cast(-1e18 as decimal(22,2));
110
 
 
111
 
# Test for bug #11283: field conversion from varchar, and text types to decimal
112
 
#
113
 
 
114
 
CREATE TABLE t1 (v varchar(10), tt tinytext, t text,
115
 
                 mt mediumtext, lt longtext);
116
 
INSERT INTO t1 VALUES ('1.01', '2.02', '3.03', '4.04', '5.05');
117
 
 
118
 
SELECT CAST(v AS DECIMAL), CAST(tt AS DECIMAL), CAST(t AS DECIMAL),
119
 
       CAST(mt AS DECIMAL), CAST(lt AS DECIMAL) from t1;
120
 
 
121
 
DROP TABLE t1;
122
 
 
123
 
#
124
 
# Bug #10237 (CAST(NULL DECIMAL) crashes server)
125
 
#
126
 
select cast(NULL as decimal(6)) as t1;
127
 
 
128
 
 
129
 
#
130
 
# Bug #17903: cast to char results in binary
131
 
#
132
 
select hex(cast('a' as binary(2)));
133
 
 
134
 
 
135
 
#
136
 
# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
137
 
#
138
 
 
139
 
# Show that HH:MM:SS of a DATE are 0, and that it's the same for columns
140
 
# and typecasts (NULL in, NULL out).
141
 
CREATE TABLE t1 (f1 DATE);
142
 
INSERT INTO t1 VALUES ('2007-07-19'), (NULL);
143
 
SELECT HOUR(f1),
144
 
       MINUTE(f1),
145
 
       SECOND(f1) FROM t1;
146
 
SELECT HOUR(CAST('2007-07-19' AS DATE)),
147
 
       MINUTE(CAST('2007-07-19' AS DATE)),
148
 
       SECOND(CAST('2007-07-19' AS DATE));
149
 
SELECT HOUR(CAST(NULL AS DATE)),
150
 
       MINUTE(CAST(NULL AS DATE)),
151
 
       SECOND(CAST(NULL AS DATE));
152
 
SELECT HOUR(NULL),
153
 
       MINUTE(NULL),
154
 
       SECOND(NULL);
155
 
DROP TABLE t1;
156
 
 
157
 
--echo End of 5.0 tests