Commit 9a5f85dc authored by Anel Husakovic's avatar Anel Husakovic Committed by Anel

MDEV-32790: Output result in show create table for mysql_json type should be longtext

- We don't test `json` MySQL tables from `std_data` since the error `ER_TABLE_NEEDS_REBUILD
` is invoked. However MDEV-32235 will override this test after merge,
but leave it to show behavior and historical changes.

- Closes PR #2833
Reviewer: <cvicentiu@mariadb.org>
          <serg@mariadb.com>
parent 9e9e0b99
...@@ -169,3 +169,47 @@ Total_Number_of_Tests Succesful_Tests String_is_valid_JSON ...@@ -169,3 +169,47 @@ Total_Number_of_Tests Succesful_Tests String_is_valid_JSON
drop table tempty; drop table tempty;
drop table mysql_json_test; drop table mysql_json_test;
drop table mysql_json_test_big; drop table mysql_json_test_big;
#
# MDEV-32790: Output result in show create table
# for mysql_json type should be longtext
#
create table t1(j json);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`j` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`j`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
create table t1(j mysql_json);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`j` mysql_json /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
create table `testjson` (
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CH...' at line 2
create table `testjson` (
`t` json /* JSON from MySQL 5.7*/ COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
show create table testjson;
Table Create Table
testjson CREATE TABLE `testjson` (
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`t`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table testjson;
create table `testjson` (
`t` longtext /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
show create table testjson;
Table Create Table
testjson CREATE TABLE `testjson` (
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table testjson;
#
# End of 10.5 tests
#
...@@ -88,3 +88,39 @@ from mysql_json_test_big; ...@@ -88,3 +88,39 @@ from mysql_json_test_big;
drop table tempty; drop table tempty;
drop table mysql_json_test; drop table mysql_json_test;
drop table mysql_json_test_big; drop table mysql_json_test_big;
--echo #
--echo # MDEV-32790: Output result in show create table
--echo # for mysql_json type should be longtext
--echo #
create table t1(j json);
show create table t1;
drop table t1;
create table t1(j mysql_json);
show create table t1;
drop table t1;
# `json` type should not have character set and collation other than utf8mb4_bin
--error ER_PARSE_ERROR
create table `testjson` (
`t` json /* JSON from MySQL 5.7*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
# By removing character set from `json` field query should work and
# expand to `longtext` with characterset
create table `testjson` (
`t` json /* JSON from MySQL 5.7*/ COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
show create table testjson;
drop table testjson;
# `longtext` that is alias can have character set
create table `testjson` (
`t` longtext /* JSON from MySQL 5.7 */ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
show create table testjson;
drop table testjson;
--echo #
--echo # End of 10.5 tests
--echo #
...@@ -62,7 +62,7 @@ class Field_mysql_json: public Field_blob ...@@ -62,7 +62,7 @@ class Field_mysql_json: public Field_blob
bool parse_mysql(String *dest, const char *data, size_t length) const; bool parse_mysql(String *dest, const char *data, size_t length) const;
bool send(Protocol *protocol) { return Field::send(protocol); } bool send(Protocol *protocol) { return Field::send(protocol); }
void sql_type(String &s) const void sql_type(String &s) const
{ s.set_ascii(STRING_WITH_LEN("json /* MySQL 5.7 */")); } { s.set_ascii(STRING_WITH_LEN("mysql_json /* JSON from MySQL 5.7 */")); }
/* this will make ALTER TABLE to consider it different from built-in field */ /* this will make ALTER TABLE to consider it different from built-in field */
Compression_method *compression_method() const { return (Compression_method*)1; } Compression_method *compression_method() const { return (Compression_method*)1; }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment