~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

edit

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>
 
35
#include "drizzled/cached_directory.h"
36
36
 
37
37
#include <drizzled/definitions.h>
38
38
#include <drizzled/base.h>
43
43
#include <drizzled/gettext.h>
44
44
#include <drizzled/unireg.h>
45
45
#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>
 
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"
52
53
 
53
54
#include <drizzled/table_proto.h>
54
55
#include <drizzled/plugin/event_observer.h>
55
 
#include <drizzled/internal_error_handler.h>
56
56
 
57
57
#include <drizzled/table/shell.h>
58
58
 
59
 
#include <drizzled/message/cache.h>
 
59
#include "drizzled/message/cache.h"
60
60
 
61
61
#include <boost/algorithm/string/compare.hpp>
62
62
 
361
361
  return false;
362
362
}
363
363
 
 
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 identifier::Table &identifier,
 
371
                                      message::table::shared_ptr &table_message,
 
372
                                      bool include_temporary_tables)
 
373
{
 
374
  drizzled::error_t err= static_cast<drizzled::error_t>(ENOENT);
 
375
 
 
376
  if (include_temporary_tables)
 
377
  {
 
378
    Table *table= session.find_temporary_table(identifier);
 
379
    if (table)
 
380
    {
 
381
      table_message.reset(new message::Table(*table->getShare()->getTableProto()));
 
382
      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;
 
393
  EngineVector::iterator iter=
 
394
    std::find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
395
                 StorageEngineGetTableDefinition(session, identifier, message, err));
 
396
 
 
397
  if (iter == vector_of_engines.end())
 
398
  {
 
399
    return ENOENT;
 
400
  }
 
401
  table_message.reset(new message::Table(message));
 
402
 
 
403
 drizzled::message::Cache::singleton().insert(identifier, table_message);
 
404
 
 
405
  return err;
 
406
}
 
407
 
364
408
message::table::shared_ptr StorageEngine::getTableMessage(Session& session,
365
409
                                                          identifier::Table::const_reference identifier,
 
410
                                                          drizzled::error_t &error,
366
411
                                                          bool include_temporary_tables)
367
412
{
368
 
  drizzled::error_t error;
369
413
  error= static_cast<drizzled::error_t>(ENOENT);
370
414
 
371
415
  if (include_temporary_tables)
373
417
    Table *table= session.find_temporary_table(identifier);
374
418
    if (table)
375
419
    {
376
 
      return message::table::shared_ptr(new message::Table(*table->getShare()->getTableMessage()));
 
420
      error= EE_OK;
 
421
      return message::table::shared_ptr(new message::Table(*table->getShare()->getTableProto()));
377
422
    }
378
423
  }
379
424
 
390
435
 
391
436
  if (iter == vector_of_engines.end())
392
437
  {
 
438
    error= static_cast<drizzled::error_t>(ENOENT);
393
439
    return message::table::shared_ptr();
394
440
  }
395
441
  message::table::shared_ptr table_message(new message::Table(message));
640
686
 
641
687
void StorageEngine::getIdentifiers(Session &session, const identifier::Schema &schema_identifier, identifier::Table::vector &set_of_identifiers)
642
688
{
 
689
  static identifier::Schema INFORMATION_SCHEMA_IDENTIFIER("information_schema");
 
690
  static identifier::Schema DATA_DICTIONARY_IDENTIFIER("data_dictionary");
 
691
 
643
692
  CachedDirectory directory(schema_identifier.getPath(), set_of_table_definition_ext);
644
693
 
645
694
  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
801
850
    - table->getShare()->path
802
851
    - table->alias
803
852
*/
804
 
void StorageEngine::print_error(int error, myf errflag, const Table &table) const
 
853
void StorageEngine::print_error(int error, myf errflag, Table &table)
805
854
{
806
855
  drizzled::error_t textno= ER_GET_ERRNO;
807
856
  switch (error) {
933
982
    textno=ER_TABLE_DEF_CHANGED;
934
983
    break;
935
984
  case HA_ERR_NO_SUCH_TABLE:
936
 
    {
937
 
      identifier::Table identifier(table.getShare()->getSchemaName(), table.getShare()->getTableName());
938
 
      my_error(ER_TABLE_UNKNOWN, identifier);
939
 
      return;
940
 
    }
 
985
    my_error(ER_NO_SUCH_TABLE, MYF(0), table.getShare()->getSchemaName(),
 
986
             table.getShare()->getTableName());
 
987
    return;
941
988
  case HA_ERR_RBR_LOGGING_FAILED:
942
989
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
943
990
    break;
1005
1052
  @return
1006
1053
    Returns true if this is a temporary error
1007
1054
*/
1008
 
bool StorageEngine::get_error_message(int , String* ) const
 
1055
bool StorageEngine::get_error_message(int , String* )
1009
1056
{
1010
1057
  return false;
1011
1058
}
1012
1059
 
1013
1060
 
1014
 
void StorageEngine::print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const
 
1061
void StorageEngine::print_keydup_error(uint32_t key_nr, const char *msg, Table &table)
1015
1062
{
1016
1063
  /* Write the duplicated key in the error message */
1017
1064
  char key[MAX_KEY_LENGTH];