1651
1653
that concurrent operations won't intervene. mysql_create_table()
1652
1654
is a wrapper that can be used for this.
1654
no_log is needed for the case of CREATE ... SELECT,
1655
as the logging will be done later in sql_insert.cc
1656
select_field_count is also used for CREATE ... SELECT,
1657
and must be zero for standard create of table.
1682
1678
my_message(ER_TABLE_MUST_HAVE_COLUMNS, ER(ER_TABLE_MUST_HAVE_COLUMNS),
1686
1682
assert(strcmp(table_name,table_proto->name().c_str())==0);
1687
1683
if (check_engine(session, table_name, create_info))
1689
1685
db_options= create_info->table_options;
1690
1686
if (create_info->row_type == ROW_TYPE_DYNAMIC)
1691
1687
db_options|=HA_OPTION_PACK_RECORD;
1745
pthread_mutex_lock(&LOCK_open);
1740
pthread_mutex_lock(&LOCK_open);
1746
1741
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1748
1743
if (table_proto_exists(path)==EEXIST)
1750
1745
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1752
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
1748
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1749
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1751
create_info->table_existed= 1; // Mark that table existed
1754
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
1753
1756
goto unlock_and_end;
1787
1790
/* Normal case, no table exists. we can go and create it */
1789
1792
case HA_ERR_TABLE_EXIST:
1791
1793
if (create_if_not_exists)
1796
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1797
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1799
create_info->table_existed= 1; // Mark that table existed
1800
goto unlock_and_end;
1793
1802
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
1794
1803
goto unlock_and_end;
1854
1863
write_bin_log(session, true, session->query, session->query_length);
1856
1865
unlock_and_end:
1858
pthread_mutex_unlock(&LOCK_open);
1866
pthread_mutex_unlock(&LOCK_open);
1861
1869
session->set_proc_info("After create");
1867
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1868
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1870
create_info->table_existed= 1; // Mark that table existed
1871
goto unlock_and_end;
3190
int create_temporary_table(Session *session,
3194
HA_CREATE_INFO *create_info,
3195
Alter_info *alter_info,
3193
create_temporary_table(Session *session,
3197
HA_CREATE_INFO *create_info,
3198
Alter_info *alter_info,
3199
3202
char index_file[FN_REFLEN], data_file[FN_REFLEN];
3924
3927
if (table_proto_exists(new_name)==EEXIST)
3926
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
3929
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
3931
*fn_ext(new_name)=0;
3932
if (mysql_rename_table(old_db_type, db, table_name, new_db, new_alias, 0))
3934
*fn_ext(new_name)=0;
3935
if (mysql_rename_table(old_db_type, db, table_name, new_db, new_alias, 0))
3936
3939
mysql_rename_table(old_db_type, new_db, new_alias, db,
3937
3940
table_name, 0);
3943
3946
if (error == HA_ERR_WRONG_COMMAND)
3946
3949
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
3947
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
3950
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
4019
4022
/* table is a normal table: Create temporary table in same directory */
4020
4023
build_table_filename(tmp_path, sizeof(tmp_path), new_db, tmp_name, true);
4021
4024
/* Open our intermediate table */
4022
new_table=open_temporary_table(session, tmp_path, new_db, tmp_name, 0, OTM_OPEN);
4025
new_table= open_temporary_table(session, tmp_path, new_db, tmp_name, 0, OTM_OPEN);
4028
if (new_table == NULL)
4027
4031
/* Copy the data if necessary. */
4028
4032
session->count_cuted_fields= CHECK_FIELD_WARN; // calc cuted fields
4029
4033
session->cuted_fields=0L;
4030
4034
session->set_proc_info("copy to tmp table");
4033
We do not copy data for MERGE tables. Only the children have data.
4034
MERGE tables have HA_NO_COPY_ON_ALTER set.
4036
if (new_table && !(new_table->file->ha_table_flags() & HA_NO_COPY_ON_ALTER))
4038
/* We don't want update TIMESTAMP fields during ALTER Table. */
4039
new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
4040
new_table->next_number_field=new_table->found_next_number_field;
4041
error= copy_data_between_tables(table, new_table,
4042
alter_info->create_list, ignore,
4043
order_num, order, &copied, &deleted,
4044
alter_info->keys_onoff,
4045
alter_info->error_if_not_empty);
4049
pthread_mutex_lock(&LOCK_open);
4050
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
4051
pthread_mutex_unlock(&LOCK_open);
4052
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
4053
alter_info->keys_onoff);
4054
error= ha_autocommit_or_rollback(session, 0);
4055
if (! session->endActiveTransaction())
4039
/* We don't want update TIMESTAMP fields during ALTER Table. */
4040
new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
4041
new_table->next_number_field=new_table->found_next_number_field;
4042
error= copy_data_between_tables(table, new_table,
4043
alter_info->create_list, ignore,
4044
order_num, order, &copied, &deleted,
4045
alter_info->keys_onoff,
4046
alter_info->error_if_not_empty);
4058
4048
/* We must not ignore bad input! */;
4059
4049
session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
4141
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4131
quick_rm_table(new_db_type, new_db, tmp_name, true);
4143
4133
else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
4144
4134
new_alias, FN_FROM_IS_TMP) || ((new_name != table_name || new_db != db) && 0))
4146
4136
/* Try to get everything back. */
4148
quick_rm_table(new_db_type, new_db, new_alias, 0);
4149
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4138
quick_rm_table(new_db_type, new_db, new_alias, false);
4139
quick_rm_table(new_db_type, new_db, tmp_name, true);
4150
4140
mysql_rename_table(old_db_type, db, old_name, db, table_name,
4151
4141
FN_FROM_IS_TMP);
4239
4229
close_temporary_table(session, new_table, 1, 1);
4242
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4232
quick_rm_table(new_db_type, new_db, tmp_name, true);