@@ -226,10 +226,10 @@ dd::enum_column_types get_new_field_type(enum_field_types type) {
226
226
*/
227
227
228
228
dd::String_type get_sql_type_by_create_field (TABLE *table,
229
- Create_field * field) {
229
+ const Create_field & field) {
230
230
DBUG_TRACE;
231
231
232
- unique_ptr_destroy_only<Field> fld (make_field (* field, table->s ));
232
+ unique_ptr_destroy_only<Field> fld (make_field (field, table->s ));
233
233
fld->init (table);
234
234
235
235
// Read column display type.
@@ -539,72 +539,69 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
539
539
//
540
540
// Iterate through all the table columns
541
541
//
542
- Create_field *field;
543
- List_iterator<Create_field> it (
544
- const_cast <List<Create_field> &>(create_fields));
545
- while ((field = it++)) {
542
+ for (const Create_field &field : create_fields) {
546
543
//
547
544
// Add new DD column
548
545
//
549
546
550
547
dd::Column *col_obj = tab_obj->add_column ();
551
548
552
- col_obj->set_name (field-> field_name );
549
+ col_obj->set_name (field. field_name );
553
550
554
- col_obj->set_type (dd::get_new_field_type (field-> sql_type ));
551
+ col_obj->set_type (dd::get_new_field_type (field. sql_type ));
555
552
556
- col_obj->set_char_length (field-> max_display_width_in_bytes ());
553
+ col_obj->set_char_length (field. max_display_width_in_bytes ());
557
554
558
555
// Set result numeric scale.
559
556
uint value = 0 ;
560
- if (get_field_numeric_scale (field, &value) == false )
557
+ if (get_field_numeric_scale (& field, &value) == false )
561
558
col_obj->set_numeric_scale (value);
562
559
563
560
// Set result numeric precision.
564
- if (get_field_numeric_precision (field, &value) == false )
561
+ if (get_field_numeric_precision (& field, &value) == false )
565
562
col_obj->set_numeric_precision (value);
566
563
567
564
// Set result datetime precision.
568
- if (get_field_datetime_precision (field, &value) == false )
565
+ if (get_field_datetime_precision (& field, &value) == false )
569
566
col_obj->set_datetime_precision (value);
570
567
571
- col_obj->set_nullable (field-> maybe_null );
568
+ col_obj->set_nullable (field. maybe_null );
572
569
573
- col_obj->set_unsigned (field-> is_unsigned );
570
+ col_obj->set_unsigned (field. is_unsigned );
574
571
575
- col_obj->set_zerofill (field-> is_zerofill );
572
+ col_obj->set_zerofill (field. is_zerofill );
576
573
577
- col_obj->set_srs_id (field-> m_srid );
574
+ col_obj->set_srs_id (field. m_srid );
578
575
579
576
// Check that the hidden type isn't the type that is used internally by
580
577
// storage engines.
581
- DBUG_ASSERT (field-> hidden != dd::Column::enum_hidden_type::HT_HIDDEN_SE);
582
- col_obj->set_hidden (field-> hidden );
578
+ DBUG_ASSERT (field. hidden != dd::Column::enum_hidden_type::HT_HIDDEN_SE);
579
+ col_obj->set_hidden (field. hidden );
583
580
584
581
/*
585
582
AUTO_INCREMENT, DEFAULT/ON UPDATE CURRENT_TIMESTAMP properties are
586
583
stored in Create_field::auto_flags.
587
584
*/
588
- if (field-> auto_flags & Field::DEFAULT_NOW)
589
- col_obj->set_default_option (now_with_opt_decimals (field-> decimals ));
585
+ if (field. auto_flags & Field::DEFAULT_NOW)
586
+ col_obj->set_default_option (now_with_opt_decimals (field. decimals ));
590
587
591
- if (field-> auto_flags & Field::ON_UPDATE_NOW)
592
- col_obj->set_update_option (now_with_opt_decimals (field-> decimals ));
588
+ if (field. auto_flags & Field::ON_UPDATE_NOW)
589
+ col_obj->set_update_option (now_with_opt_decimals (field. decimals ));
593
590
594
- col_obj->set_auto_increment ((field-> auto_flags & Field::NEXT_NUMBER) != 0 );
591
+ col_obj->set_auto_increment ((field. auto_flags & Field::NEXT_NUMBER) != 0 );
595
592
596
593
// Handle generated default
597
- if (field-> m_default_val_expr ) {
594
+ if (field. m_default_val_expr ) {
598
595
char buffer[128 ];
599
596
String default_val_expr (buffer, sizeof (buffer), &my_charset_bin);
600
597
// Convert the expression from Item* to text
601
- field-> m_default_val_expr ->print_expr (thd, &default_val_expr);
598
+ field. m_default_val_expr ->print_expr (thd, &default_val_expr);
602
599
col_obj->set_default_option (
603
600
dd::String_type (default_val_expr.ptr (), default_val_expr.length ()));
604
601
}
605
602
606
603
// Handle generated columns
607
- if (field-> gcol_info ) {
604
+ if (field. gcol_info ) {
608
605
/*
609
606
It is important to normalize the expression's text into the DD, to
610
607
make it independent from sql_mode. For example, 'a||b' means 'a OR b'
@@ -614,8 +611,8 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
614
611
*/
615
612
char buffer[128 ];
616
613
String gc_expr (buffer, sizeof (buffer), &my_charset_bin);
617
- col_obj->set_virtual (!field-> stored_in_db );
618
- field-> gcol_info ->print_expr (thd, &gc_expr);
614
+ col_obj->set_virtual (!field. stored_in_db );
615
+ field. gcol_info ->print_expr (thd, &gc_expr);
619
616
col_obj->set_generation_expression (
620
617
dd::String_type (gc_expr.ptr (), gc_expr.length ()));
621
618
@@ -627,41 +624,41 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
627
624
dd::String_type (gc_expr_for_IS.ptr (), gc_expr_for_IS.length ()));
628
625
}
629
626
630
- if (field-> comment .str && field-> comment .length )
627
+ if (field. comment .str && field. comment .length )
631
628
col_obj->set_comment (
632
- dd::String_type (field-> comment .str , field-> comment .length ));
629
+ dd::String_type (field. comment .str , field. comment .length ));
633
630
634
631
// Collation ID
635
- col_obj->set_collation_id (field-> charset ->number );
632
+ col_obj->set_collation_id (field. charset ->number );
636
633
637
634
// Was collation supplied explicitly ?
638
- col_obj->set_is_explicit_collation (field-> is_explicit_collation );
635
+ col_obj->set_is_explicit_collation (field. is_explicit_collation );
639
636
640
637
/*
641
638
Store numeric scale for types relying on this info (old and new decimal
642
639
and floating point types). Also store 0 for integer types to simplify I_S
643
640
implementation.
644
641
*/
645
- switch (field-> sql_type ) {
642
+ switch (field. sql_type ) {
646
643
case MYSQL_TYPE_FLOAT:
647
644
case MYSQL_TYPE_DOUBLE:
648
645
/* For these types we show NULL in I_S if scale was not given. */
649
- if (field-> decimals != DECIMAL_NOT_SPECIFIED)
650
- col_obj->set_numeric_scale (field-> decimals );
646
+ if (field. decimals != DECIMAL_NOT_SPECIFIED)
647
+ col_obj->set_numeric_scale (field. decimals );
651
648
else {
652
649
DBUG_ASSERT (col_obj->is_numeric_scale_null ());
653
650
}
654
651
break ;
655
652
case MYSQL_TYPE_NEWDECIMAL:
656
653
case MYSQL_TYPE_DECIMAL:
657
- col_obj->set_numeric_scale (field-> decimals );
654
+ col_obj->set_numeric_scale (field. decimals );
658
655
break ;
659
656
case MYSQL_TYPE_TINY:
660
657
case MYSQL_TYPE_SHORT:
661
658
case MYSQL_TYPE_LONG:
662
659
case MYSQL_TYPE_INT24:
663
660
case MYSQL_TYPE_LONGLONG:
664
- DBUG_ASSERT (field-> decimals == 0 );
661
+ DBUG_ASSERT (field. decimals == 0 );
665
662
col_obj->set_numeric_scale (0 );
666
663
break ;
667
664
default :
@@ -681,41 +678,41 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
681
678
when SE starts supporting optimized BIT storage but still needs
682
679
to handle correctly columns which were created before this change.
683
680
*/
684
- if (field-> sql_type == MYSQL_TYPE_BIT)
685
- col_options->set (" treat_bit_as_char" , field-> treat_bit_as_char );
681
+ if (field. sql_type == MYSQL_TYPE_BIT)
682
+ col_options->set (" treat_bit_as_char" , field. treat_bit_as_char );
686
683
687
684
// Store geometry sub type
688
- if (field-> sql_type == MYSQL_TYPE_GEOMETRY) {
689
- col_options->set (" geom_type" , field-> geom_type );
685
+ if (field. sql_type == MYSQL_TYPE_GEOMETRY) {
686
+ col_options->set (" geom_type" , field. geom_type );
690
687
}
691
688
692
689
// Field storage media and column format options
693
- if (field-> field_storage_type () != HA_SM_DEFAULT)
690
+ if (field. field_storage_type () != HA_SM_DEFAULT)
694
691
col_options->set (" storage" ,
695
- static_cast <uint32>(field-> field_storage_type ()));
692
+ static_cast <uint32>(field. field_storage_type ()));
696
693
697
- if (field-> column_format () != COLUMN_FORMAT_TYPE_DEFAULT)
694
+ if (field. column_format () != COLUMN_FORMAT_TYPE_DEFAULT)
698
695
col_options->set (" column_format" ,
699
- static_cast <uint32>(field-> column_format ()));
696
+ static_cast <uint32>(field. column_format ()));
700
697
701
698
// NOT SECONDARY column option.
702
- if (field-> flags & NOT_SECONDARY_FLAG)
699
+ if (field. flags & NOT_SECONDARY_FLAG)
703
700
col_options->set (" not_secondary" , true );
704
701
705
- if (field-> is_array ) {
702
+ if (field. is_array ) {
706
703
col_options->set (" is_array" , true );
707
704
}
708
705
709
706
//
710
707
// Write intervals
711
708
//
712
709
uint i = 0 ;
713
- if (field-> interval ) {
710
+ if (field. interval ) {
714
711
uchar buff[MAX_FIELD_WIDTH];
715
712
String tmp ((char *)buff, sizeof (buff), &my_charset_bin);
716
713
tmp.length (0 );
717
714
718
- for (const char **pos = field-> interval ->type_names ; *pos; pos++) {
715
+ for (const char **pos = field. interval ->type_names ; *pos; pos++) {
719
716
//
720
717
// Create enum/set object
721
718
//
@@ -726,7 +723,7 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
726
723
727
724
// Copy type_lengths[i] bytes including '\0'
728
725
// This helps store typelib names that are of different charsets.
729
- dd::String_type interval_name (*pos, field-> interval ->type_lengths [i]);
726
+ dd::String_type interval_name (*pos, field. interval ->type_lengths [i]);
730
727
elem_obj->set_name (interval_name);
731
728
732
729
i++;
@@ -740,13 +737,13 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
740
737
col_options->set (" interval_count" , i);
741
738
742
739
// Store geometry sub type
743
- if (field-> sql_type == MYSQL_TYPE_GEOMETRY) {
744
- col_options->set (" geom_type" , field-> geom_type );
740
+ if (field. sql_type == MYSQL_TYPE_GEOMETRY) {
741
+ col_options->set (" geom_type" , field. geom_type );
745
742
}
746
743
747
744
// Reset the buffer and assign the column's default value.
748
745
memset (buf, 0 , bufsize);
749
- if (prepare_default_value (thd, buf, table, * field, col_obj)) return true ;
746
+ if (prepare_default_value (thd, buf, table, field, col_obj)) return true ;
750
747
751
748
/* *
752
749
Storing default value specified for column in
@@ -763,7 +760,7 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
763
760
prepared in prepare_default_value() is used.
764
761
*/
765
762
String def_val;
766
- prepare_default_value_string (buf, &table, * field, col_obj, &def_val);
763
+ prepare_default_value_string (buf, &table, field, col_obj, &def_val);
767
764
if (def_val.ptr () != nullptr )
768
765
col_obj->set_default_value_utf8 (
769
766
dd::String_type (def_val.ptr (), def_val.length ()));
@@ -917,7 +914,7 @@ static void fill_dd_index_elements_from_key_parts(
917
914
}
918
915
919
916
// Check if a given key is candidate to be promoted to primary key.
920
- static bool is_candidate_primary_key (THD *thd, KEY *key,
917
+ static bool is_candidate_primary_key (THD *thd, const KEY *key,
921
918
const List<Create_field> &create_fields) {
922
919
KEY_PART_INFO *key_part;
923
920
KEY_PART_INFO *key_part_end = key->key_part + key->user_defined_key_parts ;
@@ -1095,7 +1092,7 @@ static void fill_dd_indexes_from_keyinfo(
1095
1092
fill_dd_index_elements_from_key_parts() about the same.
1096
1093
*/
1097
1094
if (primary_key_info == nullptr &&
1098
- is_candidate_primary_key (thd, const_cast <KEY *>( key) , create_fields)) {
1095
+ is_candidate_primary_key (thd, key, create_fields)) {
1099
1096
primary_key_info = key;
1100
1097
}
1101
1098
@@ -2630,7 +2627,7 @@ dd::String_type get_sql_type_by_field_info(THD *thd,
2630
2627
is_unsigned, 0 );
2631
2628
field.charset = field_charset;
2632
2629
2633
- return get_sql_type_by_create_field (&table, & field);
2630
+ return get_sql_type_by_create_field (&table, field);
2634
2631
}
2635
2632
2636
2633
bool fix_row_type (THD *thd, dd::Table *table_def, row_type correct_row_type) {
0 commit comments