~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
 
22
22
#include <fcntl.h>
23
23
#include <unistd.h>
32
32
#include <google/protobuf/io/zero_copy_stream.h>
33
33
#include <google/protobuf/io/zero_copy_stream_impl.h>
34
34
 
35
 
#include "drizzled/cached_directory.h"
36
 
 
 
35
#include <drizzled/cached_directory.h>
37
36
#include <drizzled/definitions.h>
38
37
#include <drizzled/base.h>
39
38
#include <drizzled/cursor.h>
43
42
#include <drizzled/gettext.h>
44
43
#include <drizzled/unireg.h>
45
44
#include <drizzled/data_home.h>
46
 
#include "drizzled/errmsg_print.h"
47
 
#include "drizzled/xid.h"
48
 
#include "drizzled/sql_table.h"
49
 
#include "drizzled/global_charset_info.h"
50
 
#include "drizzled/charset.h"
51
 
#include "drizzled/internal/my_sys.h"
52
 
#include "drizzled/db.h"
53
 
 
 
45
#include <drizzled/errmsg_print.h>
 
46
#include <drizzled/xid.h>
 
47
#include <drizzled/sql_table.h>
 
48
#include <drizzled/global_charset_info.h>
 
49
#include <drizzled/charset.h>
 
50
#include <drizzled/internal/my_sys.h>
54
51
#include <drizzled/table_proto.h>
55
52
#include <drizzled/plugin/event_observer.h>
56
 
 
 
53
#include <drizzled/internal_error_handler.h>
57
54
#include <drizzled/table/shell.h>
58
 
 
59
 
#include "drizzled/message/cache.h"
 
55
#include <drizzled/message/cache.h>
 
56
#include <drizzled/key.h>
60
57
 
61
58
#include <boost/algorithm/string/compare.hpp>
62
59
 
101
98
}
102
99
 
103
100
 
104
 
int StorageEngine::renameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
 
101
int StorageEngine::renameTable(Session &session, const identifier::Table &from, const identifier::Table &to)
105
102
{
106
103
  int error;
107
104
  setTransactionReadWrite(session);
137
134
  @retval
138
135
    !0  Error
139
136
*/
140
 
int StorageEngine::doDropTable(Session&, const TableIdentifier &identifier)
 
137
int StorageEngine::doDropTable(Session&, const identifier::Table &identifier)
141
138
                               
142
139
{
143
140
  int error= 0;
287
284
class StorageEngineGetTableDefinition: public std::unary_function<StorageEngine *,bool>
288
285
{
289
286
  Session& session;
290
 
  const TableIdentifier &identifier;
 
287
  const identifier::Table &identifier;
291
288
  message::Table &table_message;
292
 
  int &err;
 
289
  drizzled::error_t &err;
293
290
 
294
291
public:
295
292
  StorageEngineGetTableDefinition(Session& session_arg,
296
 
                                  const TableIdentifier &identifier_arg,
 
293
                                  const identifier::Table &identifier_arg,
297
294
                                  message::Table &table_message_arg,
298
 
                                  int &err_arg) :
 
295
                                  drizzled::error_t &err_arg) :
299
296
    session(session_arg), 
300
297
    identifier(identifier_arg),
301
298
    table_message(table_message_arg), 
306
303
    int ret= engine->doGetTableDefinition(session, identifier, table_message);
307
304
 
308
305
    if (ret != ENOENT)
309
 
      err= ret;
 
306
      err= static_cast<drizzled::error_t>(ret);
310
307
 
311
 
    return err == EEXIST || err != ENOENT;
 
308
    return err == static_cast<drizzled::error_t>(EEXIST) or err != static_cast<drizzled::error_t>(ENOENT);
312
309
  }
313
310
};
314
311
 
315
312
class StorageEngineDoesTableExist: public std::unary_function<StorageEngine *, bool>
316
313
{
317
314
  Session& session;
318
 
  const TableIdentifier &identifier;
 
315
  const identifier::Table &identifier;
319
316
 
320
317
public:
321
 
  StorageEngineDoesTableExist(Session& session_arg, const TableIdentifier &identifier_arg) :
 
318
  StorageEngineDoesTableExist(Session& session_arg, const identifier::Table &identifier_arg) :
322
319
    session(session_arg), 
323
320
    identifier(identifier_arg) 
324
321
  { }
333
330
  Utility method which hides some of the details of getTableDefinition()
334
331
*/
335
332
bool plugin::StorageEngine::doesTableExist(Session &session,
336
 
                                           const TableIdentifier &identifier,
 
333
                                           const identifier::Table &identifier,
337
334
                                           bool include_temporary_tables)
338
335
{
339
336
  if (include_temporary_tables)
354
351
  return true;
355
352
}
356
353
 
357
 
bool plugin::StorageEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier&)
 
354
bool plugin::StorageEngine::doDoesTableExist(Session&, const drizzled::identifier::Table&)
358
355
{
359
356
  std::cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
360
357
  assert(0);
361
358
  return false;
362
359
}
363
360
 
364
 
/**
365
 
  Call this function in order to give the Cursor the possiblity
366
 
  to ask engine if there are any new tables that should be written to disk
367
 
  or any dropped tables that need to be removed from disk
368
 
*/
369
 
int StorageEngine::getTableDefinition(Session& session,
370
 
                                      const TableIdentifier &identifier,
371
 
                                      message::table::shared_ptr &table_message,
372
 
                                      bool include_temporary_tables)
 
361
message::table::shared_ptr StorageEngine::getTableMessage(Session& session,
 
362
                                                          identifier::Table::const_reference identifier,
 
363
                                                          bool include_temporary_tables)
373
364
{
374
 
  int err= ENOENT;
 
365
  drizzled::error_t error;
 
366
  error= static_cast<drizzled::error_t>(ENOENT);
375
367
 
376
368
  if (include_temporary_tables)
377
369
  {
378
370
    Table *table= session.find_temporary_table(identifier);
379
371
    if (table)
380
372
    {
381
 
      table_message.reset(new message::Table(*table->getShare()->getTableProto()));
382
 
      return EEXIST;
 
373
      return message::table::shared_ptr(new message::Table(*table->getShare()->getTableMessage()));
383
374
    }
384
375
  }
385
376
 
386
377
  drizzled::message::table::shared_ptr table_ptr;
387
378
  if ((table_ptr= drizzled::message::Cache::singleton().find(identifier)))
388
379
  {
389
 
    table_message= table_ptr;
 
380
    (void)table_ptr;
390
381
  }
391
382
 
392
383
  message::Table message;
393
384
  EngineVector::iterator iter=
394
385
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
395
 
                 StorageEngineGetTableDefinition(session, identifier, message, err));
 
386
                 StorageEngineGetTableDefinition(session, identifier, message, error));
396
387
 
397
388
  if (iter == vector_of_engines.end())
398
389
  {
399
 
    return ENOENT;
 
390
    return message::table::shared_ptr();
400
391
  }
401
 
  table_message.reset(new message::Table(message));
402
 
 
403
 
 drizzled::message::Cache::singleton().insert(identifier, table_message);
404
 
 
405
 
  return err;
 
392
  message::table::shared_ptr table_message(new message::Table(message));
 
393
 
 
394
  drizzled::message::Cache::singleton().insert(identifier, table_message);
 
395
 
 
396
  return table_message;
406
397
}
407
398
 
408
399
/**
415
406
{
416
407
public:
417
408
  Ha_delete_table_error_handler() : Internal_error_handler() {}
418
 
  virtual bool handle_error(uint32_t sql_errno,
 
409
  virtual bool handle_error(drizzled::error_t sql_errno,
419
410
                            const char *message,
420
411
                            DRIZZLE_ERROR::enum_warning_level level,
421
412
                            Session *session);
425
416
 
426
417
bool
427
418
Ha_delete_table_error_handler::
428
 
handle_error(uint32_t ,
 
419
handle_error(drizzled::error_t ,
429
420
             const char *message,
430
421
             DRIZZLE_ERROR::enum_warning_level ,
431
422
             Session *)
435
426
  return true;
436
427
}
437
428
 
438
 
/**
439
 
   returns ENOENT if the file doesn't exists.
440
 
*/
441
 
int StorageEngine::dropTable(Session& session,
442
 
                             const TableIdentifier &identifier)
443
 
{
444
 
  int error= 0;
445
 
  int error_proto;
446
 
  message::table::shared_ptr src_proto;
447
 
  StorageEngine *engine;
448
 
 
449
 
  error_proto= StorageEngine::getTableDefinition(session, identifier, src_proto);
450
 
 
451
 
  if (error_proto == ER_CORRUPT_TABLE_DEFINITION)
452
 
  {
453
 
    std::string error_message;
454
 
    identifier.getSQLPath(error_message);
455
 
 
456
 
    error_message.append(" : ");
457
 
    error_message.append(src_proto->InitializationErrorString());
458
 
 
459
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
460
 
 
461
 
    return ER_CORRUPT_TABLE_DEFINITION;
462
 
  }
463
 
 
464
 
  if (src_proto)
465
 
    engine= StorageEngine::findByName(session, src_proto->engine().name());
466
 
  else
467
 
    engine= StorageEngine::findByName(session, "");
468
 
 
469
 
  if (not engine)
470
 
  {
471
 
    std::string error_message;
472
 
    identifier.getSQLPath(error_message);
473
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
474
 
 
475
 
    return ER_CORRUPT_TABLE_DEFINITION;
476
 
  }
477
 
 
478
 
  error= StorageEngine::dropTable(session, *engine, identifier);
479
 
 
480
 
  if (error_proto && error == 0)
481
 
    return 0;
482
 
 
483
 
  return error;
484
 
}
485
 
 
486
 
int StorageEngine::dropTable(Session& session,
487
 
                             StorageEngine &engine,
488
 
                             const TableIdentifier &identifier)
489
 
{
490
 
  int error;
491
 
 
 
429
class DropTableByIdentifier: public std::unary_function<EngineVector::value_type, bool>
 
430
{
 
431
  Session::reference session;
 
432
  identifier::Table::const_reference identifier;
 
433
  drizzled::error_t &error;
 
434
 
 
435
public:
 
436
 
 
437
  DropTableByIdentifier(Session::reference session_arg,
 
438
                        identifier::Table::const_reference identifier_arg,
 
439
                        drizzled::error_t &error_arg) :
 
440
    session(session_arg),
 
441
    identifier(identifier_arg),
 
442
    error(error_arg)
 
443
  { }
 
444
 
 
445
  result_type operator() (argument_type engine)
 
446
  {
 
447
    if (not engine->doDoesTableExist(session, identifier))
 
448
      return false;
 
449
 
 
450
    int local_error= engine->doDropTable(session, identifier);
 
451
 
 
452
 
 
453
    if (not local_error)
 
454
      return true;
 
455
 
 
456
    switch (local_error)
 
457
    {
 
458
    case HA_ERR_NO_SUCH_TABLE:
 
459
    case ENOENT:
 
460
      error= static_cast<drizzled::error_t>(HA_ERR_NO_SUCH_TABLE);
 
461
      return false;
 
462
 
 
463
    default:
 
464
      error= static_cast<drizzled::error_t>(local_error);
 
465
      return true;
 
466
    }
 
467
  } 
 
468
};
 
469
 
 
470
 
 
471
bool StorageEngine::dropTable(Session::reference session,
 
472
                              identifier::Table::const_reference identifier,
 
473
                              drizzled::error_t &error)
 
474
{
 
475
  error= EE_OK;
 
476
 
 
477
  EngineVector::const_iterator iter= std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
478
                                                  DropTableByIdentifier(session, identifier, error));
 
479
 
 
480
  if (error)
 
481
  {
 
482
    return false;
 
483
  }
 
484
  else if (iter == vector_of_engines.end())
 
485
  {
 
486
    error= ER_BAD_TABLE_ERROR;
 
487
    return false;
 
488
  }
 
489
 
 
490
  drizzled::message::Cache::singleton().erase(identifier);
 
491
 
 
492
  return true;
 
493
}
 
494
 
 
495
bool StorageEngine::dropTable(Session& session,
 
496
                              const identifier::Table &identifier)
 
497
{
 
498
  drizzled::error_t error;
 
499
 
 
500
  if (not dropTable(session, identifier, error))
 
501
  {
 
502
    return false;
 
503
  }
 
504
 
 
505
  return true;
 
506
}
 
507
 
 
508
bool StorageEngine::dropTable(Session::reference session,
 
509
                              StorageEngine &engine,
 
510
                              identifier::Table::const_reference identifier,
 
511
                              drizzled::error_t &error)
 
512
{
 
513
  error= EE_OK;
492
514
  engine.setTransactionReadWrite(session);
 
515
 
 
516
  assert(identifier.isTmp());
493
517
  
494
518
  if (unlikely(plugin::EventObserver::beforeDropTable(session, identifier)))
495
519
  {
497
521
  }
498
522
  else
499
523
  {
500
 
    error= engine.doDropTable(session, identifier);
 
524
    error= static_cast<drizzled::error_t>(engine.doDropTable(session, identifier));
 
525
 
501
526
    if (unlikely(plugin::EventObserver::afterDropTable(session, identifier, error)))
502
527
    {
503
528
      error= ER_EVENT_OBSERVER_PLUGIN;
506
531
 
507
532
  drizzled::message::Cache::singleton().erase(identifier);
508
533
 
509
 
  return error;
 
534
  if (error)
 
535
  {
 
536
    return false;
 
537
  }
 
538
 
 
539
  return true;
510
540
}
511
541
 
512
542
 
518
548
  @retval
519
549
   1  error
520
550
*/
521
 
int StorageEngine::createTable(Session &session,
522
 
                               const TableIdentifier &identifier,
523
 
                               message::Table& table_message)
 
551
bool StorageEngine::createTable(Session &session,
 
552
                                const identifier::Table &identifier,
 
553
                                message::Table& table_message)
524
554
{
525
 
  int error= 1;
 
555
  drizzled::error_t error= EE_OK;
 
556
 
526
557
  TableShare share(identifier);
527
558
  table::Shell table(share);
528
559
  message::Table tmp_proto;
530
561
  if (share.parse_table_proto(session, table_message) || share.open_table_from_share(&session, identifier, "", 0, 0, table))
531
562
  { 
532
563
    // @note Error occured, we should probably do a little more here.
 
564
    // ER_CORRUPT_TABLE_DEFINITION,ER_CORRUPT_TABLE_DEFINITION_ENUM 
 
565
    
 
566
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
 
567
 
 
568
    return false;
533
569
  }
534
570
  else
535
571
  {
548
584
    {
549
585
      share.storage_engine->setTransactionReadWrite(session);
550
586
 
551
 
      error= share.storage_engine->doCreateTable(session,
552
 
                                                 table,
553
 
                                                 identifier,
554
 
                                                 table_message);
 
587
      error= static_cast<drizzled::error_t>(share.storage_engine->doCreateTable(session,
 
588
                                                                                table,
 
589
                                                                                identifier,
 
590
                                                                                table_message));
555
591
    }
556
592
 
557
 
    if (error)
 
593
    if (error == ER_TABLE_PERMISSION_DENIED)
 
594
    {
 
595
      my_error(ER_TABLE_PERMISSION_DENIED, identifier);
 
596
    }
 
597
    else if (error)
558
598
    {
559
599
      std::string path;
560
600
      identifier.getSQLPath(path);
564
604
    table.delete_table();
565
605
  }
566
606
 
567
 
  return(error != 0);
 
607
  return(error == EE_OK);
568
608
}
569
609
 
570
610
Cursor *StorageEngine::getCursor(Table &arg)
576
616
  public std::unary_function<StorageEngine *, void>
577
617
{
578
618
  CachedDirectory &directory;
579
 
  const SchemaIdentifier &identifier;
580
 
  TableIdentifier::vector &set_of_identifiers;
 
619
  const identifier::Schema &identifier;
 
620
  identifier::Table::vector &set_of_identifiers;
581
621
 
582
622
public:
583
623
 
584
 
  AddTableIdentifier(CachedDirectory &directory_arg, const SchemaIdentifier &identifier_arg, TableIdentifier::vector &of_names) :
 
624
  AddTableIdentifier(CachedDirectory &directory_arg, const identifier::Schema &identifier_arg, identifier::Table::vector &of_names) :
585
625
    directory(directory_arg),
586
626
    identifier(identifier_arg),
587
627
    set_of_identifiers(of_names)
595
635
};
596
636
 
597
637
 
598
 
void StorageEngine::getIdentifiers(Session &session, const SchemaIdentifier &schema_identifier, TableIdentifier::vector &set_of_identifiers)
 
638
void StorageEngine::getIdentifiers(Session &session, const identifier::Schema &schema_identifier, identifier::Table::vector &set_of_identifiers)
599
639
{
600
 
  static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("information_schema");
601
 
  static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("data_dictionary");
602
 
 
603
640
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
604
641
 
605
642
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
632
669
  session.doGetTableIdentifiers(directory, schema_identifier, set_of_identifiers);
633
670
}
634
671
 
635
 
class DropTable: public std::unary_function<TableIdentifier&, bool>
 
672
class DropTable: public std::unary_function<identifier::Table&, bool>
636
673
{
637
674
  Session &session;
638
675
  StorageEngine *engine;
650
687
  } 
651
688
};
652
689
 
653
 
/* This will later be converted to TableIdentifiers */
 
690
/* This will later be converted to identifier::Tables */
654
691
class DropTables: public std::unary_function<StorageEngine *, void>
655
692
{
656
693
  Session &session;
657
 
  TableIdentifier::vector &table_identifiers;
 
694
  identifier::Table::vector &table_identifiers;
658
695
 
659
696
public:
660
697
 
661
 
  DropTables(Session &session_arg, TableIdentifier::vector &table_identifiers_arg) :
 
698
  DropTables(Session &session_arg, identifier::Table::vector &table_identifiers_arg) :
662
699
    session(session_arg),
663
700
    table_identifiers(table_identifiers_arg)
664
701
  { }
682
719
void StorageEngine::removeLostTemporaryTables(Session &session, const char *directory)
683
720
{
684
721
  CachedDirectory dir(directory, set_of_table_definition_ext);
685
 
  TableIdentifier::vector table_identifiers;
 
722
  identifier::Table::vector table_identifiers;
686
723
 
687
724
  if (dir.fail())
688
725
  {
711
748
    message::Table definition;
712
749
    if (StorageEngine::readTableFile(path, definition))
713
750
    {
714
 
      TableIdentifier identifier(definition.schema(), definition.name(), path);
 
751
      identifier::Table identifier(definition.schema(), definition.name(), path);
715
752
      table_identifiers.push_back(identifier);
716
753
    }
717
754
  }
761
798
    - table->getShare()->path
762
799
    - table->alias
763
800
*/
764
 
void StorageEngine::print_error(int error, myf errflag, Table &table)
765
 
{
766
 
  print_error(error, errflag, &table);
767
 
}
768
 
 
769
 
void StorageEngine::print_error(int error, myf errflag, Table *table)
770
 
{
771
 
  int textno= ER_GET_ERRNO;
 
801
void StorageEngine::print_error(int error, myf errflag, const Table &table) const
 
802
{
 
803
  drizzled::error_t textno= ER_GET_ERRNO;
772
804
  switch (error) {
773
805
  case EACCES:
774
806
    textno=ER_OPEN_AS_READONLY;
789
821
    break;
790
822
  case HA_ERR_FOUND_DUPP_KEY:
791
823
  {
792
 
    assert(table);
793
 
    uint32_t key_nr= table->get_dup_key(error);
 
824
    uint32_t key_nr= table.get_dup_key(error);
794
825
    if ((int) key_nr >= 0)
795
826
    {
796
827
      const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
797
828
 
798
 
      print_keydup_error(key_nr, err_msg, *table);
 
829
      print_keydup_error(key_nr, err_msg, table);
799
830
 
800
831
      return;
801
832
    }
804
835
  }
805
836
  case HA_ERR_FOREIGN_DUPLICATE_KEY:
806
837
  {
807
 
    assert(table);
808
 
    uint32_t key_nr= table->get_dup_key(error);
 
838
    uint32_t key_nr= table.get_dup_key(error);
809
839
    if ((int) key_nr >= 0)
810
840
    {
811
841
      uint32_t max_length;
815
845
      String str(key,sizeof(key),system_charset_info);
816
846
 
817
847
      /* Table is opened and defined at this point */
818
 
      key_unpack(&str,table,(uint32_t) key_nr);
 
848
      key_unpack(&str, &table,(uint32_t) key_nr);
819
849
      max_length= (DRIZZLE_ERRMSG_SIZE-
820
850
                   (uint32_t) strlen(ER(ER_FOREIGN_DUPLICATE_KEY)));
821
851
      if (str.length() >= max_length)
823
853
        str.length(max_length-4);
824
854
        str.append(STRING_WITH_LEN("..."));
825
855
      }
826
 
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table->getShare()->getTableName(),
 
856
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table.getShare()->getTableName(),
827
857
        str.c_ptr(), key_nr+1);
828
858
      return;
829
859
    }
846
876
    textno=ER_CRASHED_ON_USAGE;
847
877
    break;
848
878
  case HA_ERR_NOT_A_TABLE:
849
 
    textno= error;
 
879
    textno= static_cast<drizzled::error_t>(error);
850
880
    break;
851
881
  case HA_ERR_CRASHED_ON_REPAIR:
852
882
    textno=ER_CRASHED_ON_REPAIR;
900
930
    textno=ER_TABLE_DEF_CHANGED;
901
931
    break;
902
932
  case HA_ERR_NO_SUCH_TABLE:
903
 
    assert(table);
904
 
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->getShare()->getSchemaName(),
905
 
             table->getShare()->getTableName());
906
 
    return;
 
933
    {
 
934
      identifier::Table identifier(table.getShare()->getSchemaName(), table.getShare()->getTableName());
 
935
      my_error(ER_TABLE_UNKNOWN, identifier);
 
936
      return;
 
937
    }
907
938
  case HA_ERR_RBR_LOGGING_FAILED:
908
939
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
909
940
    break;
910
941
  case HA_ERR_DROP_INDEX_FK:
911
942
  {
912
 
    assert(table);
913
943
    const char *ptr= "???";
914
 
    uint32_t key_nr= table->get_dup_key(error);
 
944
    uint32_t key_nr= table.get_dup_key(error);
915
945
    if ((int) key_nr >= 0)
916
 
      ptr= table->key_info[key_nr].name;
 
946
      ptr= table.key_info[key_nr].name;
917
947
    my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
918
948
    return;
919
949
  }
958
988
      return;
959
989
    }
960
990
  }
961
 
  my_error(textno, errflag, table->getShare()->getTableName(), error);
 
991
 
 
992
  my_error(textno, errflag, table.getShare()->getTableName(), error);
962
993
}
963
994
 
964
995
 
971
1002
  @return
972
1003
    Returns true if this is a temporary error
973
1004
*/
974
 
bool StorageEngine::get_error_message(int , String* )
 
1005
bool StorageEngine::get_error_message(int , String* ) const
975
1006
{
976
1007
  return false;
977
1008
}
978
1009
 
979
1010
 
980
 
void StorageEngine::print_keydup_error(uint32_t key_nr, const char *msg, Table &table)
 
1011
void StorageEngine::print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const
981
1012
{
982
1013
  /* Write the duplicated key in the error message */
983
1014
  char key[MAX_KEY_LENGTH];
1005
1036
}
1006
1037
 
1007
1038
 
1008
 
int StorageEngine::deleteDefinitionFromPath(const TableIdentifier &identifier)
 
1039
int StorageEngine::deleteDefinitionFromPath(const identifier::Table &identifier)
1009
1040
{
1010
1041
  std::string path(identifier.getPath());
1011
1042
 
1014
1045
  return internal::my_delete(path.c_str(), MYF(0));
1015
1046
}
1016
1047
 
1017
 
int StorageEngine::renameDefinitionFromPath(const TableIdentifier &dest, const TableIdentifier &src)
 
1048
int StorageEngine::renameDefinitionFromPath(const identifier::Table &dest, const identifier::Table &src)
1018
1049
{
1019
1050
  message::Table table_message;
1020
1051
  std::string src_path(src.getPath());
1043
1074
  return error;
1044
1075
}
1045
1076
 
1046
 
int StorageEngine::writeDefinitionFromPath(const TableIdentifier &identifier, message::Table &table_message)
 
1077
int StorageEngine::writeDefinitionFromPath(const identifier::Table &identifier, const message::Table &table_message)
1047
1078
{
1048
1079
  char definition_file_tmp[FN_REFLEN];
1049
1080
  std::string file_name(identifier.getPath());
1076
1107
 
1077
1108
  if (not success)
1078
1109
  {
 
1110
    std::string error_message;
 
1111
    identifier.getSQLPath(error_message);
 
1112
 
1079
1113
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
 
1114
             error_message.c_str(),
1080
1115
             table_message.InitializationErrorString().c_str());
1081
1116
    delete output;
1082
1117
 
1118
1153
 
1119
1154
class CanCreateTable: public std::unary_function<StorageEngine *, bool>
1120
1155
{
1121
 
  const TableIdentifier &identifier;
 
1156
  const identifier::Table &identifier;
1122
1157
 
1123
1158
public:
1124
 
  CanCreateTable(const TableIdentifier &identifier_arg) :
 
1159
  CanCreateTable(const identifier::Table &identifier_arg) :
1125
1160
    identifier(identifier_arg)
1126
1161
  { }
1127
1162
 
1135
1170
/**
1136
1171
  @note on success table can be created.
1137
1172
*/
1138
 
bool StorageEngine::canCreateTable(const TableIdentifier &identifier)
 
1173
bool StorageEngine::canCreateTable(const identifier::Table &identifier)
1139
1174
{
1140
1175
  EngineVector::iterator iter=
1141
1176
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
1164
1199
    catch (...)
1165
1200
    {
1166
1201
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
 
1202
               table_message.name().empty() ? path.c_str() : table_message.name().c_str(),
1167
1203
               table_message.InitializationErrorString().empty() ? "": table_message.InitializationErrorString().c_str());
1168
1204
    }
1169
1205
  }
1175
1211
  return false;
1176
1212
}
1177
1213
 
 
1214
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine)
 
1215
{
 
1216
  output << "StorageEngine:(";
 
1217
  output <<  engine.getName();
 
1218
  output << ")";
1178
1219
 
 
1220
  return output;
 
1221
}
1179
1222
 
1180
1223
} /* namespace plugin */
1181
1224
} /* namespace drizzled */