Permalink
Browse files

Bug #21094069 FOREIGN KEYS WITH SPECIAL CHARS IN PARENT DB NAME: FALS…

…E CONSTRAINT VIOLATIONTS *

PROBLEM

In function innobase_get_foreign_key_info(), we were trying to open the
referenced table using the name stored in key (Foreign_key) ,but the
table and database name strings are stored according the system
character set and not as file name charset format.Innodb stores the
names using filename charset format , therfore it is unable to
recognize the database and table names with special characters present
in the name and therefore is unable to open the referenced table and
we get subsequent error during inserts when foreign key checks is
turned on.

FIX

Convert the database and table names into filename charset and then
open the referenced table.
  • Loading branch information...
Aditya A
Aditya A committed Jun 16, 2015
1 parent 5610e53 commit 1fae0d42c352908fed03e29db2b391a0d2969269
Showing with 17 additions and 13 deletions.
  1. +17 −13 storage/innobase/handler/handler0alter.cc
@@ -28,6 +28,7 @@ Smart ALTER TABLE
#include <mysql/innodb_priv.h>
#include <sql_alter.h>
#include <sql_class.h>
#include <sql_table.h>
#include "dict0crea.h"
#include "dict0dict.h"
@@ -825,10 +826,8 @@ innobase_get_foreign_key_info(
char* tbl_namep = NULL;
ulint db_name_len = 0;
ulint tbl_name_len = 0;
#ifdef __WIN__
char db_name[MAX_DATABASE_NAME_LEN];
char tbl_name[MAX_TABLE_NAME_LEN];
#endif
fk_key = static_cast<Foreign_key*>(key);
@@ -881,24 +880,29 @@ innobase_get_foreign_key_info(
add_fk[num_fk] = dict_mem_foreign_create();
#ifndef __WIN__
tbl_namep = fk_key->ref_table.str;
tbl_name_len = fk_key->ref_table.length;
db_namep = fk_key->ref_db.str;
db_name_len = fk_key->ref_db.length;
if(fk_key->ref_db.str) {
tablename_to_filename(fk_key->ref_db.str, db_name,
MAX_DATABASE_NAME_LEN);
db_namep = db_name;
db_name_len = strlen(db_name);
}
if (fk_key->ref_table.str) {
tablename_to_filename(fk_key->ref_table.str, tbl_name,
MAX_TABLE_NAME_LEN);
tbl_namep = tbl_name;
tbl_name_len = strlen(tbl_name);
}
#else
ut_ad(fk_key->ref_table.str);
memcpy(tbl_name, fk_key->ref_table.str,
fk_key->ref_table.length);
tbl_name[fk_key->ref_table.length] = 0;
tablename_to_filename(fk_key->ref_table.str, tbl_name,
MAX_TABLE_NAME_LEN);
innobase_casedn_str(tbl_name);
tbl_name_len = strlen(tbl_name);
tbl_namep = &tbl_name[0];
if (fk_key->ref_db.str != NULL) {
memcpy(db_name, fk_key->ref_db.str,
fk_key->ref_db.length);
db_name[fk_key->ref_db.length] = 0;
tablename_to_filename(fk_key->ref_db.str, db_name,
MAX_DATABASE_NAME_LEN);
innobase_casedn_str(db_name);
db_name_len = strlen(db_name);
db_namep = &db_name[0];

0 comments on commit 1fae0d4

Please sign in to comment.