~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Brian Aker
  • Date: 2010-03-02 07:03:12 UTC
  • mfrom: (1309.2.10 drizzle-build)
  • Revision ID: brian@gaz-20100302070312-u8xyk09u2970pgzp
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
    !0  Error
126
126
*/
127
127
int StorageEngine::doDropTable(Session&,
128
 
                                       const string table_path)
 
128
                               const string &table_path)
129
129
{
130
130
  int error= 0;
131
131
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
360
360
  or any dropped tables that need to be removed from disk
361
361
*/
362
362
int StorageEngine::getTableDefinition(Session& session,
363
 
                                              TableIdentifier &identifier,
364
 
                                              message::Table *table_proto,
365
 
                                              bool include_temporary_tables)
 
363
                                      TableIdentifier &identifier,
 
364
                                      message::Table *table_proto,
 
365
                                      bool include_temporary_tables)
366
366
{
367
367
  return getTableDefinition(session,
368
368
                            identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
427
427
  return true;
428
428
}
429
429
 
 
430
class DropTable : 
 
431
  public unary_function<StorageEngine *, void>
 
432
{
 
433
  uint64_t &success_count;
 
434
  TableIdentifier &identifier;
 
435
  Session &session;
 
436
 
 
437
public:
 
438
 
 
439
  DropTable(Session &session_arg, TableIdentifier &arg, uint64_t &count_arg) :
 
440
    success_count(count_arg),
 
441
    identifier(arg),
 
442
    session(session_arg)
 
443
  {
 
444
  }
 
445
 
 
446
  result_type operator() (argument_type engine)
 
447
  {
 
448
    // @todo someday check that at least one engine said "true"
 
449
    std::string path(identifier.getPath());
 
450
    bool success= engine->doDropTable(session, path);
 
451
 
 
452
    if (success)
 
453
      success_count++;
 
454
  }
 
455
};
 
456
 
430
457
 
431
458
/**
432
459
   returns ENOENT if the file doesn't exists.
433
460
*/
434
461
int StorageEngine::dropTable(Session& session,
435
 
                             TableIdentifier &identifier,
436
 
                             bool generate_warning)
 
462
                             TableIdentifier &identifier)
437
463
{
438
464
  int error= 0;
439
465
  int error_proto;
455
481
 
456
482
  if (engine)
457
483
  {
 
484
    std::string path(identifier.getPath());
458
485
    engine->setTransactionReadWrite(session);
459
 
    error= engine->doDropTable(session, identifier.getPath());
460
 
  }
 
486
    error= engine->doDropTable(session, path);
461
487
 
462
 
  if (error != ENOENT)
463
 
  {
464
 
    if (error == 0)
 
488
    if (not error)
465
489
    {
466
 
      if (engine && engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
467
 
      {
468
 
        deleteDefinitionFromPath(identifier);
469
 
      }
470
 
      else
471
 
      {
472
 
        error= deleteDefinitionFromPath(identifier);
 
490
      if (not engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
491
      {
 
492
        uint64_t counter; // @todo We need to refactor to check that.
 
493
 
 
494
        for_each(vector_of_schema_engines.begin(), vector_of_schema_engines.end(),
 
495
                 DropTable(session, identifier, counter));
473
496
      }
474
497
    }
475
498
  }
477
500
  if (error_proto && error == 0)
478
501
    return 0;
479
502
 
480
 
  if (((error_proto != EEXIST && error_proto != ENOENT)
481
 
      && !engine && generate_warning)
482
 
      | ( error && !engine && generate_warning))
483
 
  {
484
 
    my_error(ER_GET_ERRNO, MYF(0), error_proto);
485
 
    return error_proto;
486
 
  }
487
 
 
488
 
  if (error && generate_warning)
489
 
  {
490
 
    /*
491
 
      Because engine->print_error() use my_error() to generate the error message
492
 
      we use an internal error Cursor to intercept it and store the text
493
 
      in a temporary buffer. Later the message will be presented to user
494
 
      as a warning.
495
 
    */
496
 
    Ha_delete_table_error_handler ha_delete_table_error_handler;
497
 
 
498
 
    session.push_internal_handler(&ha_delete_table_error_handler);
499
 
    engine->print_error(error, 0);
500
 
 
501
 
    session.pop_internal_handler();
502
 
 
503
 
    /*
504
 
      XXX: should we convert *all* errors to warnings here?
505
 
      What if the error is fatal?
506
 
    */
507
 
    push_warning(&session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
508
 
                 ha_delete_table_error_handler.buff);
509
 
  }
510
 
 
511
503
  return error;
512
504
}
513
505
 
879
871
 
880
872
      // On a return of zero we know we found and deleted the table. So we
881
873
      // remove it from our search.
882
 
      if (! error)
 
874
      if (not error)
883
875
        set_of_names.erase(iter);
884
876
    }
885
877
  }