~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/filesystem_engine/filesystem_engine.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "config.h"
20
20
#include <drizzled/field.h>
21
21
#include <drizzled/field/blob.h>
22
 
#include <drizzled/field/timestamp.h>
23
22
#include <drizzled/error.h>
24
23
#include <drizzled/table.h>
25
24
#include <drizzled/session.h>
87
86
 
88
87
  int doCreateTable(Session &,
89
88
                    Table &table_arg,
90
 
                    const drizzled::TableIdentifier &identifier,
 
89
                    const drizzled::identifier::Table &identifier,
91
90
                    drizzled::message::Table&);
92
91
 
93
92
  int doGetTableDefinition(Session& ,
94
 
                           const drizzled::TableIdentifier &,
 
93
                           const drizzled::identifier::Table &,
95
94
                           drizzled::message::Table &);
96
95
 
97
 
  int doDropTable(Session&, const TableIdentifier &);
 
96
  int doDropTable(Session&, const identifier::Table &);
98
97
 
99
98
  /* operations on FilesystemTableShare */
100
99
  FilesystemTableShare *findOpenTable(const string table_name);
104
103
  uint32_t max_keys()          const { return 0; }
105
104
  uint32_t max_key_parts()     const { return 0; }
106
105
  uint32_t max_key_length()    const { return 0; }
107
 
  bool doDoesTableExist(Session& , const TableIdentifier &);
108
 
  int doRenameTable(Session&, const TableIdentifier &, const TableIdentifier &);
 
106
  bool doDoesTableExist(Session& , const identifier::Table &);
 
107
  int doRenameTable(Session&, const identifier::Table &, const identifier::Table &);
109
108
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
110
 
                             const drizzled::SchemaIdentifier &schema_identifier,
111
 
                             drizzled::TableIdentifiers &set_of_identifiers);
 
109
                             const drizzled::identifier::Schema &schema_identifier,
 
110
                             drizzled::identifier::Table::vector &set_of_identifiers);
112
111
private:
113
112
  void getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
114
 
                                   const drizzled::SchemaIdentifier &schema_identifier,
 
113
                                   const drizzled::identifier::Schema &schema_identifier,
115
114
                                   drizzled::plugin::TableNameList *set_of_names,
116
 
                                   drizzled::TableIdentifiers *set_of_identifiers);
 
115
                                   drizzled::identifier::Table::vector *set_of_identifiers);
117
116
};
118
117
 
119
118
void FilesystemEngine::getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
120
 
                                                   const drizzled::SchemaIdentifier &schema_identifier,
 
119
                                                   const drizzled::identifier::Schema &schema_identifier,
121
120
                                                   drizzled::plugin::TableNameList *set_of_names,
122
 
                                                   drizzled::TableIdentifiers *set_of_identifiers)
 
121
                                                   drizzled::identifier::Table::vector *set_of_identifiers)
123
122
{
124
123
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
125
124
 
141
140
      char uname[NAME_LEN + 1];
142
141
      uint32_t file_name_len;
143
142
 
144
 
      file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
 
143
      file_name_len= identifier::Table::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
145
144
      uname[file_name_len - sizeof(FILESYSTEM_EXT) + 1]= '\0';
146
145
      if (set_of_names)
147
146
        set_of_names->insert(uname);
148
147
      if (set_of_identifiers)
149
 
        set_of_identifiers->push_back(TableIdentifier(schema_identifier, uname));
 
148
        set_of_identifiers->push_back(identifier::Table(schema_identifier, uname));
150
149
    }
151
150
  }
152
151
}
153
152
 
154
153
void FilesystemEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
155
 
                                             const drizzled::SchemaIdentifier &schema_identifier,
156
 
                                             drizzled::TableIdentifiers &set_of_identifiers)
 
154
                                             const drizzled::identifier::Schema &schema_identifier,
 
155
                                             drizzled::identifier::Table::vector &set_of_identifiers)
157
156
{
158
157
  getTableNamesFromFilesystem(directory, schema_identifier, NULL, &set_of_identifiers);
159
158
}
160
159
 
161
 
int FilesystemEngine::doDropTable(Session &, const TableIdentifier &identifier)
 
160
int FilesystemEngine::doDropTable(Session &, const identifier::Table &identifier)
162
161
{
163
162
  string new_path(identifier.getPath());
164
163
  new_path+= FILESYSTEM_EXT;
170
169
  return err;
171
170
}
172
171
 
173
 
bool FilesystemEngine::doDoesTableExist(Session &, const TableIdentifier &identifier)
 
172
bool FilesystemEngine::doDoesTableExist(Session &, const identifier::Table &identifier)
174
173
{
175
174
  string proto_path(identifier.getPath());
176
175
  proto_path.append(FILESYSTEM_EXT);
282
281
}
283
282
 
284
283
int FilesystemEngine::doGetTableDefinition(Session &,
285
 
                                           const drizzled::TableIdentifier &identifier,
 
284
                                           const drizzled::identifier::Table &identifier,
286
285
                                           drizzled::message::Table &table_proto)
287
286
{
288
287
  string new_path(identifier.getPath());
305
304
    if (not table_proto.IsInitialized())
306
305
    {
307
306
      my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
 
307
               table_proto.name().empty() ? " " : table_proto.name().c_str(),
308
308
               table_proto.InitializationErrorString().c_str());
 
309
 
309
310
      return ER_CORRUPT_TABLE_DEFINITION;
310
311
    }
311
312
 
317
318
  // then columns of this table are added dynamically here.
318
319
  FormatInfo format;
319
320
  format.parseFromTable(&table_proto);
320
 
  if (!format.isTagFormat() || !format.isFileGiven()) {
 
321
  if (not format.isTagFormat() || not format.isFileGiven())
 
322
  {
321
323
    close(fd);
322
324
    return EEXIST;
323
325
  }
324
326
 
325
 
  vector< map<string, string> > vm;
326
 
  if (parseTaggedFile(format, vm) != 0) {
 
327
  std::vector< std::map<std::string, std::string> > vm;
 
328
  if (parseTaggedFile(format, vm) != 0)
 
329
  {
327
330
    close(fd);
328
331
 
329
332
    return EEXIST;
336
339
  // we don't care what user provides, just clear them all
337
340
  table_proto.clear_field();
338
341
  // we take the first section as sample
339
 
  map<string, string> kv= vm[0];
340
 
  for (map<string, string>::iterator iter= kv.begin();
 
342
  std::map<string, string> kv= vm[0];
 
343
  for (std::map<string, string>::iterator iter= kv.begin();
341
344
       iter != kv.end();
342
345
       ++iter)
343
346
  {
460
463
{
461
464
}
462
465
 
463
 
int FilesystemCursor::doOpen(const drizzled::TableIdentifier &identifier, int, uint32_t)
 
466
int FilesystemCursor::doOpen(const drizzled::identifier::Table &identifier, int, uint32_t)
464
467
{
465
468
  if (!(share= get_share(identifier.getPath().c_str())))
466
469
    return ENOENT;
487
490
 
488
491
int FilesystemCursor::doStartTableScan(bool)
489
492
{
490
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
493
  sql_command_type = getTable()->getSession()->getSqlCommand();
491
494
 
492
495
  if (thread_locked)
493
496
    critical_section_exit();
561
564
        if ((*field)->isReadSet() || (*field)->isWriteSet())
562
565
        {
563
566
          (*field)->setWriteSet();
564
 
          (*field)->store(content.c_str(),
565
 
                          (uint32_t)content.length(),
566
 
                          &my_charset_bin,
567
 
                          CHECK_FIELD_WARN);
 
567
          (*field)->store_and_check(CHECK_FIELD_WARN,
 
568
                                    content.c_str(),
 
569
                                    (uint32_t)content.length(),
 
570
                                    &my_charset_bin);
568
571
        }
569
572
        else
 
573
        {
570
574
          (*field)->set_default();
 
575
        }
571
576
      }
572
577
      else
573
578
        (*field)->set_null();
629
634
        if ((*field)->isReadSet() || (*field)->isWriteSet())
630
635
        {
631
636
          (*field)->setWriteSet();
632
 
          (*field)->store(content.c_str(),
633
 
                          (uint32_t)content.length(),
634
 
                          &my_charset_bin,
635
 
                          CHECK_FIELD_WARN);
 
637
          (*field)->store_and_check(CHECK_FIELD_WARN,
 
638
                                    content.c_str(),
 
639
                                    (uint32_t)content.length(),
 
640
                                    &my_charset_bin);
636
641
        }
637
642
        else
638
643
        {
696
701
 
697
702
int FilesystemCursor::doEndTableScan()
698
703
{
699
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
704
  sql_command_type = getTable->getSession()->getSqlCommand();
700
705
 
701
706
  if (share->format.isTagFormat())
702
707
  {
817
822
  if (share->format.isTagFormat())
818
823
    return 0;
819
824
 
820
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
825
  sql_command_type = getTable()->getSession()->getSqlCommand();
821
826
 
822
827
  critical_section_enter();
823
828
 
888
893
  return 0;
889
894
}
890
895
 
891
 
int FilesystemEngine::doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to)
 
896
int FilesystemEngine::doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to)
892
897
{
893
898
  if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), FILESYSTEM_EXT))
894
899
    return errno;
902
907
}
903
908
 
904
909
int FilesystemEngine::doCreateTable(Session &,
905
 
                        Table&,
906
 
                        const drizzled::TableIdentifier &identifier,
907
 
                        drizzled::message::Table &proto)
 
910
                                    Table&,
 
911
                                    const drizzled::identifier::Table &identifier,
 
912
                                    drizzled::message::Table &proto)
908
913
{
909
914
  FormatInfo format;
910
915
  format.parseFromTable(&proto);
951
956
  "Filesystem Engine",
952
957
  PLUGIN_LICENSE_GPL,
953
958
  filesystem_init_func, /* Plugin Init */
954
 
  NULL,                       /* system variables                */
 
959
  NULL,                       /* depends */
955
960
  NULL                        /* config options                  */
956
961
}
957
962
DRIZZLE_DECLARE_PLUGIN_END;