mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 17:54:16 +01:00
MDEV-35245 SHOW CREATE TABLE produces unusable statement for vector fields with constant default value
print default values for binary types as binary strings
This commit is contained in:
parent
053bd80d43
commit
72839c1435
11 changed files with 57 additions and 29 deletions
|
@ -240,7 +240,7 @@ ALTER IGNORE TABLE t1 MODIFY a VARBINARY(255) DEFAULT 'a11';
|
|||
CALL show_table;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` varbinary(255) DEFAULT 'a11',
|
||||
`a` varbinary(255) DEFAULT x'613131',
|
||||
`b` varchar(255) DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||
VERSION
|
||||
|
@ -251,7 +251,7 @@ ALTER IGNORE TABLE t1 MODIFY a VARBINARY(255) DEFAULT 'a12';
|
|||
CALL show_table;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` varbinary(255) DEFAULT 'a12',
|
||||
`a` varbinary(255) DEFAULT x'613132',
|
||||
`b` varchar(255) DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||
VERSION
|
||||
|
|
|
@ -316,3 +316,14 @@ f
|
|||
1111
|
||||
drop view v;
|
||||
drop table t;
|
||||
#
|
||||
# MDEV-35245 SHOW CREATE TABLE produces unusable statement for vector fields with constant default value
|
||||
#
|
||||
create table t1 (f vector(1) default 0x30313233, v vector(2) default x'4041424344454647');
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`f` vector(1) DEFAULT x'30313233',
|
||||
`v` vector(2) DEFAULT x'4041424344454647'
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||
drop table t1;
|
||||
|
|
|
@ -246,3 +246,10 @@ create algorithm=temptable view v as select * from t;
|
|||
select v1.f from v v1 natural join v v2;
|
||||
drop view v;
|
||||
drop table t;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-35245 SHOW CREATE TABLE produces unusable statement for vector fields with constant default value
|
||||
--echo #
|
||||
create table t1 (f vector(1) default 0x30313233, v vector(2) default x'4041424344454647');
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
|
|
|
@ -30,7 +30,7 @@ t14
|
|||
SHOW CREATE TABLE t14;
|
||||
Table Create Table
|
||||
t14 CREATE TABLE `t14` (
|
||||
`c1` binary(10) DEFAULT 'x\0\0\0\0\0\0\0\0\0'
|
||||
`c1` binary(10) DEFAULT x'78000000000000000000'
|
||||
) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||
DROP TABLE t14;
|
||||
SHOW TABLES;
|
||||
|
@ -42,7 +42,7 @@ t14
|
|||
SHOW CREATE TABLE t14;
|
||||
Table Create Table
|
||||
t14 CREATE TABLE `t14` (
|
||||
`c1` varbinary(10) DEFAULT 'x'
|
||||
`c1` varbinary(10) DEFAULT x'78'
|
||||
) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||
DROP TABLE t14;
|
||||
SHOW TABLES;
|
||||
|
@ -78,7 +78,7 @@ t14
|
|||
SHOW CREATE TABLE t14;
|
||||
Table Create Table
|
||||
t14 CREATE TABLE `t14` (
|
||||
`c1` binary(10) NOT NULL DEFAULT 'x\0\0\0\0\0\0\0\0\0'
|
||||
`c1` binary(10) NOT NULL DEFAULT x'78000000000000000000'
|
||||
) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||
DROP TABLE t14;
|
||||
SHOW TABLES;
|
||||
|
@ -90,7 +90,7 @@ t14
|
|||
SHOW CREATE TABLE t14;
|
||||
Table Create Table
|
||||
t14 CREATE TABLE `t14` (
|
||||
`c1` varbinary(10) NOT NULL DEFAULT 'x'
|
||||
`c1` varbinary(10) NOT NULL DEFAULT x'78'
|
||||
) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||
DROP TABLE t14;
|
||||
SHOW TABLES;
|
||||
|
|
|
@ -534,7 +534,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob
|
|||
def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO
|
||||
|
|
|
@ -529,7 +529,7 @@ def test tb3 f119 2 '' NO char 1 1 NULL NULL NULL latin1 latin1_bin char(1) s
|
|||
def test tb3 f120 3 '' NO char 1 1 NULL NULL NULL latin1 latin1_swedish_ci char(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f121 4 NULL YES char 50 50 NULL NULL NULL latin1 latin1_swedish_ci char(50) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f122 5 NULL YES char 50 50 NULL NULL NULL latin1 latin1_swedish_ci char(50) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 6 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 6 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f130 7 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f131 8 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f132 9 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO
|
||||
|
|
|
@ -591,7 +591,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob
|
|||
def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references NEVER NULL NO NO
|
||||
def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill select,insert,update,references NEVER NULL NO NO
|
||||
|
|
|
@ -591,7 +591,7 @@ def test tb3 f125 8 NULL YES tinyblob 255 255 NULL NULL NULL NULL NULL tinyblob
|
|||
def test tb3 f126 9 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob NEVER NULL NO NO
|
||||
def test tb3 f127 10 NULL YES mediumblob 16777215 16777215 NULL NULL NULL NULL NULL mediumblob NEVER NULL NO NO
|
||||
def test tb3 f128 11 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob NEVER NULL NO NO
|
||||
def test tb3 f129 12 '' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) NEVER NULL NO NO
|
||||
def test tb3 f129 12 x'05' NO binary 1 1 NULL NULL NULL NULL NULL binary(1) NEVER NULL NO NO
|
||||
def test tb3 f130 13 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(4) NEVER NULL NO NO
|
||||
def test tb3 f131 14 99 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned NEVER NULL NO NO
|
||||
def test tb3 f132 15 099 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned zerofill NEVER NULL NO NO
|
||||
|
|
|
@ -1863,28 +1863,38 @@ static bool get_field_default_value(THD *thd, Field *field, String *def_value,
|
|||
str.qs_append('\'');
|
||||
str.qs_append(field->val_int(), 2);
|
||||
str.qs_append('\'');
|
||||
quoted= 0;
|
||||
def_value->append(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
field->val_str(&str);
|
||||
if (!field->str_needs_quotes())
|
||||
quoted= 0;
|
||||
if (str.length())
|
||||
{
|
||||
if (str.charset() == &my_charset_bin)
|
||||
{
|
||||
def_value->append('x');
|
||||
def_value->append('\'');
|
||||
def_value->append_hex(str.ptr(), str.length());
|
||||
def_value->append('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuffer<MAX_FIELD_WIDTH> def_val;
|
||||
uint dummy_errors;
|
||||
/* convert to system_charset_info == utf8 */
|
||||
def_val.copy(str.ptr(), str.length(), field->charset(),
|
||||
system_charset_info, &dummy_errors);
|
||||
if (quoted)
|
||||
append_unescaped(def_value, def_val.ptr(), def_val.length());
|
||||
else
|
||||
def_value->append(def_val);
|
||||
}
|
||||
}
|
||||
else if (quoted)
|
||||
def_value->set(STRING_WITH_LEN("''"), system_charset_info);
|
||||
}
|
||||
if (str.length())
|
||||
{
|
||||
StringBuffer<MAX_FIELD_WIDTH> def_val;
|
||||
uint dummy_errors;
|
||||
/* convert to system_charset_info == utf8 */
|
||||
def_val.copy(str.ptr(), str.length(), field->charset(),
|
||||
system_charset_info, &dummy_errors);
|
||||
if (quoted)
|
||||
append_unescaped(def_value, def_val.ptr(), def_val.length());
|
||||
else
|
||||
def_value->append(def_val);
|
||||
}
|
||||
else if (quoted)
|
||||
def_value->set(STRING_WITH_LEN("''"), system_charset_info);
|
||||
}
|
||||
else if (field->maybe_null() && quoted)
|
||||
def_value->set(STRING_WITH_LEN("NULL"), system_charset_info); // Null as default
|
||||
|
|
|
@ -75,7 +75,7 @@ c BINARY NOT NULL DEFAULT 0
|
|||
SHOW COLUMNS IN t1;
|
||||
Field Type Null Key Default Extra
|
||||
pk int(11) NO PRI NULL auto_increment
|
||||
c binary(1) NO 0
|
||||
c binary(1) NO x'30'
|
||||
ALTER TABLE t1 ADD COLUMN err BINARY NOT NULL DEFAULT NULL;
|
||||
ERROR 42000: Invalid default value for 'err'
|
||||
INSERT INTO t1 (c) VALUES (NULL);
|
||||
|
@ -209,7 +209,7 @@ c VARBINARY(64) NOT NULL DEFAULT 'test'
|
|||
SHOW COLUMNS IN t1;
|
||||
Field Type Null Key Default Extra
|
||||
pk int(11) NO PRI NULL auto_increment
|
||||
c varbinary(64) NO test
|
||||
c varbinary(64) NO x'74657374'
|
||||
ALTER TABLE t1 ADD COLUMN err VARBINARY(64) NOT NULL DEFAULT NULL;
|
||||
ERROR 42000: Invalid default value for 'err'
|
||||
INSERT INTO t1 (c) VALUES (NULL);
|
||||
|
|
|
@ -60,7 +60,7 @@ SHOW COLUMNS IN t1;
|
|||
Field Type Null Key Default Extra
|
||||
c binary(1) YES NULL
|
||||
c1 binary(1) YES NULL
|
||||
c2 binary(1) YES 0
|
||||
c2 binary(1) YES x'30'
|
||||
pk int(11) NO PRI NULL auto_increment
|
||||
INSERT INTO t1 (c,c1,c2) VALUES (NULL,NULL,NULL);
|
||||
INSERT INTO t1 (c,c1,c2) VALUES (0,0,0);
|
||||
|
@ -183,7 +183,7 @@ SHOW COLUMNS IN t1;
|
|||
Field Type Null Key Default Extra
|
||||
c varbinary(64) YES NULL
|
||||
c1 varbinary(64) YES NULL
|
||||
c2 varbinary(64) YES test
|
||||
c2 varbinary(64) YES x'74657374'
|
||||
pk int(11) NO PRI NULL auto_increment
|
||||
INSERT INTO t1 (c,c1,c2) VALUES (NULL,NULL,NULL);
|
||||
INSERT INTO t1 (c,c1,c2) VALUES ('test','test','test');
|
||||
|
|
Loading…
Add table
Reference in a new issue