From e86fc82cf27303a0fe165b4567291ae228491302 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Oct 2003 20:02:27 +0200 Subject: [PATCH] bug #1434 (and related issues) --- mysql-test/t/create.test | 22 +++++++++++++++++++++- sql/sql_class.h | 4 ++-- sql/sql_insert.cc | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index d46807f1dca..815aad560b1 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -129,8 +129,28 @@ insert into t1 values ("a", 1), ("b", 2); drop table t1; # -# Bug # 801 +# Bug #801 # create table t1 select x'4132'; drop table t1; + +# +# bug #1434 +# + +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +--error 1136 +create table if not exists t1 select 1,2,3,4; +create table if not exists t1 select 1; +select * from t1; +drop table t1; +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +--error 1136 +create table if not exists t1 select 1,2,3,4; +create table if not exists t1 select 1; +select * from t1; +drop table t1; + diff --git a/sql/sql_class.h b/sql/sql_class.h index 2ed9cb7b877..bf626eb7d92 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -703,6 +703,7 @@ class select_create: public select_insert { HA_CREATE_INFO *create_info; MYSQL_LOCK *lock; Field **field; + my_bool do_not_drop; public: select_create (const char *db_name, const char *table_name, HA_CREATE_INFO *create_info_par, @@ -711,8 +712,7 @@ public: List &select_fields,enum_duplicates duplic) :select_insert (NULL, &select_fields, duplic), db(db_name), name(table_name), extra_fields(&fields_par),keys(&keys_par), - create_info(create_info_par), - lock(0) + create_info(create_info_par), lock(0), do_not_drop(0) {} int prepare(List &list); bool send_data(List &values); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0a83358e8c6..ad08ad6ccd6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1438,6 +1438,15 @@ select_create::prepare(List &values) if (!table) DBUG_RETURN(-1); // abort() deletes table + if (table->fields < values.elements) + { + do_not_drop=1; + my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, + ER(ER_WRONG_VALUE_COUNT_ON_ROW), + MYF(0),1); + DBUG_RETURN(-1); + } + /* First field to copy */ field=table->field+table->fields - values.elements; @@ -1498,7 +1507,7 @@ bool select_create::send_eof() */ if (!table->tmp_table) hash_delete(&open_cache,(byte*) table); - lock=0; + lock=0; table=0; VOID(pthread_mutex_unlock(&LOCK_open)); } @@ -1519,7 +1528,8 @@ void select_create::abort() enum db_type table_type=table->db_type; if (!table->tmp_table) hash_delete(&open_cache,(byte*) table); - quick_rm_table(table_type,db,name); + if (!do_not_drop) + quick_rm_table(table_type,db,name); table=0; } VOID(pthread_mutex_unlock(&LOCK_open));