~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Paul McCullagh
  • Date: 2010-05-26 10:17:56 UTC
  • mto: (1567.1.3 new-staging)
  • mto: This revision was merged to the branch mainline in revision 1568.
  • Revision ID: paul.mccullagh@primebase.org-20100526101756-3qdwb9id3qhog0z1
Adjust for namespace changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/my_hash.h"
35
36
#include "drizzled/cached_directory.h"
36
37
 
37
38
#include <drizzled/definitions.h>
54
55
#include <drizzled/table_proto.h>
55
56
#include <drizzled/plugin/event_observer.h>
56
57
 
57
 
#include <drizzled/table/shell.h>
58
 
 
59
 
#include "drizzled/message/cache.h"
60
 
 
61
 
#include <boost/algorithm/string/compare.hpp>
62
 
 
63
58
static bool shutdown_has_begun= false; // Once we put in the container for the vector/etc for engines this will go away.
64
59
 
 
60
using namespace std;
 
61
 
65
62
namespace drizzled
66
63
{
67
64
 
71
68
static EngineVector vector_of_engines;
72
69
static EngineVector vector_of_schema_engines;
73
70
 
74
 
const std::string DEFAULT_STRING("default");
75
71
const std::string UNKNOWN_STRING("UNKNOWN");
76
72
const std::string DEFAULT_DEFINITION_FILE_EXT(".dfe");
77
73
 
82
78
  return vector_of_schema_engines;
83
79
}
84
80
 
85
 
StorageEngine::StorageEngine(const std::string name_arg,
86
 
                             const std::bitset<HTON_BIT_SIZE> &flags_arg) :
 
81
StorageEngine::StorageEngine(const string name_arg,
 
82
                             const bitset<HTON_BIT_SIZE> &flags_arg) :
87
83
  Plugin(name_arg, "StorageEngine"),
88
84
  MonitoredInTransaction(), /* This gives the storage engine a "slot" or ID */
89
85
  flags(flags_arg)
101
97
}
102
98
 
103
99
 
104
 
int StorageEngine::renameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
 
100
int StorageEngine::renameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
105
101
{
106
102
  int error;
107
103
  setTransactionReadWrite(session);
137
133
  @retval
138
134
    !0  Error
139
135
*/
140
 
int StorageEngine::doDropTable(Session&, const TableIdentifier &identifier)
 
136
int StorageEngine::doDropTable(Session&, TableIdentifier &identifier)
141
137
                               
142
138
{
143
139
  int error= 0;
192
188
}
193
189
 
194
190
class FindEngineByName
195
 
  : public std::unary_function<StorageEngine *, bool>
 
191
  : public unary_function<StorageEngine *, bool>
196
192
{
197
 
  const std::string &predicate;
 
193
  const string &target;
198
194
 
199
195
public:
200
 
  explicit FindEngineByName(const std::string &target_arg) :
201
 
    predicate(target_arg)
 
196
  explicit FindEngineByName(const string &target_arg) :
 
197
    target(target_arg)
202
198
  {
203
199
  }
204
 
 
205
200
  result_type operator() (argument_type engine)
206
201
  {
207
 
    return boost::iequals(engine->getName(), predicate);
 
202
    string engine_name(engine->getName());
 
203
 
 
204
    transform(engine_name.begin(), engine_name.end(),
 
205
              engine_name.begin(), ::tolower);
 
206
    return engine_name == target;
208
207
  }
209
208
};
210
209
 
211
 
StorageEngine *StorageEngine::findByName(const std::string &predicate)
 
210
StorageEngine *StorageEngine::findByName(const string &find_str)
212
211
{
213
 
  EngineVector::iterator iter= std::find_if(vector_of_engines.begin(),
214
 
                                            vector_of_engines.end(),
215
 
                                            FindEngineByName(predicate));
 
212
  string search_string(find_str);
 
213
  transform(search_string.begin(), search_string.end(),
 
214
            search_string.begin(), ::tolower);
 
215
 
 
216
  
 
217
  EngineVector::iterator iter= find_if(vector_of_engines.begin(),
 
218
                                       vector_of_engines.end(),
 
219
                                       FindEngineByName(search_string));
216
220
  if (iter != vector_of_engines.end())
217
221
  {
218
222
    StorageEngine *engine= *iter;
223
227
  return NULL;
224
228
}
225
229
 
226
 
StorageEngine *StorageEngine::findByName(Session& session, const std::string &predicate)
 
230
StorageEngine *StorageEngine::findByName(Session& session, const string &find_str)
227
231
{
228
 
  if (boost::iequals(predicate, DEFAULT_STRING))
 
232
  string search_string(find_str);
 
233
  transform(search_string.begin(), search_string.end(),
 
234
            search_string.begin(), ::tolower);
 
235
 
 
236
  if (search_string.compare("default") == 0)
229
237
    return session.getDefaultStorageEngine();
230
238
 
231
 
  EngineVector::iterator iter= std::find_if(vector_of_engines.begin(),
232
 
                                            vector_of_engines.end(),
233
 
                                            FindEngineByName(predicate));
 
239
  EngineVector::iterator iter= find_if(vector_of_engines.begin(),
 
240
                                       vector_of_engines.end(),
 
241
                                       FindEngineByName(search_string));
234
242
  if (iter != vector_of_engines.end())
235
243
  {
236
244
    StorageEngine *engine= *iter;
241
249
  return NULL;
242
250
}
243
251
 
244
 
class StorageEngineCloseConnection : public std::unary_function<StorageEngine *, void>
 
252
class StorageEngineCloseConnection : public unary_function<StorageEngine *, void>
245
253
{
246
254
  Session *session;
247
255
public:
263
271
*/
264
272
void StorageEngine::closeConnection(Session* session)
265
273
{
266
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
267
 
                StorageEngineCloseConnection(session));
 
274
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
275
           StorageEngineCloseConnection(session));
268
276
}
269
277
 
270
278
bool StorageEngine::flushLogs(StorageEngine *engine)
271
279
{
272
280
  if (engine == NULL)
273
281
  {
274
 
    if (std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
275
 
                     std::mem_fun(&StorageEngine::flush_logs))
 
282
    if (find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
283
                mem_fun(&StorageEngine::flush_logs))
276
284
        != vector_of_engines.begin())
277
285
      return true;
278
286
  }
284
292
  return false;
285
293
}
286
294
 
287
 
class StorageEngineGetTableDefinition: public std::unary_function<StorageEngine *,bool>
 
295
class StorageEngineGetTableDefinition: public unary_function<StorageEngine *,bool>
288
296
{
289
297
  Session& session;
290
 
  const TableIdentifier &identifier;
 
298
  TableIdentifier &identifier;
291
299
  message::Table &table_message;
292
300
  int &err;
293
301
 
294
302
public:
295
303
  StorageEngineGetTableDefinition(Session& session_arg,
296
 
                                  const TableIdentifier &identifier_arg,
 
304
                                  TableIdentifier &identifier_arg,
297
305
                                  message::Table &table_message_arg,
298
306
                                  int &err_arg) :
299
307
    session(session_arg), 
312
320
  }
313
321
};
314
322
 
315
 
class StorageEngineDoesTableExist: public std::unary_function<StorageEngine *, bool>
 
323
class StorageEngineDoesTableExist: public unary_function<StorageEngine *, bool>
316
324
{
317
325
  Session& session;
318
 
  const TableIdentifier &identifier;
 
326
  TableIdentifier &identifier;
319
327
 
320
328
public:
321
 
  StorageEngineDoesTableExist(Session& session_arg, const TableIdentifier &identifier_arg) :
 
329
  StorageEngineDoesTableExist(Session& session_arg, TableIdentifier &identifier_arg) :
322
330
    session(session_arg), 
323
331
    identifier(identifier_arg) 
324
332
  { }
333
341
  Utility method which hides some of the details of getTableDefinition()
334
342
*/
335
343
bool plugin::StorageEngine::doesTableExist(Session &session,
336
 
                                           const TableIdentifier &identifier,
 
344
                                           TableIdentifier &identifier,
337
345
                                           bool include_temporary_tables)
338
346
{
339
347
  if (include_temporary_tables)
343
351
  }
344
352
 
345
353
  EngineVector::iterator iter=
346
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
347
 
                 StorageEngineDoesTableExist(session, identifier));
 
354
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
355
            StorageEngineDoesTableExist(session, identifier));
348
356
 
349
357
  if (iter == vector_of_engines.end())
350
358
  {
354
362
  return true;
355
363
}
356
364
 
357
 
bool plugin::StorageEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier&)
 
365
bool plugin::StorageEngine::doDoesTableExist(Session&, TableIdentifier&)
358
366
{
359
 
  std::cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
 
367
  cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
360
368
  assert(0);
361
369
  return false;
362
370
}
367
375
  or any dropped tables that need to be removed from disk
368
376
*/
369
377
int StorageEngine::getTableDefinition(Session& session,
370
 
                                      const TableIdentifier &identifier,
371
 
                                      message::table::shared_ptr &table_message,
 
378
                                      TableIdentifier &identifier,
 
379
                                      message::Table &table_message,
372
380
                                      bool include_temporary_tables)
373
381
{
374
382
  int err= ENOENT;
375
383
 
376
384
  if (include_temporary_tables)
377
385
  {
378
 
    Table *table= session.find_temporary_table(identifier);
379
 
    if (table)
380
 
    {
381
 
      table_message.reset(new message::Table(*table->getShare()->getTableProto()));
 
386
    if (session.doGetTableDefinition(identifier, table_message) == EEXIST)
382
387
      return EEXIST;
383
 
    }
384
 
  }
385
 
 
386
 
  drizzled::message::table::shared_ptr table_ptr;
387
 
  if ((table_ptr= drizzled::message::Cache::singleton().find(identifier)))
388
 
  {
389
 
    table_message= table_ptr;
390
 
  }
391
 
 
392
 
  message::Table message;
 
388
  }
 
389
 
393
390
  EngineVector::iterator iter=
394
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
395
 
                 StorageEngineGetTableDefinition(session, identifier, message, err));
 
391
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
392
            StorageEngineGetTableDefinition(session, identifier, table_message, err));
396
393
 
397
394
  if (iter == vector_of_engines.end())
398
395
  {
399
396
    return ENOENT;
400
397
  }
401
 
  table_message.reset(new message::Table(message));
402
 
 
403
 
 drizzled::message::Cache::singleton().insert(identifier, table_message);
404
398
 
405
399
  return err;
406
400
}
439
433
   returns ENOENT if the file doesn't exists.
440
434
*/
441
435
int StorageEngine::dropTable(Session& session,
442
 
                             const TableIdentifier &identifier)
 
436
                             TableIdentifier &identifier)
443
437
{
444
438
  int error= 0;
445
439
  int error_proto;
446
 
  message::table::shared_ptr src_proto;
 
440
  message::Table src_proto;
447
441
  StorageEngine *engine;
448
442
 
449
443
  error_proto= StorageEngine::getTableDefinition(session, identifier, src_proto);
450
444
 
451
445
  if (error_proto == ER_CORRUPT_TABLE_DEFINITION)
452
446
  {
453
 
    std::string error_message;
454
 
    identifier.getSQLPath(error_message);
 
447
    string error_message;
455
448
 
 
449
    error_message.append(identifier.getSQLPath());
456
450
    error_message.append(" : ");
457
 
    error_message.append(src_proto->InitializationErrorString());
 
451
    error_message.append(src_proto.InitializationErrorString());
458
452
 
459
453
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
460
454
 
461
455
    return ER_CORRUPT_TABLE_DEFINITION;
462
456
  }
463
457
 
464
 
  if (src_proto)
465
 
    engine= StorageEngine::findByName(session, src_proto->engine().name());
466
 
  else
467
 
    engine= StorageEngine::findByName(session, "");
 
458
  engine= StorageEngine::findByName(session, src_proto.engine().name());
468
459
 
469
460
  if (not engine)
470
461
  {
471
 
    std::string error_message;
472
 
    identifier.getSQLPath(error_message);
473
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
 
462
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), identifier.getSQLPath().c_str());
474
463
 
475
464
    return ER_CORRUPT_TABLE_DEFINITION;
476
465
  }
485
474
 
486
475
int StorageEngine::dropTable(Session& session,
487
476
                             StorageEngine &engine,
488
 
                             const TableIdentifier &identifier)
 
477
                             TableIdentifier &identifier)
489
478
{
490
479
  int error;
491
480
 
504
493
    }
505
494
  }
506
495
 
507
 
  drizzled::message::Cache::singleton().erase(identifier);
508
496
 
509
497
  return error;
510
498
}
519
507
   1  error
520
508
*/
521
509
int StorageEngine::createTable(Session &session,
522
 
                               const TableIdentifier &identifier,
 
510
                               TableIdentifier &identifier,
523
511
                               message::Table& table_message)
524
512
{
525
513
  int error= 1;
526
 
  TableShare share(identifier);
527
 
  table::Shell table(share);
 
514
  Table table;
 
515
  TableShare share(identifier.getSchemaName().c_str(), 0, identifier.getTableName().c_str(), identifier.getPath().c_str());
528
516
  message::Table tmp_proto;
529
517
 
530
 
  if (share.parse_table_proto(session, table_message) || share.open_table_from_share(&session, identifier, "", 0, 0, table))
 
518
  if (share.parse_table_proto(session, table_message) || share.open_table_from_share(&session, "", 0, 0, table))
531
519
  { 
532
520
    // @note Error occured, we should probably do a little more here.
533
521
  }
556
544
 
557
545
    if (error)
558
546
    {
559
 
      std::string path;
560
 
      identifier.getSQLPath(path);
561
 
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), path.c_str(), error);
 
547
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
562
548
    }
563
549
 
564
 
    table.delete_table();
 
550
    table.delete_table(false);
565
551
  }
566
552
 
567
553
  return(error != 0);
568
554
}
569
555
 
570
 
Cursor *StorageEngine::getCursor(Table &arg)
 
556
Cursor *StorageEngine::getCursor(TableShare &share, memory::Root *alloc)
571
557
{
572
 
  return create(arg);
 
558
  return create(share, alloc);
573
559
}
574
560
 
 
561
class AddTableName : 
 
562
  public unary_function<StorageEngine *, void>
 
563
{
 
564
  CachedDirectory &directory;
 
565
  SchemaIdentifier &identifier;
 
566
  TableNameList &set_of_names;
 
567
 
 
568
public:
 
569
 
 
570
  AddTableName(CachedDirectory &directory_arg, SchemaIdentifier &identifier_arg, set<string>& of_names) :
 
571
    directory(directory_arg),
 
572
    identifier(identifier_arg),
 
573
    set_of_names(of_names)
 
574
  {
 
575
  }
 
576
 
 
577
  result_type operator() (argument_type engine)
 
578
  {
 
579
    engine->doGetTableNames(directory, identifier, set_of_names);
 
580
  }
 
581
};
 
582
 
575
583
class AddTableIdentifier : 
576
 
  public std::unary_function<StorageEngine *, void>
 
584
  public unary_function<StorageEngine *, void>
577
585
{
578
586
  CachedDirectory &directory;
579
 
  const SchemaIdentifier &identifier;
580
 
  TableIdentifier::vector &set_of_identifiers;
 
587
  SchemaIdentifier &identifier;
 
588
  TableIdentifiers &set_of_identifiers;
581
589
 
582
590
public:
583
591
 
584
 
  AddTableIdentifier(CachedDirectory &directory_arg, const SchemaIdentifier &identifier_arg, TableIdentifier::vector &of_names) :
 
592
  AddTableIdentifier(CachedDirectory &directory_arg, SchemaIdentifier &identifier_arg, TableIdentifiers &of_names) :
585
593
    directory(directory_arg),
586
594
    identifier(identifier_arg),
587
595
    set_of_identifiers(of_names)
595
603
};
596
604
 
597
605
 
598
 
void StorageEngine::getIdentifiers(Session &session, const SchemaIdentifier &schema_identifier, TableIdentifier::vector &set_of_identifiers)
599
 
{
600
 
  static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("information_schema");
601
 
  static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("data_dictionary");
602
 
 
603
 
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
604
 
 
605
 
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
606
 
  { }
607
 
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
608
 
  { }
609
 
  else
610
 
  {
611
 
    if (directory.fail())
612
 
    {
613
 
      errno= directory.getError();
614
 
      if (errno == ENOENT)
615
 
      {
616
 
        std::string path;
617
 
        schema_identifier.getSQLPath(path);
618
 
        my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), path.c_str());
619
 
      }
620
 
      else
621
 
      {
622
 
        my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), directory.getPath(), errno);
623
 
      }
624
 
 
625
 
      return;
626
 
    }
627
 
  }
628
 
 
629
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
630
 
                AddTableIdentifier(directory, schema_identifier, set_of_identifiers));
 
606
static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("information_schema");
 
607
static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("data_dictionary");
 
608
 
 
609
void StorageEngine::getTableNames(Session &session, SchemaIdentifier &schema_identifier, TableNameList &set_of_names)
 
610
{
 
611
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
 
612
 
 
613
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
 
614
  { }
 
615
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
 
616
  { }
 
617
  else
 
618
  {
 
619
    if (directory.fail())
 
620
    {
 
621
      errno= directory.getError();
 
622
      if (errno == ENOENT)
 
623
        my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), schema_identifier.getSQLPath().c_str());
 
624
      else
 
625
        my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), directory.getPath(), errno);
 
626
      return;
 
627
    }
 
628
  }
 
629
 
 
630
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
631
           AddTableName(directory, schema_identifier, set_of_names));
 
632
 
 
633
  session.doGetTableNames(directory, schema_identifier, set_of_names);
 
634
}
 
635
 
 
636
void StorageEngine::getTableIdentifiers(Session &session, SchemaIdentifier &schema_identifier, TableIdentifiers &set_of_identifiers)
 
637
{
 
638
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
 
639
 
 
640
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
 
641
  { }
 
642
  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
 
643
  { }
 
644
  else
 
645
  {
 
646
    if (directory.fail())
 
647
    {
 
648
      errno= directory.getError();
 
649
      if (errno == ENOENT)
 
650
        my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), schema_identifier.getSQLPath().c_str());
 
651
      else
 
652
        my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), directory.getPath(), errno);
 
653
      return;
 
654
    }
 
655
  }
 
656
 
 
657
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
658
           AddTableIdentifier(directory, schema_identifier, set_of_identifiers));
631
659
 
632
660
  session.doGetTableIdentifiers(directory, schema_identifier, set_of_identifiers);
633
661
}
634
662
 
635
 
class DropTable: public std::unary_function<TableIdentifier&, bool>
 
663
class DropTable: public unary_function<TableIdentifier&, bool>
636
664
{
637
665
  Session &session;
638
666
  StorageEngine *engine;
651
679
};
652
680
 
653
681
/* This will later be converted to TableIdentifiers */
654
 
class DropTables: public std::unary_function<StorageEngine *, void>
 
682
class DropTables: public unary_function<StorageEngine *, void>
655
683
{
656
684
  Session &session;
657
 
  TableIdentifier::vector &table_identifiers;
 
685
  TableIdentifierList &table_identifiers;
658
686
 
659
687
public:
660
688
 
661
 
  DropTables(Session &session_arg, TableIdentifier::vector &table_identifiers_arg) :
 
689
  DropTables(Session &session_arg, TableIdentifierList &table_identifiers_arg) :
662
690
    session(session_arg),
663
691
    table_identifiers(table_identifiers_arg)
664
692
  { }
667
695
  {
668
696
    // True returning from DropTable means the table has been successfully
669
697
    // deleted, so it should be removed from the list of tables to drop
670
 
    table_identifiers.erase(std::remove_if(table_identifiers.begin(),
671
 
                                           table_identifiers.end(),
672
 
                                           DropTable(session, engine)),
 
698
    table_identifiers.erase(remove_if(table_identifiers.begin(),
 
699
                                      table_identifiers.end(),
 
700
                                      DropTable(session, engine)),
673
701
                            table_identifiers.end());
674
702
  }
675
703
};
682
710
void StorageEngine::removeLostTemporaryTables(Session &session, const char *directory)
683
711
{
684
712
  CachedDirectory dir(directory, set_of_table_definition_ext);
685
 
  TableIdentifier::vector table_identifiers;
 
713
  TableIdentifierList table_identifiers;
686
714
 
687
715
  if (dir.fail())
688
716
  {
698
726
       fileIter != files.end(); fileIter++)
699
727
  {
700
728
    size_t length;
701
 
    std::string path;
 
729
    string path;
702
730
    CachedDirectory::Entry *entry= *fileIter;
703
731
 
704
732
    /* We remove the file extension. */
716
744
    }
717
745
  }
718
746
 
719
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
720
 
                DropTables(session, table_identifiers));
721
 
 
 
747
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
748
           DropTables(session, table_identifiers));
 
749
  
722
750
  /*
723
751
    Now we just clean up anything that might left over.
724
752
 
725
753
    We rescan because some of what might have been there should
726
754
    now be all nice and cleaned up.
727
755
  */
728
 
  std::set<std::string> all_exts= set_of_table_definition_ext;
 
756
  set<string> all_exts= set_of_table_definition_ext;
729
757
 
730
758
  for (EngineVector::iterator iter= vector_of_engines.begin();
731
759
       iter != vector_of_engines.end() ; iter++)
740
768
  for (CachedDirectory::Entries::iterator fileIter= files.begin();
741
769
       fileIter != files.end(); fileIter++)
742
770
  {
743
 
    std::string path;
 
771
    string path;
744
772
    CachedDirectory::Entry *entry= *fileIter;
745
773
 
746
774
    path+= directory;
795
823
    {
796
824
      const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
797
825
 
 
826
      if (key_nr == 0 &&
 
827
          (table->key_info[0].key_part[0].field->flags &
 
828
           AUTO_INCREMENT_FLAG)
 
829
          && (current_session)->lex->sql_command == SQLCOM_ALTER_TABLE)
 
830
      {
 
831
        err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE);
 
832
      }
 
833
 
798
834
      print_keydup_error(key_nr, err_msg, *table);
799
 
 
800
835
      return;
801
836
    }
802
837
    textno=ER_DUP_KEY;
1005
1040
}
1006
1041
 
1007
1042
 
1008
 
int StorageEngine::deleteDefinitionFromPath(const TableIdentifier &identifier)
 
1043
int StorageEngine::deleteDefinitionFromPath(TableIdentifier &identifier)
1009
1044
{
1010
 
  std::string path(identifier.getPath());
 
1045
  string path(identifier.getPath());
1011
1046
 
1012
1047
  path.append(DEFAULT_DEFINITION_FILE_EXT);
1013
1048
 
1014
1049
  return internal::my_delete(path.c_str(), MYF(0));
1015
1050
}
1016
1051
 
1017
 
int StorageEngine::renameDefinitionFromPath(const TableIdentifier &dest, const TableIdentifier &src)
 
1052
int StorageEngine::renameDefinitionFromPath(TableIdentifier &dest, TableIdentifier &src)
1018
1053
{
1019
1054
  message::Table table_message;
1020
 
  std::string src_path(src.getPath());
1021
 
  std::string dest_path(dest.getPath());
 
1055
  string src_path(src.getPath());
 
1056
  string dest_path(dest.getPath());
1022
1057
 
1023
1058
  src_path.append(DEFAULT_DEFINITION_FILE_EXT);
1024
1059
  dest_path.append(DEFAULT_DEFINITION_FILE_EXT);
1043
1078
  return error;
1044
1079
}
1045
1080
 
1046
 
int StorageEngine::writeDefinitionFromPath(const TableIdentifier &identifier, message::Table &table_message)
 
1081
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_message)
1047
1082
{
1048
1083
  char definition_file_tmp[FN_REFLEN];
1049
 
  std::string file_name(identifier.getPath());
 
1084
  string file_name(identifier.getPath());
1050
1085
 
1051
1086
  file_name.append(DEFAULT_DEFINITION_FILE_EXT);
1052
1087
 
1063
1098
  google::protobuf::io::ZeroCopyOutputStream* output=
1064
1099
    new google::protobuf::io::FileOutputStream(fd);
1065
1100
 
1066
 
  bool success;
1067
 
 
1068
 
  try
1069
 
  {
1070
 
    success= table_message.SerializeToZeroCopyStream(output);
1071
 
  }
1072
 
  catch (...)
1073
 
  {
1074
 
    success= false;
1075
 
  }
1076
 
 
1077
 
  if (not success)
 
1101
  if (not table_message.SerializeToZeroCopyStream(output))
1078
1102
  {
1079
1103
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
1080
1104
             table_message.InitializationErrorString().c_str());
1116
1140
  return 0;
1117
1141
}
1118
1142
 
1119
 
class CanCreateTable: public std::unary_function<StorageEngine *, bool>
 
1143
class CanCreateTable: public unary_function<StorageEngine *, bool>
1120
1144
{
1121
 
  const TableIdentifier &identifier;
 
1145
  TableIdentifier &identifier;
1122
1146
 
1123
1147
public:
1124
 
  CanCreateTable(const TableIdentifier &identifier_arg) :
 
1148
  CanCreateTable(TableIdentifier &identifier_arg) :
1125
1149
    identifier(identifier_arg)
1126
1150
  { }
1127
1151
 
1135
1159
/**
1136
1160
  @note on success table can be created.
1137
1161
*/
1138
 
bool StorageEngine::canCreateTable(const TableIdentifier &identifier)
 
1162
bool StorageEngine::canCreateTable(drizzled::TableIdentifier &identifier)
1139
1163
{
1140
1164
  EngineVector::iterator iter=
1141
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
1142
 
                 CanCreateTable(identifier));
 
1165
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
1166
            CanCreateTable(identifier));
1143
1167
 
1144
1168
  if (iter == vector_of_engines.end())
1145
1169
  {
1151
1175
 
1152
1176
bool StorageEngine::readTableFile(const std::string &path, message::Table &table_message)
1153
1177
{
1154
 
  std::fstream input(path.c_str(), std::ios::in | std::ios::binary);
 
1178
  fstream input(path.c_str(), ios::in | ios::binary);
1155
1179
 
1156
1180
  if (input.good())
1157
1181
  {
1158
 
    try {
1159
 
      if (table_message.ParseFromIstream(&input))
1160
 
      {
1161
 
        return true;
1162
 
      }
1163
 
    }
1164
 
    catch (...)
 
1182
    if (table_message.ParseFromIstream(&input))
1165
1183
    {
1166
 
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
1167
 
               table_message.InitializationErrorString().empty() ? "": table_message.InitializationErrorString().c_str());
 
1184
      return true;
1168
1185
    }
 
1186
 
 
1187
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
 
1188
             table_message.InitializationErrorString().c_str());
1169
1189
  }
1170
1190
  else
1171
1191
  {