~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-31 19:14:14 UTC
  • Revision ID: brian@gaz-20100331191414-9yv44mmpvf0tb7l1
Updated to use show schemas specific table.

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>
52
53
#include "drizzled/db.h"
53
54
 
54
55
#include <drizzled/table_proto.h>
55
 
#include <drizzled/plugin/event_observer.h>
56
 
 
57
 
#include <drizzled/table/shell.h>
58
 
 
59
 
#include "drizzled/message/cache.h"
60
 
 
61
 
#include <boost/algorithm/string/compare.hpp>
62
56
 
63
57
static bool shutdown_has_begun= false; // Once we put in the container for the vector/etc for engines this will go away.
64
58
 
 
59
using namespace std;
 
60
 
65
61
namespace drizzled
66
62
{
67
63
 
71
67
static EngineVector vector_of_engines;
72
68
static EngineVector vector_of_schema_engines;
73
69
 
74
 
const std::string DEFAULT_STRING("default");
75
70
const std::string UNKNOWN_STRING("UNKNOWN");
76
71
const std::string DEFAULT_DEFINITION_FILE_EXT(".dfe");
77
72
 
82
77
  return vector_of_schema_engines;
83
78
}
84
79
 
85
 
StorageEngine::StorageEngine(const std::string name_arg,
86
 
                             const std::bitset<HTON_BIT_SIZE> &flags_arg) :
 
80
StorageEngine::StorageEngine(const string name_arg,
 
81
                             const bitset<HTON_BIT_SIZE> &flags_arg) :
87
82
  Plugin(name_arg, "StorageEngine"),
88
83
  MonitoredInTransaction(), /* This gives the storage engine a "slot" or ID */
89
84
  flags(flags_arg)
101
96
}
102
97
 
103
98
 
104
 
int StorageEngine::renameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
 
99
int StorageEngine::renameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
105
100
{
106
 
  int error;
107
101
  setTransactionReadWrite(session);
108
102
 
109
 
  if (unlikely(plugin::EventObserver::beforeRenameTable(session, from, to)))
110
 
  {
111
 
    error= ER_EVENT_OBSERVER_PLUGIN;
112
 
  }
113
 
  else
114
 
  {
115
 
    error =  doRenameTable(session, from, to);
116
 
    if (unlikely(plugin::EventObserver::afterRenameTable(session, from, to, error)))
117
 
    {
118
 
      error= ER_EVENT_OBSERVER_PLUGIN;
119
 
    }
120
 
  }
121
 
  
122
 
  return error;
 
103
  return doRenameTable(session, from, to);
123
104
}
124
105
 
125
106
/**
137
118
  @retval
138
119
    !0  Error
139
120
*/
140
 
int StorageEngine::doDropTable(Session&, const TableIdentifier &identifier)
 
121
int StorageEngine::doDropTable(Session&, TableIdentifier &identifier)
141
122
                               
142
123
{
143
124
  int error= 0;
192
173
}
193
174
 
194
175
class FindEngineByName
195
 
  : public std::unary_function<StorageEngine *, bool>
 
176
  : public unary_function<StorageEngine *, bool>
196
177
{
197
 
  const std::string &predicate;
 
178
  const string &target;
198
179
 
199
180
public:
200
 
  explicit FindEngineByName(const std::string &target_arg) :
201
 
    predicate(target_arg)
 
181
  explicit FindEngineByName(const string &target_arg) :
 
182
    target(target_arg)
202
183
  {
203
184
  }
204
 
 
205
185
  result_type operator() (argument_type engine)
206
186
  {
207
 
    return boost::iequals(engine->getName(), predicate);
 
187
    string engine_name(engine->getName());
 
188
 
 
189
    transform(engine_name.begin(), engine_name.end(),
 
190
              engine_name.begin(), ::tolower);
 
191
    return engine_name == target;
208
192
  }
209
193
};
210
194
 
211
 
StorageEngine *StorageEngine::findByName(const std::string &predicate)
 
195
StorageEngine *StorageEngine::findByName(const string &find_str)
212
196
{
213
 
  EngineVector::iterator iter= std::find_if(vector_of_engines.begin(),
214
 
                                            vector_of_engines.end(),
215
 
                                            FindEngineByName(predicate));
 
197
  string search_string(find_str);
 
198
  transform(search_string.begin(), search_string.end(),
 
199
            search_string.begin(), ::tolower);
 
200
 
 
201
  
 
202
  EngineVector::iterator iter= find_if(vector_of_engines.begin(),
 
203
                                       vector_of_engines.end(),
 
204
                                       FindEngineByName(search_string));
216
205
  if (iter != vector_of_engines.end())
217
206
  {
218
207
    StorageEngine *engine= *iter;
223
212
  return NULL;
224
213
}
225
214
 
226
 
StorageEngine *StorageEngine::findByName(Session& session, const std::string &predicate)
 
215
StorageEngine *StorageEngine::findByName(Session& session, const string &find_str)
227
216
{
228
 
  if (boost::iequals(predicate, DEFAULT_STRING))
 
217
  string search_string(find_str);
 
218
  transform(search_string.begin(), search_string.end(),
 
219
            search_string.begin(), ::tolower);
 
220
 
 
221
  if (search_string.compare("default") == 0)
229
222
    return session.getDefaultStorageEngine();
230
223
 
231
 
  EngineVector::iterator iter= std::find_if(vector_of_engines.begin(),
232
 
                                            vector_of_engines.end(),
233
 
                                            FindEngineByName(predicate));
 
224
  EngineVector::iterator iter= find_if(vector_of_engines.begin(),
 
225
                                       vector_of_engines.end(),
 
226
                                       FindEngineByName(search_string));
234
227
  if (iter != vector_of_engines.end())
235
228
  {
236
229
    StorageEngine *engine= *iter;
241
234
  return NULL;
242
235
}
243
236
 
244
 
class StorageEngineCloseConnection : public std::unary_function<StorageEngine *, void>
 
237
class StorageEngineCloseConnection : public unary_function<StorageEngine *, void>
245
238
{
246
239
  Session *session;
247
240
public:
263
256
*/
264
257
void StorageEngine::closeConnection(Session* session)
265
258
{
266
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
267
 
                StorageEngineCloseConnection(session));
 
259
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
260
           StorageEngineCloseConnection(session));
268
261
}
269
262
 
270
263
bool StorageEngine::flushLogs(StorageEngine *engine)
271
264
{
272
265
  if (engine == NULL)
273
266
  {
274
 
    if (std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
275
 
                     std::mem_fun(&StorageEngine::flush_logs))
 
267
    if (find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
268
                mem_fun(&StorageEngine::flush_logs))
276
269
        != vector_of_engines.begin())
277
270
      return true;
278
271
  }
284
277
  return false;
285
278
}
286
279
 
287
 
class StorageEngineGetTableDefinition: public std::unary_function<StorageEngine *,bool>
 
280
class StorageEngineGetTableDefinition: public unary_function<StorageEngine *,bool>
288
281
{
289
282
  Session& session;
290
 
  const TableIdentifier &identifier;
 
283
  TableIdentifier &identifier;
291
284
  message::Table &table_message;
292
285
  int &err;
293
286
 
294
287
public:
295
288
  StorageEngineGetTableDefinition(Session& session_arg,
296
 
                                  const TableIdentifier &identifier_arg,
 
289
                                  TableIdentifier &identifier_arg,
297
290
                                  message::Table &table_message_arg,
298
291
                                  int &err_arg) :
299
292
    session(session_arg), 
312
305
  }
313
306
};
314
307
 
315
 
class StorageEngineDoesTableExist: public std::unary_function<StorageEngine *, bool>
 
308
class StorageEngineDoesTableExist: public unary_function<StorageEngine *, bool>
316
309
{
317
310
  Session& session;
318
 
  const TableIdentifier &identifier;
 
311
  TableIdentifier &identifier;
319
312
 
320
313
public:
321
 
  StorageEngineDoesTableExist(Session& session_arg, const TableIdentifier &identifier_arg) :
 
314
  StorageEngineDoesTableExist(Session& session_arg, TableIdentifier &identifier_arg) :
322
315
    session(session_arg), 
323
316
    identifier(identifier_arg) 
324
317
  { }
333
326
  Utility method which hides some of the details of getTableDefinition()
334
327
*/
335
328
bool plugin::StorageEngine::doesTableExist(Session &session,
336
 
                                           const TableIdentifier &identifier,
 
329
                                           TableIdentifier &identifier,
337
330
                                           bool include_temporary_tables)
338
331
{
339
332
  if (include_temporary_tables)
343
336
  }
344
337
 
345
338
  EngineVector::iterator iter=
346
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
347
 
                 StorageEngineDoesTableExist(session, identifier));
 
339
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
340
            StorageEngineDoesTableExist(session, identifier));
348
341
 
349
342
  if (iter == vector_of_engines.end())
350
343
  {
354
347
  return true;
355
348
}
356
349
 
357
 
bool plugin::StorageEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier&)
 
350
bool plugin::StorageEngine::doDoesTableExist(Session&, TableIdentifier&)
358
351
{
359
 
  std::cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
 
352
  cerr << " Engine was called for doDoesTableExist() and does not implement it: " << this->getName() << "\n";
360
353
  assert(0);
361
354
  return false;
362
355
}
367
360
  or any dropped tables that need to be removed from disk
368
361
*/
369
362
int StorageEngine::getTableDefinition(Session& session,
370
 
                                      const TableIdentifier &identifier,
371
 
                                      message::table::shared_ptr &table_message,
 
363
                                      TableIdentifier &identifier,
 
364
                                      message::Table &table_message,
372
365
                                      bool include_temporary_tables)
373
366
{
374
367
  int err= ENOENT;
375
368
 
376
369
  if (include_temporary_tables)
377
370
  {
378
 
    Table *table= session.find_temporary_table(identifier);
379
 
    if (table)
380
 
    {
381
 
      table_message.reset(new message::Table(*table->getShare()->getTableProto()));
 
371
    if (session.doGetTableDefinition(identifier, table_message) == EEXIST)
382
372
      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;
 
373
  }
 
374
 
393
375
  EngineVector::iterator iter=
394
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
395
 
                 StorageEngineGetTableDefinition(session, identifier, message, err));
 
376
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
377
            StorageEngineGetTableDefinition(session, identifier, table_message, err));
396
378
 
397
379
  if (iter == vector_of_engines.end())
398
380
  {
399
381
    return ENOENT;
400
382
  }
401
 
  table_message.reset(new message::Table(message));
402
 
 
403
 
 drizzled::message::Cache::singleton().insert(identifier, table_message);
404
383
 
405
384
  return err;
406
385
}
439
418
   returns ENOENT if the file doesn't exists.
440
419
*/
441
420
int StorageEngine::dropTable(Session& session,
442
 
                             const TableIdentifier &identifier)
 
421
                             TableIdentifier &identifier)
443
422
{
444
423
  int error= 0;
445
424
  int error_proto;
446
 
  message::table::shared_ptr src_proto;
 
425
  message::Table src_proto;
447
426
  StorageEngine *engine;
448
427
 
449
428
  error_proto= StorageEngine::getTableDefinition(session, identifier, src_proto);
450
429
 
451
430
  if (error_proto == ER_CORRUPT_TABLE_DEFINITION)
452
431
  {
453
 
    std::string error_message;
454
 
    identifier.getSQLPath(error_message);
 
432
    string error_message;
455
433
 
 
434
    error_message.append(identifier.getSQLPath());
456
435
    error_message.append(" : ");
457
 
    error_message.append(src_proto->InitializationErrorString());
 
436
    error_message.append(src_proto.InitializationErrorString());
458
437
 
459
438
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
460
439
 
461
440
    return ER_CORRUPT_TABLE_DEFINITION;
462
441
  }
463
442
 
464
 
  if (src_proto)
465
 
    engine= StorageEngine::findByName(session, src_proto->engine().name());
466
 
  else
467
 
    engine= StorageEngine::findByName(session, "");
 
443
  engine= StorageEngine::findByName(session, src_proto.engine().name());
468
444
 
469
445
  if (not engine)
470
446
  {
471
 
    std::string error_message;
472
 
    identifier.getSQLPath(error_message);
473
 
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), error_message.c_str());
 
447
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), identifier.getSQLPath().c_str());
474
448
 
475
449
    return ER_CORRUPT_TABLE_DEFINITION;
476
450
  }
485
459
 
486
460
int StorageEngine::dropTable(Session& session,
487
461
                             StorageEngine &engine,
488
 
                             const TableIdentifier &identifier)
 
462
                             TableIdentifier &identifier)
489
463
{
490
464
  int error;
491
465
 
492
466
  engine.setTransactionReadWrite(session);
493
 
  
494
 
  if (unlikely(plugin::EventObserver::beforeDropTable(session, identifier)))
495
 
  {
496
 
    error= ER_EVENT_OBSERVER_PLUGIN;
497
 
  }
498
 
  else
499
 
  {
500
 
    error= engine.doDropTable(session, identifier);
501
 
    if (unlikely(plugin::EventObserver::afterDropTable(session, identifier, error)))
502
 
    {
503
 
      error= ER_EVENT_OBSERVER_PLUGIN;
504
 
    }
505
 
  }
506
 
 
507
 
  drizzled::message::Cache::singleton().erase(identifier);
 
467
  error= engine.doDropTable(session, identifier);
508
468
 
509
469
  return error;
510
470
}
519
479
   1  error
520
480
*/
521
481
int StorageEngine::createTable(Session &session,
522
 
                               const TableIdentifier &identifier,
 
482
                               TableIdentifier &identifier,
 
483
                               bool update_create_info,
523
484
                               message::Table& table_message)
524
485
{
525
486
  int error= 1;
526
 
  TableShare share(identifier);
527
 
  table::Shell table(share);
 
487
  Table table;
 
488
  TableShare share(identifier.getSchemaName().c_str(), 0, identifier.getTableName().c_str(), identifier.getPath().c_str());
528
489
  message::Table tmp_proto;
529
490
 
530
 
  if (share.parse_table_proto(session, table_message) || share.open_table_from_share(&session, identifier, "", 0, 0, table))
 
491
  if (parse_table_proto(session, table_message, &share) || open_table_from_share(&session, &share, "", 0, 0, &table))
531
492
  { 
532
493
    // @note Error occured, we should probably do a little more here.
533
494
  }
534
495
  else
535
496
  {
 
497
    if (update_create_info)
 
498
      table.updateCreateInfo(&table_message);
 
499
 
536
500
    /* Check for legal operations against the Engine using the proto (if used) */
537
501
    if (table_message.type() == message::Table::TEMPORARY &&
538
502
        share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
556
520
 
557
521
    if (error)
558
522
    {
559
 
      std::string path;
560
 
      identifier.getSQLPath(path);
561
 
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), path.c_str(), error);
 
523
      my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
562
524
    }
563
525
 
564
 
    table.delete_table();
 
526
    table.closefrm(false);
565
527
  }
566
528
 
 
529
  share.free_table_share();
567
530
  return(error != 0);
568
531
}
569
532
 
570
 
Cursor *StorageEngine::getCursor(Table &arg)
 
533
Cursor *StorageEngine::getCursor(TableShare &share, memory::Root *alloc)
571
534
{
572
 
  return create(arg);
 
535
  return create(share, alloc);
573
536
}
574
537
 
575
 
class AddTableIdentifier : 
576
 
  public std::unary_function<StorageEngine *, void>
 
538
/**
 
539
  TODO -> Remove this to force all engines to implement their own file. Solves the "we only looked at dfe" problem.
 
540
*/
 
541
void StorageEngine::doGetTableNames(CachedDirectory&, SchemaIdentifier&, set<string>&)
 
542
{ }
 
543
 
 
544
class AddTableName : 
 
545
  public unary_function<StorageEngine *, void>
577
546
{
578
547
  CachedDirectory &directory;
579
 
  const SchemaIdentifier &identifier;
580
 
  TableIdentifier::vector &set_of_identifiers;
 
548
  SchemaIdentifier &identifier;
 
549
  TableNameList &set_of_names;
581
550
 
582
551
public:
583
552
 
584
 
  AddTableIdentifier(CachedDirectory &directory_arg, const SchemaIdentifier &identifier_arg, TableIdentifier::vector &of_names) :
 
553
  AddTableName(CachedDirectory &directory_arg, SchemaIdentifier &identifier_arg, set<string>& of_names) :
585
554
    directory(directory_arg),
586
555
    identifier(identifier_arg),
587
 
    set_of_identifiers(of_names)
 
556
    set_of_names(of_names)
588
557
  {
589
558
  }
590
559
 
591
560
  result_type operator() (argument_type engine)
592
561
  {
593
 
    engine->doGetTableIdentifiers(directory, identifier, set_of_identifiers);
 
562
    engine->doGetTableNames(directory, identifier, set_of_names);
594
563
  }
595
564
};
596
565
 
597
566
 
598
 
void StorageEngine::getIdentifiers(Session &session, const SchemaIdentifier &schema_identifier, TableIdentifier::vector &set_of_identifiers)
 
567
static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("information_schema");
 
568
static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("data_dictionary");
 
569
 
 
570
void StorageEngine::getTableNames(Session &session, SchemaIdentifier &schema_identifier, TableNameList &set_of_names)
599
571
{
600
 
  static SchemaIdentifier INFORMATION_SCHEMA_IDENTIFIER("information_schema");
601
 
  static SchemaIdentifier DATA_DICTIONARY_IDENTIFIER("data_dictionary");
602
 
 
603
572
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
604
573
 
605
574
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
612
581
    {
613
582
      errno= directory.getError();
614
583
      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
 
      }
 
584
        my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), schema_identifier.getSQLPath().c_str());
620
585
      else
621
 
      {
622
586
        my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), directory.getPath(), errno);
623
 
      }
624
 
 
625
587
      return;
626
588
    }
627
589
  }
628
590
 
629
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
630
 
                AddTableIdentifier(directory, schema_identifier, set_of_identifiers));
 
591
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
592
           AddTableName(directory, schema_identifier, set_of_names));
631
593
 
632
 
  session.doGetTableIdentifiers(directory, schema_identifier, set_of_identifiers);
 
594
  session.doGetTableNames(directory, schema_identifier, set_of_names);
633
595
}
634
596
 
635
 
class DropTable: public std::unary_function<TableIdentifier&, bool>
636
 
{
637
 
  Session &session;
638
 
  StorageEngine *engine;
639
 
 
640
 
public:
641
 
 
642
 
  DropTable(Session &session_arg, StorageEngine *engine_arg) :
643
 
    session(session_arg),
644
 
    engine(engine_arg)
645
 
  { }
646
 
 
647
 
  result_type operator() (argument_type identifier)
648
 
  {
649
 
    return engine->doDropTable(session, identifier) == 0;
650
 
  } 
651
 
};
652
 
 
653
597
/* This will later be converted to TableIdentifiers */
654
 
class DropTables: public std::unary_function<StorageEngine *, void>
 
598
class DropTables: public unary_function<StorageEngine *, void>
655
599
{
656
600
  Session &session;
657
 
  TableIdentifier::vector &table_identifiers;
 
601
  TableIdentifierList &table_identifiers;
658
602
 
659
603
public:
660
604
 
661
 
  DropTables(Session &session_arg, TableIdentifier::vector &table_identifiers_arg) :
 
605
  DropTables(Session &session_arg, TableIdentifierList &table_identifiers_arg) :
662
606
    session(session_arg),
663
607
    table_identifiers(table_identifiers_arg)
664
608
  { }
665
609
 
666
610
  result_type operator() (argument_type engine)
667
611
  {
668
 
    // True returning from DropTable means the table has been successfully
669
 
    // 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)),
673
 
                            table_identifiers.end());
 
612
    for (TableIdentifierList::iterator iter= table_identifiers.begin();
 
613
         iter != table_identifiers.end();
 
614
         iter++)
 
615
    {
 
616
      int error= engine->doDropTable(session, const_cast<TableIdentifier&>(*iter));
 
617
 
 
618
      // On a return of zero we know we found and deleted the table. So we
 
619
      // remove it from our search.
 
620
      if (not error)
 
621
        table_identifiers.erase(iter);
 
622
    }
674
623
  }
675
624
};
676
625
 
682
631
void StorageEngine::removeLostTemporaryTables(Session &session, const char *directory)
683
632
{
684
633
  CachedDirectory dir(directory, set_of_table_definition_ext);
685
 
  TableIdentifier::vector table_identifiers;
 
634
  TableIdentifierList table_identifiers;
686
635
 
687
636
  if (dir.fail())
688
637
  {
698
647
       fileIter != files.end(); fileIter++)
699
648
  {
700
649
    size_t length;
701
 
    std::string path;
 
650
    string path;
702
651
    CachedDirectory::Entry *entry= *fileIter;
703
652
 
704
653
    /* We remove the file extension. */
716
665
    }
717
666
  }
718
667
 
719
 
  std::for_each(vector_of_engines.begin(), vector_of_engines.end(),
720
 
                DropTables(session, table_identifiers));
721
 
 
 
668
  for_each(vector_of_engines.begin(), vector_of_engines.end(),
 
669
           DropTables(session, table_identifiers));
 
670
  
722
671
  /*
723
672
    Now we just clean up anything that might left over.
724
673
 
725
674
    We rescan because some of what might have been there should
726
675
    now be all nice and cleaned up.
727
676
  */
728
 
  std::set<std::string> all_exts= set_of_table_definition_ext;
 
677
  set<string> all_exts= set_of_table_definition_ext;
729
678
 
730
679
  for (EngineVector::iterator iter= vector_of_engines.begin();
731
680
       iter != vector_of_engines.end() ; iter++)
740
689
  for (CachedDirectory::Entries::iterator fileIter= files.begin();
741
690
       fileIter != files.end(); fileIter++)
742
691
  {
743
 
    std::string path;
 
692
    string path;
744
693
    CachedDirectory::Entry *entry= *fileIter;
745
694
 
746
695
    path+= directory;
758
707
  @note
759
708
    In case of delete table it's only safe to use the following parts of
760
709
    the 'table' structure:
761
 
    - table->getShare()->path
 
710
    - table->s->path
762
711
    - table->alias
763
712
*/
764
713
void StorageEngine::print_error(int error, myf errflag, Table &table)
795
744
    {
796
745
      const char *err_msg= ER(ER_DUP_ENTRY_WITH_KEY_NAME);
797
746
 
 
747
      if (key_nr == 0 &&
 
748
          (table->key_info[0].key_part[0].field->flags &
 
749
           AUTO_INCREMENT_FLAG)
 
750
          && (current_session)->lex->sql_command == SQLCOM_ALTER_TABLE)
 
751
      {
 
752
        err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE);
 
753
      }
 
754
 
798
755
      print_keydup_error(key_nr, err_msg, *table);
799
 
 
800
756
      return;
801
757
    }
802
758
    textno=ER_DUP_KEY;
823
779
        str.length(max_length-4);
824
780
        str.append(STRING_WITH_LEN("..."));
825
781
      }
826
 
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table->getShare()->getTableName(),
 
782
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table->s->table_name.str,
827
783
        str.c_ptr(), key_nr+1);
828
784
      return;
829
785
    }
901
857
    break;
902
858
  case HA_ERR_NO_SUCH_TABLE:
903
859
    assert(table);
904
 
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->getShare()->getSchemaName(),
905
 
             table->getShare()->getTableName());
 
860
    my_error(ER_NO_SUCH_TABLE, MYF(0), table->s->getSchemaName(),
 
861
             table->s->table_name.str);
906
862
    return;
907
863
  case HA_ERR_RBR_LOGGING_FAILED:
908
864
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
958
914
      return;
959
915
    }
960
916
  }
961
 
  my_error(textno, errflag, table->getShare()->getTableName(), error);
 
917
  my_error(textno, errflag, table->s->table_name.str, error);
962
918
}
963
919
 
964
920
 
1005
961
}
1006
962
 
1007
963
 
1008
 
int StorageEngine::deleteDefinitionFromPath(const TableIdentifier &identifier)
 
964
int StorageEngine::deleteDefinitionFromPath(TableIdentifier &identifier)
1009
965
{
1010
 
  std::string path(identifier.getPath());
 
966
  string path(identifier.getPath());
1011
967
 
1012
968
  path.append(DEFAULT_DEFINITION_FILE_EXT);
1013
969
 
1014
970
  return internal::my_delete(path.c_str(), MYF(0));
1015
971
}
1016
972
 
1017
 
int StorageEngine::renameDefinitionFromPath(const TableIdentifier &dest, const TableIdentifier &src)
 
973
int StorageEngine::renameDefinitionFromPath(TableIdentifier &dest, TableIdentifier &src)
1018
974
{
1019
975
  message::Table table_message;
1020
 
  std::string src_path(src.getPath());
1021
 
  std::string dest_path(dest.getPath());
 
976
  string src_path(src.getPath());
 
977
  string dest_path(dest.getPath());
1022
978
 
1023
979
  src_path.append(DEFAULT_DEFINITION_FILE_EXT);
1024
980
  dest_path.append(DEFAULT_DEFINITION_FILE_EXT);
1043
999
  return error;
1044
1000
}
1045
1001
 
1046
 
int StorageEngine::writeDefinitionFromPath(const TableIdentifier &identifier, message::Table &table_message)
 
1002
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_message)
1047
1003
{
1048
1004
  char definition_file_tmp[FN_REFLEN];
1049
 
  std::string file_name(identifier.getPath());
 
1005
  string file_name(identifier.getPath());
1050
1006
 
1051
1007
  file_name.append(DEFAULT_DEFINITION_FILE_EXT);
1052
1008
 
1063
1019
  google::protobuf::io::ZeroCopyOutputStream* output=
1064
1020
    new google::protobuf::io::FileOutputStream(fd);
1065
1021
 
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)
 
1022
  if (not table_message.SerializeToZeroCopyStream(output))
1078
1023
  {
1079
1024
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
1080
1025
             table_message.InitializationErrorString().c_str());
1116
1061
  return 0;
1117
1062
}
1118
1063
 
1119
 
class CanCreateTable: public std::unary_function<StorageEngine *, bool>
 
1064
class CanCreateTable: public unary_function<StorageEngine *, bool>
1120
1065
{
1121
 
  const TableIdentifier &identifier;
 
1066
  TableIdentifier &identifier;
1122
1067
 
1123
1068
public:
1124
 
  CanCreateTable(const TableIdentifier &identifier_arg) :
 
1069
  CanCreateTable(TableIdentifier &identifier_arg) :
1125
1070
    identifier(identifier_arg)
1126
1071
  { }
1127
1072
 
1135
1080
/**
1136
1081
  @note on success table can be created.
1137
1082
*/
1138
 
bool StorageEngine::canCreateTable(const TableIdentifier &identifier)
 
1083
bool StorageEngine::canCreateTable(drizzled::TableIdentifier &identifier)
1139
1084
{
1140
1085
  EngineVector::iterator iter=
1141
 
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
1142
 
                 CanCreateTable(identifier));
 
1086
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
1087
            CanCreateTable(identifier));
1143
1088
 
1144
1089
  if (iter == vector_of_engines.end())
1145
1090
  {
1151
1096
 
1152
1097
bool StorageEngine::readTableFile(const std::string &path, message::Table &table_message)
1153
1098
{
1154
 
  std::fstream input(path.c_str(), std::ios::in | std::ios::binary);
 
1099
  fstream input(path.c_str(), ios::in | ios::binary);
1155
1100
 
1156
1101
  if (input.good())
1157
1102
  {
1158
 
    try {
1159
 
      if (table_message.ParseFromIstream(&input))
1160
 
      {
1161
 
        return true;
1162
 
      }
1163
 
    }
1164
 
    catch (...)
 
1103
    if (table_message.ParseFromIstream(&input))
1165
1104
    {
1166
 
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
1167
 
               table_message.InitializationErrorString().empty() ? "": table_message.InitializationErrorString().c_str());
 
1105
      return true;
1168
1106
    }
 
1107
 
 
1108
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
 
1109
             table_message.InitializationErrorString().c_str());
1169
1110
  }
1170
1111
  else
1171
1112
  {