Fix for bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage

Unencode internal db & table name
parent ae836b42
......@@ -56,3 +56,25 @@ test t3 FOREIGN KEY A2 test t2 NONE SET NULL RESTRICT
test t4 FOREIGN KEY A3 test t3 NONE NO ACTION SET NULL
test t5 FOREIGN KEY A4 test t4 NONE RESTRICT CASCADE
drop tables t5, t4, t3, t2, t1;
create database `db-1`;
use `db-1`;
create table `t-2` (
id int(10) unsigned not null auto_increment,
primary key (id)
) engine=innodb;
create table `t-1` (
id int(10) unsigned not null auto_increment,
idtype int(10) unsigned not null,
primary key (id),
key fk_t1_1 (idtype),
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
) engine=innodb;
use test;
select referenced_table_schema, referenced_table_name
from information_schema.key_column_usage
where constraint_schema = 'db-1';
referenced_table_schema referenced_table_name
NULL NULL
db-1 t-2
NULL NULL
drop database `db-1`;
-- source include/testdb_only.inc
-- source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
......@@ -53,3 +54,26 @@ from information_schema.TABLE_CONSTRAINTS a,
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
drop tables t5, t4, t3, t2, t1;
#
# Bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage
#
create database `db-1`;
use `db-1`;
create table `t-2` (
id int(10) unsigned not null auto_increment,
primary key (id)
) engine=innodb;
create table `t-1` (
id int(10) unsigned not null auto_increment,
idtype int(10) unsigned not null,
primary key (id),
key fk_t1_1 (idtype),
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
) engine=innodb;
use test;
select referenced_table_schema, referenced_table_name
from information_schema.key_column_usage
where constraint_schema = 'db-1';
drop database `db-1`;
......@@ -5933,6 +5933,9 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
uint i;
FOREIGN_KEY_INFO f_key_info;
LEX_STRING *name= 0;
uint ulen;
char uname[NAME_LEN*3+1]; /* Unencoded name */
char db_name[NAME_LEN*3+1];
const char *tmp_buff;
tmp_buff= foreign->id;
......@@ -5943,14 +5946,23 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
f_key_info.forein_id= make_lex_string(thd, 0, tmp_buff,
(uint) strlen(tmp_buff), 1);
tmp_buff= foreign->referenced_table_name;
/* Database name */
i= 0;
while (tmp_buff[i] != '/')
i++;
f_key_info.referenced_db= make_lex_string(thd, 0,
tmp_buff, i, 1);
{
db_name[i]= tmp_buff[i];
i++;
}
db_name[i]= 0;
ulen= filename_to_tablename(db_name, uname, sizeof(uname));
f_key_info.referenced_db= make_lex_string(thd, 0, uname, ulen, 1);
/* Table name */
tmp_buff+= i + 1;
f_key_info.referenced_table= make_lex_string(thd, 0, tmp_buff,
(uint) strlen(tmp_buff), 1);
ulen= filename_to_tablename(tmp_buff, uname, sizeof(uname));
f_key_info.referenced_table= make_lex_string(thd, 0, uname,
ulen, 1);
for (i= 0;;) {
tmp_buff= foreign->foreign_col_names[i];
......
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