~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-04-13 16:22:40 UTC
  • mfrom: (971.1.78 mordred)
  • Revision ID: brian@gaz-20090413162240-ugi3gvhofmcuglzl
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <drizzled/unireg.h>
32
32
#include <drizzled/item/int.h>
33
33
#include <drizzled/item/empty_string.h>
34
 
#include <drizzled/replicator.h>
 
34
#include <drizzled/transaction_services.h>
 
35
 
35
36
 
36
37
using namespace std;
37
 
 
 
38
extern drizzled::TransactionServices transaction_services;
38
39
extern HASH lock_db_cache;
39
40
 
40
41
int creating_table= 0;        // How many mysql_create_table are running
298
299
void write_bin_log(Session *session, bool,
299
300
                   char const *query, size_t query_length)
300
301
{
301
 
  (void)replicator_statement(session, query, query_length);
 
302
  transaction_services.rawStatement(session, query, query_length);
302
303
}
303
304
 
304
305
 
3171
3172
  uint32_t flags= alter_info->flags;
3172
3173
 
3173
3174
  if (ALTER_ADD_COLUMN & flags)
3174
 
    *alter_flags|= HA_ADD_COLUMN;
 
3175
    alter_flags->set(HA_ADD_COLUMN);
3175
3176
  if (ALTER_DROP_COLUMN & flags)
3176
 
    *alter_flags|= HA_DROP_COLUMN;
 
3177
    alter_flags->set(HA_DROP_COLUMN);
3177
3178
  if (ALTER_RENAME & flags)
3178
 
    *alter_flags|= HA_RENAME_TABLE;
 
3179
    alter_flags->set(HA_RENAME_TABLE);
3179
3180
  if (ALTER_CHANGE_COLUMN & flags)
3180
 
    *alter_flags|= HA_CHANGE_COLUMN;
 
3181
    alter_flags->set(HA_CHANGE_COLUMN);
3181
3182
  if (ALTER_COLUMN_DEFAULT & flags)
3182
 
    *alter_flags|= HA_COLUMN_DEFAULT_VALUE;
 
3183
    alter_flags->set(HA_COLUMN_DEFAULT_VALUE);
3183
3184
  if (ALTER_COLUMN_STORAGE & flags)
3184
 
    *alter_flags|= HA_COLUMN_STORAGE;
 
3185
    alter_flags->set(HA_COLUMN_STORAGE);
3185
3186
  if (ALTER_COLUMN_FORMAT & flags)
3186
 
    *alter_flags|= HA_COLUMN_FORMAT;
 
3187
    alter_flags->set(HA_COLUMN_FORMAT);
3187
3188
  if (ALTER_COLUMN_ORDER & flags)
3188
 
    *alter_flags|= HA_ALTER_COLUMN_ORDER;
 
3189
    alter_flags->set(HA_ALTER_COLUMN_ORDER);
3189
3190
  if (ALTER_STORAGE & flags)
3190
 
    *alter_flags|= HA_ALTER_STORAGE;
 
3191
    alter_flags->set(HA_ALTER_STORAGE);
3191
3192
  if (ALTER_ROW_FORMAT & flags)
3192
 
    *alter_flags|= HA_ALTER_ROW_FORMAT;
 
3193
    alter_flags->set(HA_ALTER_ROW_FORMAT);
3193
3194
  if (ALTER_RECREATE & flags)
3194
 
    *alter_flags|= HA_RECREATE;
 
3195
    alter_flags->set(HA_RECREATE);
3195
3196
  if (ALTER_FOREIGN_KEY & flags)
3196
 
    *alter_flags|= HA_ALTER_FOREIGN_KEY;
 
3197
    alter_flags->set(HA_ALTER_FOREIGN_KEY);
3197
3198
}
3198
3199
 
3199
3200
 
3332
3333
      Check what has changed and set alter_flags
3333
3334
    */
3334
3335
    if (table->s->fields < alter_info->create_list.elements)
3335
 
      *alter_flags|= HA_ADD_COLUMN;
 
3336
      alter_flags->set(HA_ADD_COLUMN);
3336
3337
    else if (table->s->fields > alter_info->create_list.elements)
3337
 
      *alter_flags|= HA_DROP_COLUMN;
 
3338
      alter_flags->set(HA_DROP_COLUMN);
3338
3339
    if (create_info->db_type != table->s->db_type() ||
3339
3340
        create_info->used_fields & HA_CREATE_USED_ENGINE)
3340
 
      *alter_flags|= HA_ALTER_STORAGE_ENGINE;
 
3341
      alter_flags->set(HA_ALTER_STORAGE_ENGINE);
3341
3342
    if (create_info->used_fields & HA_CREATE_USED_CHARSET)
3342
 
      *alter_flags|= HA_CHANGE_CHARACTER_SET;
 
3343
      alter_flags->set(HA_CHANGE_CHARACTER_SET);
3343
3344
    if (create_info->used_fields & HA_CREATE_USED_DEFAULT_CHARSET)
3344
 
      *alter_flags|= HA_SET_DEFAULT_CHARACTER_SET;
 
3345
      alter_flags->set(HA_SET_DEFAULT_CHARACTER_SET);
3345
3346
    if (alter_info->flags & ALTER_RECREATE)
3346
 
      *alter_flags|= HA_RECREATE;
 
3347
      alter_flags->set(HA_RECREATE);
3347
3348
    /* TODO check for ADD/DROP FOREIGN KEY */
3348
3349
    if (alter_info->flags & ALTER_FOREIGN_KEY)
3349
 
      *alter_flags|=  HA_ALTER_FOREIGN_KEY;
 
3350
      alter_flags->set(HA_ALTER_FOREIGN_KEY);
3350
3351
  }
3351
3352
  /*
3352
3353
    Go through fields and check if the original ones are compatible
3371
3372
    {
3372
3373
      /* Evaluate changes bitmap and send to check_if_incompatible_data() */
3373
3374
      if (!(table_changes_local= field->is_equal(new_field)))
3374
 
        *alter_flags|= HA_ALTER_COLUMN_TYPE;
 
3375
        alter_flags->set(HA_ALTER_COLUMN_TYPE);
3375
3376
 
3376
3377
      /*
3377
3378
        Check if the altered column is a stored virtual field.
3379
3380
        the expression functions are not equal.
3380
3381
      */
3381
3382
      if (field->is_stored && field->vcol_info)
3382
 
        *alter_flags|= HA_ALTER_STORED_VCOL;
 
3383
        alter_flags->set(HA_ALTER_STORED_VCOL);
3383
3384
 
3384
3385
      /* Check if field was renamed */
3385
3386
      field->flags&= ~FIELD_IS_RENAMED;
3388
3389
                        new_field->field_name))
3389
3390
      {
3390
3391
        field->flags|= FIELD_IS_RENAMED;
3391
 
        *alter_flags|= HA_ALTER_COLUMN_NAME;
 
3392
        alter_flags->set(HA_ALTER_COLUMN_NAME);
3392
3393
      }
3393
3394
 
3394
3395
      *table_changes&= table_changes_local;
3395
3396
      if (table_changes_local == IS_EQUAL_PACK_LENGTH)
3396
 
        *alter_flags|= HA_ALTER_COLUMN_TYPE;
 
3397
        alter_flags->set(HA_ALTER_COLUMN_TYPE);
3397
3398
 
3398
3399
      /* Check that NULL behavior is same for old and new fields */
3399
3400
      if ((new_field->flags & NOT_NULL_FLAG) !=
3400
3401
          (uint32_t) (field->flags & NOT_NULL_FLAG))
3401
3402
      {
3402
3403
        *table_changes= IS_EQUAL_NO;
3403
 
        *alter_flags|= HA_ALTER_COLUMN_NULLABLE;
 
3404
        alter_flags->set(HA_ALTER_COLUMN_NULLABLE);
3404
3405
      }
3405
3406
    }
3406
3407
 
3447
3448
      {
3448
3449
        /* Unique key. Check for "PRIMARY". */
3449
3450
        if (is_primary_key(table_key))
3450
 
          *alter_flags|= HA_DROP_PK_INDEX;
 
3451
          alter_flags->set(HA_DROP_PK_INDEX);
3451
3452
        else
3452
 
          *alter_flags|= HA_DROP_UNIQUE_INDEX;
 
3453
          alter_flags->set(HA_DROP_UNIQUE_INDEX);
3453
3454
      }
3454
3455
      else
3455
 
        *alter_flags|= HA_DROP_INDEX;
 
3456
        alter_flags->set(HA_DROP_INDEX);
3456
3457
      *table_changes= IS_EQUAL_NO;
3457
3458
      continue;
3458
3459
    }
3467
3468
      {
3468
3469
        // Unique key. Check for "PRIMARY".
3469
3470
        if (is_primary_key(table_key))
3470
 
          *alter_flags|= HA_ALTER_PK_INDEX;
 
3471
          alter_flags->set(HA_ALTER_PK_INDEX);
3471
3472
        else
3472
 
          *alter_flags|= HA_ALTER_UNIQUE_INDEX;
 
3473
          alter_flags->set(HA_ALTER_UNIQUE_INDEX);
3473
3474
      }
3474
3475
      else
3475
 
        *alter_flags|= HA_ALTER_INDEX;
 
3476
        alter_flags->set(HA_ALTER_INDEX);
3476
3477
      goto index_changed;
3477
3478
    }
3478
3479
 
3496
3497
        {
3497
3498
          /* Unique key. Check for "PRIMARY" */
3498
3499
          if (is_primary_key(table_key))
3499
 
            *alter_flags|= HA_ALTER_PK_INDEX;
 
3500
            alter_flags->set(HA_ALTER_PK_INDEX);
3500
3501
          else
3501
 
            *alter_flags|= HA_ALTER_UNIQUE_INDEX;
 
3502
            alter_flags->set(HA_ALTER_UNIQUE_INDEX);
3502
3503
        }
3503
3504
        else
3504
 
          *alter_flags|= HA_ALTER_INDEX;
 
3505
          alter_flags->set(HA_ALTER_INDEX);
3505
3506
        goto index_changed;
3506
3507
      }
3507
3508
    }
3558
3559
      {
3559
3560
        /* Unique key. Check for "PRIMARY" */
3560
3561
        if (is_primary_key(new_key))
3561
 
          *alter_flags|= HA_ADD_PK_INDEX;
 
3562
          alter_flags->set(HA_ADD_PK_INDEX);
3562
3563
        else
3563
 
        *alter_flags|= HA_ADD_UNIQUE_INDEX;
 
3564
        alter_flags->set(HA_ADD_UNIQUE_INDEX);
3564
3565
      }
3565
3566
      else
3566
 
        *alter_flags|= HA_ADD_INDEX;
 
3567
        alter_flags->set(HA_ADD_INDEX);
3567
3568
      *table_changes= IS_EQUAL_NO;
3568
3569
    }
3569
3570
  }
4657
4658
      can do the change on-line
4658
4659
    */
4659
4660
    if (new_name == table_name && new_db == db &&
4660
 
        ha_alter_flags.is_set())
 
4661
        ha_alter_flags.any())
4661
4662
    {
4662
4663
      Alter_info tmp_alter_info(*alter_info, session->mem_root);
4663
4664