Skip to content

Commit 6f65931

Browse files
committed
MDEV-19906 Port show_old_temporals from MySQL 5.6
Old temporal data types (created with a pre-10.0 version of MariaDB) are now displayed with a /* mariadb-5.3 */ comment in: - SHOW CREATE TABLE - DESCRIBE - INFORMATION_SCHEMA.COLUMNS.COLUMN_TYPE For example: CREATE TABLE `t1` ( `t0` datetime /* mariadb-5.3 */ DEFAULT NULL, `t6` datetime(6) /* mariadb-5.3 */ DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 Note, new temporal data types are displayed without a format comment.
1 parent e7558d4 commit 6f65931

File tree

10 files changed

+376
-53
lines changed

10 files changed

+376
-53
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
#
2+
# MDEV-19906 Port show_old_temporals from MySQL 5.6
3+
#
4+
TRUNCATE TABLE mariadb5312_datetime;
5+
SHOW CREATE TABLE mariadb5312_datetime;
6+
Table Create Table
7+
mariadb5312_datetime CREATE TABLE `mariadb5312_datetime` (
8+
`t0` datetime /* mariadb-5.3 */ DEFAULT NULL,
9+
`t1` datetime(1) /* mariadb-5.3 */ DEFAULT NULL,
10+
`t2` datetime(2) /* mariadb-5.3 */ DEFAULT NULL,
11+
`t3` datetime(3) /* mariadb-5.3 */ DEFAULT NULL,
12+
`t4` datetime(4) /* mariadb-5.3 */ DEFAULT NULL,
13+
`t5` datetime(5) /* mariadb-5.3 */ DEFAULT NULL,
14+
`t6` datetime(6) /* mariadb-5.3 */ DEFAULT NULL
15+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
16+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_datetime';
17+
COLUMN_NAME t0
18+
DATA_TYPE datetime
19+
COLUMN_TYPE datetime /* mariadb-5.3 */
20+
COLUMN_NAME t1
21+
DATA_TYPE datetime
22+
COLUMN_TYPE datetime(1) /* mariadb-5.3 */
23+
COLUMN_NAME t2
24+
DATA_TYPE datetime
25+
COLUMN_TYPE datetime(2) /* mariadb-5.3 */
26+
COLUMN_NAME t3
27+
DATA_TYPE datetime
28+
COLUMN_TYPE datetime(3) /* mariadb-5.3 */
29+
COLUMN_NAME t4
30+
DATA_TYPE datetime
31+
COLUMN_TYPE datetime(4) /* mariadb-5.3 */
32+
COLUMN_NAME t5
33+
DATA_TYPE datetime
34+
COLUMN_TYPE datetime(5) /* mariadb-5.3 */
35+
COLUMN_NAME t6
36+
DATA_TYPE datetime
37+
COLUMN_TYPE datetime(6) /* mariadb-5.3 */
38+
DESCRIBE mariadb5312_datetime;
39+
Field t0
40+
Type datetime /* mariadb-5.3 */
41+
Null YES
42+
Key
43+
Default NULL
44+
Extra
45+
Field t1
46+
Type datetime(1) /* mariadb-5.3 */
47+
Null YES
48+
Key
49+
Default NULL
50+
Extra
51+
Field t2
52+
Type datetime(2) /* mariadb-5.3 */
53+
Null YES
54+
Key
55+
Default NULL
56+
Extra
57+
Field t3
58+
Type datetime(3) /* mariadb-5.3 */
59+
Null YES
60+
Key
61+
Default NULL
62+
Extra
63+
Field t4
64+
Type datetime(4) /* mariadb-5.3 */
65+
Null YES
66+
Key
67+
Default NULL
68+
Extra
69+
Field t5
70+
Type datetime(5) /* mariadb-5.3 */
71+
Null YES
72+
Key
73+
Default NULL
74+
Extra
75+
Field t6
76+
Type datetime(6) /* mariadb-5.3 */
77+
Null YES
78+
Key
79+
Default NULL
80+
Extra
81+
DROP TABLE mariadb5312_datetime;
82+
TRUNCATE TABLE mariadb5312_timestamp;
83+
SHOW CREATE TABLE mariadb5312_timestamp;
84+
Table Create Table
85+
mariadb5312_timestamp CREATE TABLE `mariadb5312_timestamp` (
86+
`t0` timestamp /* mariadb-5.3 */ NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
87+
`t1` timestamp(1) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.0',
88+
`t2` timestamp(2) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.00',
89+
`t3` timestamp(3) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.000',
90+
`t4` timestamp(4) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.0000',
91+
`t5` timestamp(5) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.00000',
92+
`t6` timestamp(6) /* mariadb-5.3 */ NOT NULL DEFAULT '0000-00-00 00:00:00.000000'
93+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
94+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_timestamp';
95+
COLUMN_NAME t0
96+
DATA_TYPE timestamp
97+
COLUMN_TYPE timestamp /* mariadb-5.3 */
98+
COLUMN_NAME t1
99+
DATA_TYPE timestamp
100+
COLUMN_TYPE timestamp(1) /* mariadb-5.3 */
101+
COLUMN_NAME t2
102+
DATA_TYPE timestamp
103+
COLUMN_TYPE timestamp(2) /* mariadb-5.3 */
104+
COLUMN_NAME t3
105+
DATA_TYPE timestamp
106+
COLUMN_TYPE timestamp(3) /* mariadb-5.3 */
107+
COLUMN_NAME t4
108+
DATA_TYPE timestamp
109+
COLUMN_TYPE timestamp(4) /* mariadb-5.3 */
110+
COLUMN_NAME t5
111+
DATA_TYPE timestamp
112+
COLUMN_TYPE timestamp(5) /* mariadb-5.3 */
113+
COLUMN_NAME t6
114+
DATA_TYPE timestamp
115+
COLUMN_TYPE timestamp(6) /* mariadb-5.3 */
116+
DESCRIBE mariadb5312_timestamp;
117+
Field t0
118+
Type timestamp /* mariadb-5.3 */
119+
Null NO
120+
Key
121+
Default current_timestamp()
122+
Extra on update current_timestamp()
123+
Field t1
124+
Type timestamp(1) /* mariadb-5.3 */
125+
Null NO
126+
Key
127+
Default 0000-00-00 00:00:00.0
128+
Extra
129+
Field t2
130+
Type timestamp(2) /* mariadb-5.3 */
131+
Null NO
132+
Key
133+
Default 0000-00-00 00:00:00.00
134+
Extra
135+
Field t3
136+
Type timestamp(3) /* mariadb-5.3 */
137+
Null NO
138+
Key
139+
Default 0000-00-00 00:00:00.000
140+
Extra
141+
Field t4
142+
Type timestamp(4) /* mariadb-5.3 */
143+
Null NO
144+
Key
145+
Default 0000-00-00 00:00:00.0000
146+
Extra
147+
Field t5
148+
Type timestamp(5) /* mariadb-5.3 */
149+
Null NO
150+
Key
151+
Default 0000-00-00 00:00:00.00000
152+
Extra
153+
Field t6
154+
Type timestamp(6) /* mariadb-5.3 */
155+
Null NO
156+
Key
157+
Default 0000-00-00 00:00:00.000000
158+
Extra
159+
DROP TABLE mariadb5312_timestamp;
160+
TRUNCATE TABLE mariadb5312_time;
161+
SHOW CREATE TABLE mariadb5312_time;
162+
Table Create Table
163+
mariadb5312_time CREATE TABLE `mariadb5312_time` (
164+
`t0` time /* mariadb-5.3 */ DEFAULT NULL,
165+
`t1` time(1) /* mariadb-5.3 */ DEFAULT NULL,
166+
`t2` time(2) /* mariadb-5.3 */ DEFAULT NULL,
167+
`t3` time(3) /* mariadb-5.3 */ DEFAULT NULL,
168+
`t4` time(4) /* mariadb-5.3 */ DEFAULT NULL,
169+
`t5` time(5) /* mariadb-5.3 */ DEFAULT NULL,
170+
`t6` time(6) /* mariadb-5.3 */ DEFAULT NULL
171+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
172+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_time';
173+
COLUMN_NAME t0
174+
DATA_TYPE time
175+
COLUMN_TYPE time /* mariadb-5.3 */
176+
COLUMN_NAME t1
177+
DATA_TYPE time
178+
COLUMN_TYPE time(1) /* mariadb-5.3 */
179+
COLUMN_NAME t2
180+
DATA_TYPE time
181+
COLUMN_TYPE time(2) /* mariadb-5.3 */
182+
COLUMN_NAME t3
183+
DATA_TYPE time
184+
COLUMN_TYPE time(3) /* mariadb-5.3 */
185+
COLUMN_NAME t4
186+
DATA_TYPE time
187+
COLUMN_TYPE time(4) /* mariadb-5.3 */
188+
COLUMN_NAME t5
189+
DATA_TYPE time
190+
COLUMN_TYPE time(5) /* mariadb-5.3 */
191+
COLUMN_NAME t6
192+
DATA_TYPE time
193+
COLUMN_TYPE time(6) /* mariadb-5.3 */
194+
DESCRIBE mariadb5312_time;
195+
Field t0
196+
Type time /* mariadb-5.3 */
197+
Null YES
198+
Key
199+
Default NULL
200+
Extra
201+
Field t1
202+
Type time(1) /* mariadb-5.3 */
203+
Null YES
204+
Key
205+
Default NULL
206+
Extra
207+
Field t2
208+
Type time(2) /* mariadb-5.3 */
209+
Null YES
210+
Key
211+
Default NULL
212+
Extra
213+
Field t3
214+
Type time(3) /* mariadb-5.3 */
215+
Null YES
216+
Key
217+
Default NULL
218+
Extra
219+
Field t4
220+
Type time(4) /* mariadb-5.3 */
221+
Null YES
222+
Key
223+
Default NULL
224+
Extra
225+
Field t5
226+
Type time(5) /* mariadb-5.3 */
227+
Null YES
228+
Key
229+
Default NULL
230+
Extra
231+
Field t6
232+
Type time(6) /* mariadb-5.3 */
233+
Null YES
234+
Key
235+
Default NULL
236+
Extra
237+
DROP TABLE mariadb5312_time;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--let $MYSQLD_DATADIR= `select @@datadir`
2+
3+
--echo #
4+
--echo # MDEV-19906 Port show_old_temporals from MySQL 5.6
5+
--echo #
6+
7+
--copy_file $MYSQL_TEST_DIR/std_data/mariadb53_temporal/mariadb5312_datetime.frm $MYSQLD_DATADIR/test/mariadb5312_datetime.frm
8+
TRUNCATE TABLE mariadb5312_datetime;
9+
SHOW CREATE TABLE mariadb5312_datetime;
10+
--vertical_results
11+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_datetime';
12+
DESCRIBE mariadb5312_datetime;
13+
--horizontal_results
14+
DROP TABLE mariadb5312_datetime;
15+
16+
--copy_file $MYSQL_TEST_DIR/std_data/mariadb53_temporal/mariadb5312_timestamp.frm $MYSQLD_DATADIR/test/mariadb5312_timestamp.frm
17+
TRUNCATE TABLE mariadb5312_timestamp;
18+
SHOW CREATE TABLE mariadb5312_timestamp;
19+
--vertical_results
20+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_timestamp';
21+
DESCRIBE mariadb5312_timestamp;
22+
--horizontal_results
23+
DROP TABLE mariadb5312_timestamp;
24+
25+
--copy_file $MYSQL_TEST_DIR/std_data/mariadb53_temporal/mariadb5312_time.frm $MYSQLD_DATADIR/test/mariadb5312_time.frm
26+
TRUNCATE TABLE mariadb5312_time;
27+
SHOW CREATE TABLE mariadb5312_time;
28+
--vertical_results
29+
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='mariadb5312_time';
30+
DESCRIBE mariadb5312_time;
31+
--horizontal_results
32+
DROP TABLE mariadb5312_time;
Binary file not shown.
Binary file not shown.
Binary file not shown.

sql/field.cc

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,19 +5329,6 @@ void Field_timestamp0::sort_string(uchar *to,uint length __attribute__((unused))
53295329
}
53305330

53315331

5332-
void Field_timestamp::sql_type(String &res) const
5333-
{
5334-
if (!decimals())
5335-
{
5336-
res.set_ascii(STRING_WITH_LEN("timestamp"));
5337-
return;
5338-
}
5339-
CHARSET_INFO *cs=res.charset();
5340-
res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
5341-
"timestamp(%u)", decimals()));
5342-
}
5343-
5344-
53455332
int Field_timestamp0::set_time()
53465333
{
53475334
set_notnull();
@@ -5621,6 +5608,44 @@ void Field_temporal::set_warnings(Sql_condition::enum_warning_level trunc_level,
56215608
}
56225609

56235610

5611+
void Field_temporal::sql_type_dec_comment(String &res,
5612+
const Name &name,
5613+
uint dec,
5614+
const Name &comment) const
5615+
{
5616+
CHARSET_INFO *cs=res.charset();
5617+
res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
5618+
"%.*s(%u)%s%.*s%s",
5619+
(uint) name.length(), name.ptr(),
5620+
dec,
5621+
comment.length() ? " /* " : "",
5622+
(uint) comment.length(), comment.ptr(),
5623+
comment.length() ? " */" : ""));
5624+
}
5625+
5626+
5627+
void Field_temporal::sql_type_comment(String &res,
5628+
const Name &name,
5629+
const Name &comment) const
5630+
{
5631+
CHARSET_INFO *cs=res.charset();
5632+
res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
5633+
"%.*s%s%.*s%s",
5634+
(uint) name.length(), name.ptr(),
5635+
comment.length() ? " /* " : "",
5636+
(uint) comment.length(), comment.ptr(),
5637+
comment.length() ? " */" : ""));
5638+
}
5639+
5640+
5641+
const Name & Field_temporal::type_version_mysql56()
5642+
{
5643+
DBUG_EXECUTE_IF("sql_type", return Type_handler::version_mysql56(); );
5644+
static Name none(NULL, 0);
5645+
return none;
5646+
}
5647+
5648+
56245649
/*
56255650
Store string into a date/time field
56265651
@@ -5991,17 +6016,6 @@ void Field_time0::sort_string(uchar *to,uint length __attribute__((unused)))
59916016
to[2] = ptr[0];
59926017
}
59936018

5994-
void Field_time::sql_type(String &res) const
5995-
{
5996-
if (decimals() == 0)
5997-
{
5998-
res.set_ascii(STRING_WITH_LEN("time"));
5999-
return;
6000-
}
6001-
CHARSET_INFO *cs= res.charset();
6002-
res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
6003-
"time(%d)", decimals()));
6004-
}
60056019

60066020
int Field_time_hires::reset()
60076021
{
@@ -6811,19 +6825,6 @@ void Field_datetime0::sort_string(uchar *to,uint length __attribute__((unused)))
68116825
}
68126826

68136827

6814-
void Field_datetime::sql_type(String &res) const
6815-
{
6816-
if (decimals() == 0)
6817-
{
6818-
res.set_ascii(STRING_WITH_LEN("datetime"));
6819-
return;
6820-
}
6821-
CHARSET_INFO *cs= res.charset();
6822-
res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
6823-
"datetime(%u)", decimals()));
6824-
}
6825-
6826-
68276828
int Field_datetime::set_time()
68286829
{
68296830
THD *thd= table->in_use;

0 commit comments

Comments
 (0)