~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2010-11-30 00:29:39 UTC
  • mto: (1965.2.2 build)
  • mto: This revision was merged to the branch mainline in revision 1966.
  • Revision ID: brian@tangent.org-20101130002939-8bzz3xpa0aapbq2w
Fix sleep() so that a kill command will kill it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
  }
135
135
 
136
136
  if (not validateCreateTableOption())
 
137
  {
137
138
    return true;
 
139
  }
138
140
 
139
141
  /* ALTER TABLE ends previous transaction */
140
142
  if (not session->endActiveTransaction())
 
143
  {
141
144
    return true;
 
145
  }
142
146
 
143
147
  if (not (need_start_waiting= not session->wait_if_global_read_lock(0, 1)))
 
148
  {
144
149
    return true;
 
150
  }
145
151
 
146
152
  bool res;
147
153
  if (original_table_message->type() == message::Table::STANDARD )
347
353
        if (def->sql_type == DRIZZLE_TYPE_BLOB)
348
354
        {
349
355
          my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
350
 
          return true;
 
356
                goto err;
351
357
        }
352
358
        if ((def->def= alter->def))
353
359
        {
355
361
          def->flags&= ~NO_DEFAULT_VALUE_FLAG;
356
362
        }
357
363
        else
358
 
        {
359
364
          def->flags|= NO_DEFAULT_VALUE_FLAG;
360
 
        }
361
365
        alter_it.remove();
362
366
      }
363
367
    }
368
372
    if (def->change && ! def->field)
369
373
    {
370
374
      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table->getMutableShare()->getTableName());
371
 
      return true;
 
375
      goto err;
372
376
    }
373
377
    /*
374
 
      If we have been given a field which has no default value, and is not null then we need to bail.
 
378
      Check that the DATE/DATETIME not null field we are going to add is
 
379
      either has a default value or the '0000-00-00' is allowed by the
 
380
      set sql mode.
 
381
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
 
382
      flag to allow ALTER Table only if the table to be altered is empty.
375
383
    */
376
 
    if (not (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) and not def->change)
 
384
    if ((def->sql_type == DRIZZLE_TYPE_DATE ||
 
385
         def->sql_type == DRIZZLE_TYPE_DATETIME) &&
 
386
        ! alter_info->datetime_field &&
 
387
        ! (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)))
377
388
    {
 
389
      alter_info->datetime_field= def;
378
390
      alter_info->error_if_not_empty= true;
379
391
    }
380
392
    if (! def->after)
381
 
    {
382
393
      new_create_list.push_back(def);
383
 
    }
384
394
    else if (def->after == first_keyword)
385
 
    {
386
395
      new_create_list.push_front(def);
387
 
    }
388
396
    else
389
397
    {
390
398
      CreateField *find;
397
405
      if (! find)
398
406
      {
399
407
        my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table->getMutableShare()->getTableName());
400
 
        return true;
 
408
        goto err;
401
409
      }
402
410
      find_it.after(def); /* Put element after this */
403
411
      /*
413
421
      if (alter_info->build_method == HA_BUILD_ONLINE)
414
422
      {
415
423
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->getQueryString()->c_str());
416
 
        return true;
 
424
        goto err;
417
425
      }
418
426
      alter_info->build_method= HA_BUILD_OFFLINE;
419
427
    }
424
432
             MYF(0),
425
433
             alter_info->alter_list.head()->name,
426
434
             table->getMutableShare()->getTableName());
427
 
    return true;
 
435
    goto err;
428
436
  }
429
437
  if (! new_create_list.elements)
430
438
  {
431
439
    my_message(ER_CANT_REMOVE_ALL_FIELDS,
432
440
               ER(ER_CANT_REMOVE_ALL_FIELDS),
433
441
               MYF(0));
434
 
    return true;
 
442
    goto err;
435
443
  }
436
444
 
437
445
  /*
568
576
      if (key->type == Key::FOREIGN_KEY)
569
577
      {
570
578
        if (((Foreign_key *)key)->validate(new_create_list))
571
 
        {
572
 
          return true;
573
 
        }
 
579
          goto err;
574
580
 
575
581
        Foreign_key *fkey= (Foreign_key*)key;
576
582
        add_foreign_key_to_table_message(&table_message,
591
597
        my_error(ER_WRONG_NAME_FOR_INDEX,
592
598
                 MYF(0),
593
599
                 key->name.str);
594
 
        return true;
 
600
        goto err;
595
601
      }
596
602
    }
597
603
  }
618
624
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
619
625
             MYF(0),
620
626
             alter_info->drop_list.head()->name);
621
 
    return true;
 
627
    goto err;
622
628
  }
623
629
  if (alter_info->alter_list.elements)
624
630
  {
625
631
    my_error(ER_CANT_DROP_FIELD_OR_KEY,
626
632
             MYF(0),
627
633
             alter_info->alter_list.head()->name);
628
 
    return true;
 
634
    goto err;
629
635
  }
630
636
 
631
637
  if (not table_message.options().has_comment()
644
650
  rc= false;
645
651
  alter_info->create_list.swap(new_create_list);
646
652
  alter_info->key_list.swap(new_key_list);
 
653
err:
647
654
 
648
655
  size_t num_engine_options= table_message.engine().options_size();
649
656
  size_t original_num_engine_options= original_proto.engine().options_size();
670
677
 
671
678
  drizzled::message::update(table_message);
672
679
 
673
 
  return false;
 
680
  return rc;
674
681
}
675
682
 
676
683
/* table_list should contain just one table */
893
900
  ha_rows copied= 0;
894
901
  ha_rows deleted= 0;
895
902
 
896
 
  if (not original_table_identifier.isValid())
897
 
    return true;
898
 
 
899
 
  if (not new_table_identifier.isValid())
900
 
    return true;
901
 
 
902
903
  session->set_proc_info("init");
903
904
 
904
905
  table->use_all_columns();
1149
1150
    */
1150
1151
    if (alter_info->error_if_not_empty && session->row_count)
1151
1152
    {
1152
 
      my_error(ER_INVALID_ALTER_TABLE_FOR_NOT_NULL, MYF(0));
 
1153
      const char *f_val= 0;
 
1154
      enum enum_drizzle_timestamp_type t_type= DRIZZLE_TIMESTAMP_DATE;
 
1155
 
 
1156
      switch (alter_info->datetime_field->sql_type)
 
1157
      {
 
1158
      case DRIZZLE_TYPE_DATE:
 
1159
        f_val= "0000-00-00";
 
1160
        t_type= DRIZZLE_TIMESTAMP_DATE;
 
1161
        break;
 
1162
      case DRIZZLE_TYPE_DATETIME:
 
1163
        f_val= "0000-00-00 00:00:00";
 
1164
        t_type= DRIZZLE_TIMESTAMP_DATETIME;
 
1165
        break;
 
1166
      default:
 
1167
        /* Shouldn't get here. */
 
1168
        assert(0);
 
1169
      }
 
1170
      bool save_abort_on_warning= session->abort_on_warning;
 
1171
      session->abort_on_warning= true;
 
1172
      make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
1173
                                   f_val, internal::strlength(f_val), t_type,
 
1174
                                   alter_info->datetime_field->field_name);
 
1175
      session->abort_on_warning= save_abort_on_warning;
1153
1176
    }
1154
1177
 
1155
1178
    if (original_table_identifier.isTmp())
1546
1569
        to->next_number_field->reset();
1547
1570
    }
1548
1571
 
1549
 
    for (CopyField *copy_ptr= copy; copy_ptr != copy_end ; copy_ptr++)
 
1572
    for (CopyField *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++)
1550
1573
    {
1551
 
      if (not copy->to_field->hasDefault() and copy->from_null_ptr and  *copy->from_null_ptr & copy->from_bit)
1552
 
      {
1553
 
        copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
1554
 
                                    ER_WARN_DATA_TRUNCATED, 1);
1555
 
        copy->to_field->reset();
1556
 
        error= 1;
1557
 
        break;
1558
 
      }
1559
 
 
1560
1574
      copy_ptr->do_copy(copy_ptr);
1561
1575
    }
1562
 
 
1563
 
    if (error)
1564
 
    {
1565
 
      break;
1566
 
    }
1567
 
 
1568
1576
    prev_insert_id= to->cursor->next_insert_id;
1569
1577
    error= to->cursor->insertRecord(to->record[0]);
1570
1578
    to->auto_increment_field_not_null= false;
1571
1579
 
1572
1580
    if (error)
1573
1581
    { 
1574
 
      if (!ignore || to->cursor->is_fatal_error(error, HA_CHECK_DUP))
 
1582
      if (!ignore ||
 
1583
          to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1575
1584
      { 
1576
1585
        to->print_error(error, MYF(0));
1577
1586
        break;