Commit 13cf5e6b authored by unknown's avatar unknown

fix for the 2361 bug: ALTER TABLE ... DROP PRIMARY KEY drops a non-primary key

"PRIMARY" has been replaced by primary_key_name.


sql/mysql_priv.h:
  "PRIMARY" replaced by primary_key_name.
sql/sql_help.cc:
  "PRIMARY" replaced by primary_key_name.
sql/sql_select.cc:
  "PRIMARY" replaced by primary_key_name.
sql/sql_show.cc:
  "PRIMARY" replaced by primary_key_name.
sql/sql_table.cc:
  fix for the 2361 bug: ALTER TABLE ... DROP PRIMARY KEY drops a non-primary key
  "PRIMARY" replaced by primary_key_name.
sql/table.cc:
  "PRIMARY" replaced by primary_key_name.
parent d228cd2e
...@@ -38,6 +38,7 @@ typedef ulong key_part_map; /* Used for finding key parts */ ...@@ -38,6 +38,7 @@ typedef ulong key_part_map; /* Used for finding key parts */
/* useful constants */ /* useful constants */
extern const key_map key_map_empty; extern const key_map key_map_empty;
extern const key_map key_map_full; extern const key_map key_map_full;
extern const char *primary_key_name;
#include "mysql_com.h" #include "mysql_com.h"
#include <violite.h> #include <violite.h>
......
...@@ -274,9 +274,9 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, ...@@ -274,9 +274,9 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations,
DBUG_ENTER("get_topics_for_keyword"); DBUG_ENTER("get_topics_for_keyword");
if ((iindex_topic= find_type((char*) "PRIMARY", if ((iindex_topic= find_type((char*) primary_key_name,
&topics->keynames, 1+2)-1)<0 || &topics->keynames, 1+2)-1)<0 ||
(iindex_relations= find_type((char*) "PRIMARY", (iindex_relations= find_type((char*) primary_key_name,
&relations->keynames, 1+2)-1)<0) &relations->keynames, 1+2)-1)<0)
{ {
send_error(thd,ER_CORRUPT_HELP_DB); send_error(thd,ER_CORRUPT_HELP_DB);
......
...@@ -9130,16 +9130,16 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) ...@@ -9130,16 +9130,16 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
{ {
res= mysql_explain_select(thd, sl, res= mysql_explain_select(thd, sl,
(((&thd->lex->select_lex)==sl)? (((&thd->lex->select_lex)==sl)?
((thd->lex->all_selects_list != sl)?"PRIMARY": ((thd->lex->all_selects_list != sl) ?
"SIMPLE"): primary_key_name : "SIMPLE"):
((sl == first)? ((sl == first)?
((sl->linkage == DERIVED_TABLE_TYPE) ? ((sl->linkage == DERIVED_TABLE_TYPE) ?
"DERIVED": "DERIVED":
((sl->uncacheable & UNCACHEABLE_DEPENDENT)? ((sl->uncacheable & UNCACHEABLE_DEPENDENT) ?
"DEPENDENT SUBQUERY": "DEPENDENT SUBQUERY":
(sl->uncacheable?"UNCACHEABLE SUBQUERY": (sl->uncacheable?"UNCACHEABLE SUBQUERY":
"SUBQUERY"))): "SUBQUERY"))):
((sl->uncacheable & UNCACHEABLE_DEPENDENT)? ((sl->uncacheable & UNCACHEABLE_DEPENDENT) ?
"DEPENDENT UNION": "DEPENDENT UNION":
sl->uncacheable?"UNCACHEABLE UNION": sl->uncacheable?"UNCACHEABLE UNION":
"UNION"))), "UNION"))),
......
...@@ -1167,7 +1167,7 @@ store_create_info(THD *thd, TABLE *table, String *packet) ...@@ -1167,7 +1167,7 @@ store_create_info(THD *thd, TABLE *table, String *packet)
bool found_primary=0; bool found_primary=0;
packet->append(",\n ", 4); packet->append(",\n ", 4);
if (i == primary_key && !strcmp(key_info->name,"PRIMARY")) if (i == primary_key && !strcmp(key_info->name, primary_key_name))
{ {
found_primary=1; found_primary=1;
packet->append("PRIMARY ", 8); packet->append("PRIMARY ", 8);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <io.h> #include <io.h>
#endif #endif
static const char *primary_key_name="PRIMARY"; const char *primary_key_name= "PRIMARY";
static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end); static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end); static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
...@@ -2244,8 +2244,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -2244,8 +2244,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{ {
char *key_name= key_info->name; char *key_name= key_info->name;
if (drop_primary && !my_strcasecmp(system_charset_info, key_name, if (drop_primary && (key_info-> flags & HA_NOSAME) &&
"PRIMARY")) !my_strcasecmp(system_charset_info, key_name, primary_key_name))
{ {
drop_primary= 0; drop_primary= 0;
continue; continue;
...@@ -2305,7 +2305,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -2305,7 +2305,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
key_list.push_back(new Key(key_info->flags & HA_SPATIAL ? Key::SPATIAL : key_list.push_back(new Key(key_info->flags & HA_SPATIAL ? Key::SPATIAL :
(key_info->flags & HA_NOSAME ? (key_info->flags & HA_NOSAME ?
(!my_strcasecmp(system_charset_info, (!my_strcasecmp(system_charset_info,
key_name, "PRIMARY") ? key_name, primary_key_name) ?
Key::PRIMARY : Key::UNIQUE) : Key::PRIMARY : Key::UNIQUE) :
(key_info->flags & HA_FULLTEXT ? (key_info->flags & HA_FULLTEXT ?
Key::FULLTEXT : Key::MULTIPLE)), Key::FULLTEXT : Key::MULTIPLE)),
......
...@@ -481,8 +481,8 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -481,8 +481,8 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
/* Fix key->name and key_part->field */ /* Fix key->name and key_part->field */
if (key_parts) if (key_parts)
{ {
uint primary_key=(uint) (find_type((char*) "PRIMARY",&outparam->keynames, uint primary_key=(uint) (find_type((char*) primary_key_name,
3)-1); &outparam->keynames, 3) - 1);
uint ha_option=outparam->file->table_flags(); uint ha_option=outparam->file->table_flags();
keyinfo=outparam->key_info; keyinfo=outparam->key_info;
key_part=keyinfo->key_part; key_part=keyinfo->key_part;
......
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