From 87ac01c3d4916f665d3497999c6bf1cc29280ec9 Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Wed, 19 Oct 2016 15:23:02 -0500 Subject: [PATCH] MCOL-218: Make drop database work in the columnstore engine. --- dbcon/mysql/ha_calpont_ddl.cpp | 11 ++++++++++- dbcon/mysql/ha_calpont_impl.cpp | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dbcon/mysql/ha_calpont_ddl.cpp b/dbcon/mysql/ha_calpont_ddl.cpp index 6133778e5..e7889afea 100755 --- a/dbcon/mysql/ha_calpont_ddl.cpp +++ b/dbcon/mysql/ha_calpont_ddl.cpp @@ -2043,7 +2043,16 @@ int ha_calpont_impl_delete_table_(const char *db, const char *name, cal_connecti } string emsg; - stmt = thd->query(); + if (thd->lex->sql_command == SQLCOM_DROP_DB) + { + std::string tableName = std::string(name); + tableName.erase(0,tableName.rfind("/")+1); + stmt = std::string("DROP TABLE ") + std::string(tableName); + } + else + { + stmt = thd->query(); + } stmt += ";"; int rc = ProcessDDLStatement(stmt, schema, tbl, tid2sid(thd->thread_id), emsg); // cout << "ProcessDDLStatement rc=" << rc << endl; diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index 25cd2b9ea..1202ad241 100755 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -3161,6 +3161,7 @@ int ha_calpont_impl_create(const char *name, TABLE *table_arg, HA_CREATE_INFO *c int ha_calpont_impl_delete_table(const char *name) { THD *thd = current_thd; + char *dbName = NULL; if (!name) { @@ -3183,16 +3184,17 @@ int ha_calpont_impl_delete_table(const char *name) if (!thd->lex) return 0; if (!idb_mysql_query_str(thd)) return 0; - // @bug 1700. if (thd->lex->sql_command == SQLCOM_DROP_DB) { - thd->get_stmt_da()->set_overwrite_status(true); - thd->raise_error_printf(ER_CHECK_NOT_IMPLEMENTED, "Non-empty database can not be dropped. "); - return 1; + dbName = thd->lex->name.str; + } + else + { + TABLE_LIST *first_table= (TABLE_LIST*) thd->lex->select_lex.table_list.first; + dbName = first_table->db; } - TABLE_LIST *first_table= (TABLE_LIST*) thd->lex->select_lex.table_list.first; - if (!first_table->db) + if (!dbName) { setError(thd, ER_INTERNAL_ERROR, "Drop Table with NULL schema not permitted"); return 1; @@ -3206,7 +3208,7 @@ int ha_calpont_impl_delete_table(const char *name) return 0; } // @bug 1793. make vtable droppable in calpontsys. "$vtable" ==> "@0024vtable" passed in as name. - if (strcmp(first_table->db, "calpontsys") == 0 && string(name).find("@0024vtable") == string::npos) + if (strcmp(dbName, "calpontsys") == 0 && string(name).find("@0024vtable") == string::npos) { std::string stmt(idb_mysql_query_str(thd)); algorithm::to_upper(stmt); @@ -3219,7 +3221,7 @@ int ha_calpont_impl_delete_table(const char *name) return 1; } - int rc = ha_calpont_impl_delete_table_(first_table->db, name, *ci); + int rc = ha_calpont_impl_delete_table_(dbName, name, *ci); return rc; } int ha_calpont_impl_write_row(uchar *buf, TABLE* table)