~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

fix indentation so I can remotely read the function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4021
4021
    */
4022
4022
  Field **f_ptr,*field;
4023
4023
  for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
4024
 
    {
 
4024
  {
4025
4025
    /* Check if field should be dropped */
4026
4026
    Alter_drop *drop;
4027
4027
    drop_it.rewind();
4029
4029
    {
4030
4030
      if (drop->type == Alter_drop::COLUMN &&
4031
4031
          !my_strcasecmp(system_charset_info,field->field_name, drop->name))
4032
 
    {
 
4032
      {
4033
4033
        /* Reset auto_increment value if it was dropped */
4034
4034
        if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
4035
4035
            !(used_fields & HA_CREATE_USED_AUTO))
4036
 
      {
 
4036
        {
4037
4037
          create_info->auto_increment_value=0;
4038
4038
          create_info->used_fields|=HA_CREATE_USED_AUTO;
 
4039
        }
 
4040
        break;
4039
4041
      }
4040
 
        break;
4041
4042
    }
4042
 
  }
4043
4043
    if (drop)
4044
 
      {
 
4044
    {
4045
4045
      drop_it.remove();
4046
4046
      continue;
4047
4047
    }
4064
4064
        goto err;
4065
4065
      }
4066
4066
      if (!def->after)
4067
 
        {
 
4067
      {
4068
4068
        new_create_list.push_back(def);
4069
4069
        def_it.remove();
4070
 
        }
4071
4070
      }
4072
 
      else
4073
 
      {
 
4071
    }
 
4072
    else
 
4073
    {
4074
4074
      /*
4075
4075
        This field was not dropped and not changed, add it to the list
4076
4076
        for the new table.
4080
4080
      alter_it.rewind();                        // Change default if ALTER
4081
4081
      Alter_column *alter;
4082
4082
      while ((alter=alter_it++))
4083
 
        {
 
4083
      {
4084
4084
        if (!my_strcasecmp(system_charset_info,field->field_name, alter->name))
4085
4085
          break;
4086
 
        }
 
4086
      }
4087
4087
      if (alter)
4088
 
        {
 
4088
      {
4089
4089
        if (def->sql_type == DRIZZLE_TYPE_BLOB)
4090
4090
        {
4091
4091
          my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
4107
4107
      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table->s->table_name.str);
4108
4108
      goto err;
4109
4109
    }
4110
 
      /*
 
4110
    /*
4111
4111
      Check that the DATE/DATETIME not null field we are going to add is
4112
4112
      either has a default value or the '0000-00-00' is allowed by the
4113
4113
      set sql mode.
4114
4114
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
4115
4115
      flag to allow ALTER Table only if the table to be altered is empty.
4116
 
      */
 
4116
    */
4117
4117
    if ((def->sql_type == DRIZZLE_TYPE_DATE ||
4118
4118
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
4119
 
         !alter_info->datetime_field &&
4120
 
         !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
4121
 
         session->variables.sql_mode & MODE_NO_ZERO_DATE)
 
4119
        !alter_info->datetime_field &&
 
4120
        !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
 
4121
        session->variables.sql_mode & MODE_NO_ZERO_DATE)
4122
4122
    {
4123
 
        alter_info->datetime_field= def;
4124
 
        alter_info->error_if_not_empty= true;
 
4123
      alter_info->datetime_field= def;
 
4124
      alter_info->error_if_not_empty= true;
4125
4125
    }
4126
4126
    if (!def->after)
4127
4127
      new_create_list.push_back(def);
4135
4135
      {
4136
4136
        if (!my_strcasecmp(system_charset_info,def->after, find->field_name))
4137
4137
          break;
4138
 
  }
 
4138
      }
4139
4139
      if (!find)
4140
 
  {
 
4140
      {
4141
4141
        my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table->s->table_name.str);
4142
 
    goto err;
4143
 
  }
 
4142
        goto err;
 
4143
      }
4144
4144
      find_it.after(def);                       // Put element after this
4145
4145
      /*
4146
4146
        XXX: hack for Bug#28427.
4165
4165
    my_error(ER_BAD_FIELD_ERROR, MYF(0),
4166
4166
             alter_info->alter_list.head()->name, table->s->table_name.str);
4167
4167
    goto err;
4168
 
    }
 
4168
  }
4169
4169
  if (!new_create_list.elements)
4170
 
    {
 
4170
  {
4171
4171
    my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
4172
4172
               MYF(0));
4173
4173
    goto err;
4174
 
    }
 
4174
  }
4175
4175
 
4176
 
    /*
 
4176
  /*
4177
4177
    Collect all keys which isn't in drop list. Add only those
4178
4178
    for which some fields exists.
4179
 
    */
 
4179
  */
4180
4180
 
4181
4181
  for (uint32_t i=0 ; i < table->s->keys ; i++,key_info++)
4182
 
    {
 
4182
  {
4183
4183
    char *key_name= key_info->name;
4184
4184
    Alter_drop *drop;
4185
4185
    drop_it.rewind();
4186
4186
    while ((drop=drop_it++))
4187
 
      {
 
4187
    {
4188
4188
      if (drop->type == Alter_drop::KEY &&
4189
4189
          !my_strcasecmp(system_charset_info,key_name, drop->name))
4190
4190
        break;
4191
 
      }
 
4191
    }
4192
4192
    if (drop)
4193
 
        {
 
4193
    {
4194
4194
      drop_it.remove();
4195
4195
      continue;
4196
4196
    }
4205
4205
      Create_field *cfield;
4206
4206
      field_it.rewind();
4207
4207
      while ((cfield=field_it++))
4208
 
    {
 
4208
      {
4209
4209
        if (cfield->change)
4210
 
    {
 
4210
        {
4211
4211
          if (!my_strcasecmp(system_charset_info, key_part_name,
4212
4212
                             cfield->change))
4213
4213
            break;