~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2008-10-13 10:14:09 UTC
  • mfrom: (383.7.6 drizzle-virtual-columns)
  • mto: This revision was merged to the branch mainline in revision 511.
  • Revision ID: monty@inaugust.com-20081013101409-aszm0nonww0f07zd
Merged in Virtual Column work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
839
839
                          (sql_field->decimals << FIELDFLAG_DEC_SHIFT));
840
840
    break;
841
841
  }
842
 
  if (!(sql_field->flags & NOT_NULL_FLAG))
 
842
  if (!(sql_field->flags & NOT_NULL_FLAG) ||
 
843
      (sql_field->vcol_info)) /* Make virtual columns always allow NULL values */
843
844
    sql_field->pack_flag|= FIELDFLAG_MAYBE_NULL;
844
845
  if (sql_field->flags & NO_DEFAULT_VALUE_FLAG)
845
846
    sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT;
1093
1094
            null_fields--;
1094
1095
          sql_field->flags=             dup_field->flags;
1095
1096
          sql_field->interval=          dup_field->interval;
 
1097
          sql_field->vcol_info=         dup_field->vcol_info;
 
1098
          sql_field->is_stored=      dup_field->is_stored;
1096
1099
          it2.remove();                 // Remove first (create) definition
1097
1100
          select_field_pos--;
1098
1101
          break;
1124
1127
    sql_field->offset= record_offset;
1125
1128
    if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1126
1129
      auto_increment++;
1127
 
    record_offset+= sql_field->pack_length;
 
1130
    /*
 
1131
          For now skip fields that are not physically stored in the database
 
1132
          (virtual fields) and update their offset later 
 
1133
          (see the next loop).
 
1134
        */
 
1135
    if (sql_field->is_stored)
 
1136
      record_offset+= sql_field->pack_length;
 
1137
  }
 
1138
  /* Update virtual fields' offset */
 
1139
  it.rewind();
 
1140
  while ((sql_field=it++))
 
1141
  {
 
1142
    if (not sql_field->is_stored)
 
1143
    {
 
1144
      sql_field->offset= record_offset;
 
1145
      record_offset+= sql_field->pack_length;
 
1146
    }
1128
1147
  }
1129
1148
  if (timestamps_with_niladic > 1)
1130
1149
  {
1171
1190
    if (key->type == Key::FOREIGN_KEY)
1172
1191
    {
1173
1192
      fk_key_count++;
 
1193
      if (((Foreign_key *)key)->validate(alter_info->create_list))
 
1194
        return true;
1174
1195
      Foreign_key *fk_key= (Foreign_key*) key;
1175
1196
      if (fk_key->ref_columns.elements &&
1176
1197
          fk_key->ref_columns.elements != fk_key->columns.elements)
1360
1381
            return(true);
1361
1382
          }
1362
1383
        }
 
1384
        if (not sql_field->is_stored)
 
1385
        {
 
1386
          /* Key fields must always be physically stored. */
 
1387
          my_error(ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN, MYF(0));
 
1388
          return(true);
 
1389
        }
 
1390
        if (key->type == Key::PRIMARY && sql_field->vcol_info)
 
1391
        {
 
1392
          my_error(ER_PRIMARY_KEY_BASED_ON_VIRTUAL_COLUMN, MYF(0));
 
1393
          return(true);
 
1394
        }
1363
1395
        if (!(sql_field->flags & NOT_NULL_FLAG))
1364
1396
        {
1365
1397
          if (key->type == Key::PRIMARY)
3409
3441
      if (!(table_changes_local= field->is_equal(new_field)))
3410
3442
        *alter_flags|= HA_ALTER_COLUMN_TYPE;
3411
3443
 
 
3444
      /*
 
3445
        Check if the altered column is a stored virtual field.
 
3446
        TODO: Mark such a column with an alter flag only if
 
3447
        the expression functions are not equal. 
 
3448
      */
 
3449
      if (field->is_stored && field->vcol_info)
 
3450
        *alter_flags|= HA_ALTER_STORED_VCOL;
 
3451
 
3412
3452
      /* Check if field was renamed */
3413
3453
      field->flags&= ~FIELD_IS_RENAMED;
3414
3454
      if (my_strcasecmp(system_charset_info,
4046
4086
    if (def)
4047
4087
    {                                           // Field is changed
4048
4088
      def->field=field;
 
4089
      if (field->is_stored != def->is_stored)
 
4090
      {
 
4091
        my_error(ER_UNSUPPORTED_ACTION_ON_VIRTUAL_COLUMN,
 
4092
                 MYF(0),
 
4093
                 "Changing the STORED status");
 
4094
        goto err;
 
4095
      }
4049
4096
      if (!def->after)
4050
4097
        {
4051
4098
        new_create_list.push_back(def);
4263
4310
    Key *key;
4264
4311
    while ((key=key_it++))                      // Add new keys
4265
4312
    {
 
4313
      if (key->type == Key::FOREIGN_KEY &&
 
4314
          ((Foreign_key *)key)->validate(new_create_list))
 
4315
        goto err;
4266
4316
      if (key->type != Key::FOREIGN_KEY)
4267
4317
        new_key_list.push_back(key);
4268
4318
      if (key->name.str &&
5215
5265
      copy_ptr->do_copy(copy_ptr);
5216
5266
    }
5217
5267
    prev_insert_id= to->file->next_insert_id;
 
5268
    update_virtual_fields_marked_for_write(to, false);
5218
5269
    error=to->file->ha_write_row(to->record[0]);
5219
5270
    to->auto_increment_field_not_null= false;
5220
5271
    if (error)