summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorAnnamalai Gurusami <annamalai.gurusami@oracle.com>2013-02-12 15:35:56 +0530
committerAnnamalai Gurusami <annamalai.gurusami@oracle.com>2013-02-12 15:35:56 +0530
commitb2e8e0de4fa33d898985c45ac2386afce52ae5a1 (patch)
tree743332f17cdd9a87527f4eb28654131c4ad3c2fc /storage
parent2df2e2617cc75ad532e59a294672f3aab071defe (diff)
parent8aecb30cdd1eea3517684dfc8d9d598b59396316 (diff)
downloadmariadb-git-b2e8e0de4fa33d898985c45ac2386afce52ae5a1.tar.gz
Merge from mysql-5.1 to mysql-5.5.
Diffstat (limited to 'storage')
-rw-r--r--storage/innobase/dict/dict0crea.c9
-rw-r--r--storage/innobase/dict/dict0dict.c5
-rw-r--r--storage/innobase/handler/ha_innodb.cc34
-rw-r--r--storage/innobase/include/db0err.h1
-rw-r--r--storage/innobase/include/ha_prototypes.h11
-rw-r--r--storage/innobase/ut/ut0ut.c2
6 files changed, 61 insertions, 1 deletions
diff --git a/storage/innobase/dict/dict0crea.c b/storage/innobase/dict/dict0crea.c
index d7373a4b8ef..cb3dbcbe4ac 100644
--- a/storage/innobase/dict/dict0crea.c
+++ b/storage/innobase/dict/dict0crea.c
@@ -42,6 +42,7 @@ Created 1/8/1996 Heikki Tuuri
#include "trx0roll.h"
#include "usr0sess.h"
#include "ut0vec.h"
+#include "ha_prototypes.h"
/*****************************************************************//**
Based on a table object, this function builds the entry to be inserted
@@ -1427,12 +1428,20 @@ dict_create_add_foreign_to_dictionary(
pars_info_t* info = pars_info_create();
if (foreign->id == NULL) {
+ char* stripped_name;
/* Generate a new constraint id */
ulint namelen = strlen(table->name);
char* id = mem_heap_alloc(foreign->heap, namelen + 20);
/* no overflow if number < 1e13 */
sprintf(id, "%s_ibfk_%lu", table->name, (ulong) (*id_nr)++);
foreign->id = id;
+
+ stripped_name = strchr(foreign->id, '/') + 1;
+ if (innobase_check_identifier_length(stripped_name)) {
+ fprintf(stderr, "InnoDB: Generated foreign key "
+ "name (%s) is too long\n", foreign->id);
+ return(DB_IDENTIFIER_TOO_LONG);
+ }
}
pars_info_add_str_literal(info, "id", foreign->id);
diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c
index 1acb0f7efe5..a887ff0b1ca 100644
--- a/storage/innobase/dict/dict0dict.c
+++ b/storage/innobase/dict/dict0dict.c
@@ -4679,6 +4679,7 @@ dict_print_info_on_foreign_key_in_create_format(
dict_foreign_t* foreign, /*!< in: foreign key constraint */
ibool add_newline) /*!< in: whether to add a newline */
{
+ char constraint_name[MAX_TABLE_NAME_LEN];
const char* stripped_id;
ulint i;
@@ -4700,7 +4701,9 @@ dict_print_info_on_foreign_key_in_create_format(
}
fputs(" CONSTRAINT ", file);
- ut_print_name(file, trx, FALSE, stripped_id);
+ innobase_convert_from_id(&my_charset_filename, constraint_name,
+ stripped_id, MAX_TABLE_NAME_LEN);
+ ut_print_name(file, trx, FALSE, constraint_name);
fputs(" FOREIGN KEY (", file);
for (i = 0;;) {
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 5b7502209d5..5d9bf04e664 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -1075,6 +1075,9 @@ convert_error_code_to_mysql(
return(HA_ERR_UNDO_REC_TOO_BIG);
case DB_OUT_OF_MEMORY:
return(HA_ERR_OUT_OF_MEM);
+ case DB_IDENTIFIER_TOO_LONG:
+ my_error(ER_TOO_LONG_IDENT, MYF(0));
+ return(HA_ERR_INTERNAL_ERROR);
}
}
@@ -1155,6 +1158,37 @@ innobase_convert_from_table_id(
strconvert(cs, from, &my_charset_filename, to, (uint) len, &errors);
}
+/**********************************************************************
+Check if the length of the identifier exceeds the maximum allowed.
+The input to this function is an identifier in charset my_charset_filename.
+return true when length of identifier is too long. */
+extern "C" UNIV_INTERN
+my_bool
+innobase_check_identifier_length(
+/*=============================*/
+ const char* id) /* in: identifier to check. it must belong
+ to charset my_charset_filename */
+{
+ char tmp[MAX_TABLE_NAME_LEN + 10];
+ uint errors;
+ uint len;
+ int well_formed_error = 0;
+ CHARSET_INFO* cs1 = &my_charset_filename;
+ CHARSET_INFO* cs2 = thd_charset(current_thd);
+
+ len = strconvert(cs1, id, cs2, tmp, MAX_TABLE_NAME_LEN + 10, &errors);
+
+ uint res = cs2->cset->well_formed_len(cs2, tmp, tmp + len,
+ NAME_CHAR_LEN,
+ &well_formed_error);
+
+ if (well_formed_error || res != len) {
+ my_error(ER_TOO_LONG_IDENT, MYF(0), tmp);
+ return(true);
+ }
+ return(false);
+}
+
/******************************************************************//**
Converts an identifier to UTF-8. */
extern "C" UNIV_INTERN
diff --git a/storage/innobase/include/db0err.h b/storage/innobase/include/db0err.h
index 95ccef16be0..b27bc954940 100644
--- a/storage/innobase/include/db0err.h
+++ b/storage/innobase/include/db0err.h
@@ -114,6 +114,7 @@ enum db_err {
DB_UNDO_RECORD_TOO_BIG, /* the undo log record is too big */
DB_TABLE_IN_FK_CHECK, /* table is being used in foreign
key check */
+ DB_IDENTIFIER_TOO_LONG, /* Identifier name too long */
/* The following are partial failure codes */
DB_FAIL = 1000,
diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h
index edf7a1a28c1..ae0188fdaa1 100644
--- a/storage/innobase/include/ha_prototypes.h
+++ b/storage/innobase/include/ha_prototypes.h
@@ -296,4 +296,15 @@ ulint
innobase_get_lower_case_table_names(void);
/*=====================================*/
+/**********************************************************************
+Check if the length of the identifier exceeds the maximum allowed.
+The input to this function is an identifier in charset my_charset_filename.
+return true when length of identifier is too long. */
+UNIV_INTERN
+my_bool
+innobase_check_identifier_length(
+/*=============================*/
+ const char* id); /* in: identifier to check. it must belong
+ to charset my_charset_filename */
+
#endif
diff --git a/storage/innobase/ut/ut0ut.c b/storage/innobase/ut/ut0ut.c
index 2fe45aad2a7..699af1fcaa1 100644
--- a/storage/innobase/ut/ut0ut.c
+++ b/storage/innobase/ut/ut0ut.c
@@ -728,6 +728,8 @@ ut_strerr(
return("End of index");
case DB_TABLE_IN_FK_CHECK:
return("Table is being used in foreign key check");
+ case DB_IDENTIFIER_TOO_LONG:
+ return("Identifier name is too long");
/* do not add default: in order to produce a warning if new code
is added to the enum but not added here */
}