diff options
author | unknown <mskold@mysql.com> | 2004-12-06 14:51:10 +0100 |
---|---|---|
committer | unknown <mskold@mysql.com> | 2004-12-06 14:51:10 +0100 |
commit | c6b3c442a5ba34c027a7fa405620e9a1684ed50d (patch) | |
tree | f201e8bf2eaec493e1061ae5458aa6629dfb0c9a /sql/ha_ndbcluster.cc | |
parent | 04866cf0f1c9341dff58e45c5063508f83e8aeb8 (diff) | |
download | mariadb-git-c6b3c442a5ba34c027a7fa405620e9a1684ed50d.tar.gz |
Fix for bug#6935 table rename does not work with ndb tables
Diffstat (limited to 'sql/ha_ndbcluster.cc')
-rw-r--r-- | sql/ha_ndbcluster.cc | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 6c609cd54ac..7054619fdab 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -3627,9 +3627,13 @@ int ha_ndbcluster::create_index(const char *name, int ha_ndbcluster::rename_table(const char *from, const char *to) { + NDBDICT *dict; char new_tabname[FN_HEADLEN]; + const NDBTAB *orig_tab; + int result; DBUG_ENTER("ha_ndbcluster::rename_table"); + DBUG_PRINT("info", ("Renaming %s to %s", from, to)); set_dbname(from); set_tabname(from); set_tabname(to, new_tabname); @@ -3637,14 +3641,20 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) if (check_ndb_connection()) DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION); + dict= m_ndb->getDictionary(); + if (!(orig_tab= dict->getTable(m_tabname))) + ERR_RETURN(dict->getNdbError()); - int result= alter_table_name(m_tabname, new_tabname); - if (result == 0) + m_table= (void *)orig_tab; + // Change current database to that of target table + set_dbname(to); + m_ndb->setDatabaseName(m_dbname); + if (!(result= alter_table_name(new_tabname))) { - set_tabname(to); - handler::rename_table(from, to); + // Rename .ndb file + result= handler::rename_table(from, to); } - + DBUG_RETURN(result); } @@ -3653,19 +3663,16 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) Rename a table in NDB Cluster using alter table */ -int ha_ndbcluster::alter_table_name(const char *from, const char *to) +int ha_ndbcluster::alter_table_name(const char *to) { - NDBDICT *dict= m_ndb->getDictionary(); - const NDBTAB *orig_tab; + NDBDICT * dict= m_ndb->getDictionary(); + const NDBTAB *orig_tab= (const NDBTAB *) m_table; + int ret; DBUG_ENTER("alter_table_name_table"); - DBUG_PRINT("enter", ("Renaming %s to %s", from, to)); - if (!(orig_tab= dict->getTable(from))) - ERR_RETURN(dict->getNdbError()); - - NdbDictionary::Table copy_tab= dict->getTableForAlteration(from); - copy_tab.setName(to); - if (dict->alterTable(copy_tab) != 0) + NdbDictionary::Table new_tab= dict->getTableForAlteration(*orig_tab); + new_tab.setName(to); + if (dict->alterTable(new_tab) != 0) ERR_RETURN(dict->getNdbError()); m_table= NULL; @@ -3688,7 +3695,7 @@ int ha_ndbcluster::delete_table(const char *name) if (check_ndb_connection()) DBUG_RETURN(HA_ERR_NO_CONNECTION); - + // Remove .ndb file handler::delete_table(name); DBUG_RETURN(drop_table()); } @@ -3944,6 +3951,7 @@ Ndb* check_ndb_in_thd(THD* thd) } + int ha_ndbcluster::check_ndb_connection() { THD* thd= current_thd; |