summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc80
1 files changed, 33 insertions, 47 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 91051df29b7..1015e538a8f 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -3043,6 +3043,15 @@ bool check_duplicates_in_interval(const char *set_or_name,
}
+bool Column_definition::
+ prepare_charset_for_string(const Column_derived_attributes *dattr)
+{
+ if (!charset)
+ charset= dattr->charset();
+ return (flags & BINCMP_FLAG) && !(charset= find_bin_collation(charset));
+}
+
+
bool Column_definition::prepare_stage2_blob(handler *file,
ulonglong table_flags,
uint field_flags)
@@ -3123,38 +3132,6 @@ bool Column_definition::prepare_stage2(handler *file,
}
-/*
- Get character set from field object generated by parser using
- default values when not set.
-
- SYNOPSIS
- get_sql_field_charset()
- sql_field The sql_field object
- create_info Info generated by parser
-
- RETURN VALUES
- cs Character set
-*/
-
-CHARSET_INFO* get_sql_field_charset(Column_definition *sql_field,
- HA_CREATE_INFO *create_info)
-{
- CHARSET_INFO *cs= sql_field->charset;
-
- if (!cs)
- cs= create_info->default_table_charset;
- /*
- table_charset is set only in ALTER TABLE t1 CONVERT TO CHARACTER SET csname
- if we want change character set for all varchar/char columns.
- But the table charset must not affect the BLOB fields, so don't
- allow to change my_charset_bin to somethig else.
- */
- if (create_info->table_charset && cs != &my_charset_bin)
- cs= create_info->table_charset;
- return cs;
-}
-
-
/**
Modifies the first column definition whose SQL type is TIMESTAMP
by adding the features DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.
@@ -3327,11 +3304,14 @@ bool Column_definition::prepare_stage1_bit(THD *thd,
bool Column_definition::prepare_stage1(THD *thd,
MEM_ROOT *mem_root,
handler *file,
- ulonglong table_flags)
+ ulonglong table_flags,
+ const Column_derived_attributes
+ *derived_attr)
{
return type_handler()->Column_definition_prepare_stage1(thd, mem_root,
this, file,
- table_flags);
+ table_flags,
+ derived_attr);
}
@@ -3598,6 +3578,9 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
int select_field_count= C_CREATE_SELECT(create_table_mode);
bool tmp_table= create_table_mode == C_ALTER_TABLE;
bool is_hash_field_needed= false;
+ const Column_derived_attributes dattr(create_info->default_table_charset);
+ const Column_bulk_alter_attributes
+ battr(create_info->alter_table_convert_to_charset);
DBUG_ENTER("mysql_prepare_create_table");
DBUG_EXECUTE_IF("test_pseudo_invisible",{
@@ -3653,26 +3636,27 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
for (field_no=0; (sql_field=it++) ; field_no++)
{
+ /* Virtual fields are always NULL */
+ if (sql_field->vcol_info)
+ sql_field->flags&= ~NOT_NULL_FLAG;
+
/*
Initialize length from its original value (number of characters),
which was set in the parser. This is necessary if we're
executing a prepared statement for the second time.
*/
sql_field->length= sql_field->char_length;
- /* Set field charset. */
- sql_field->charset= get_sql_field_charset(sql_field, create_info);
- if ((sql_field->flags & BINCMP_FLAG) &&
- !(sql_field->charset= find_bin_collation(sql_field->charset)))
- DBUG_RETURN(true);
- /* Virtual fields are always NULL */
- if (sql_field->vcol_info)
- sql_field->flags&= ~NOT_NULL_FLAG;
+ if (sql_field->bulk_alter(&dattr, &battr))
+ DBUG_RETURN(true);
if (sql_field->prepare_stage1(thd, thd->mem_root,
- file, file->ha_table_flags()))
+ file, file->ha_table_flags(),
+ &dattr))
DBUG_RETURN(true);
+ DBUG_ASSERT(sql_field->charset);
+
if (sql_field->real_field_type() == MYSQL_TYPE_BIT &&
file->ha_table_flags() & HA_CAN_BIT_FIELD)
total_uneven_bit_length+= sql_field->length & 7;
@@ -3723,7 +3707,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
if (!(sql_field->flags & NOT_NULL_FLAG))
null_fields--;
- if (sql_field->redefine_stage1(dup_field, file, create_info))
+ if (sql_field->redefine_stage1(dup_field, file))
DBUG_RETURN(true);
it2.remove(); // Remove first (create) definition
@@ -4764,7 +4748,9 @@ bool Column_definition::prepare_blob_field(THD *thd)
bool Column_definition::sp_prepare_create_field(THD *thd, MEM_ROOT *mem_root)
{
- return prepare_stage1(thd, mem_root, NULL, HA_CAN_GEOMETRY) ||
+ DBUG_ASSERT(charset);
+ const Column_derived_attributes dattr(&my_charset_bin);
+ return prepare_stage1(thd, mem_root, NULL, HA_CAN_GEOMETRY, &dattr) ||
prepare_stage2(NULL, HA_CAN_GEOMETRY);
}
@@ -11946,8 +11932,8 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
{
create_info.used_fields&= ~HA_CREATE_USED_CHARSET;
create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
- create_info.default_table_charset= create_info.table_charset;
- create_info.table_charset= 0;
+ create_info.default_table_charset= create_info.alter_table_convert_to_charset;
+ create_info.alter_table_convert_to_charset= 0;
}
/*