~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/archive/ha_archive.cc

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
static unsigned int global_version;
110
110
 
111
111
/* The file extension */
112
 
#define ARZ ".ARZ"               // The data file
 
112
#define ARZ ".arz"               // The data file
113
113
#define ARN ".ARN"               // Files used during an optimize call
114
114
 
115
115
 
134
134
  NULL
135
135
};
136
136
 
137
 
class ArchiveTableNameIterator: public drizzled::plugin::TableNameIteratorImplementation
138
 
{
139
 
private:
140
 
  MY_DIR *dirp;
141
 
  uint32_t current_entry;
142
 
 
143
 
public:
144
 
  ArchiveTableNameIterator(const std::string &database)
145
 
    : drizzled::plugin::TableNameIteratorImplementation(database), dirp(NULL), current_entry(-1)
146
 
    {};
147
 
 
148
 
  ~ArchiveTableNameIterator();
149
 
 
150
 
  int next(std::string *name);
151
 
 
152
 
};
153
 
 
154
 
ArchiveTableNameIterator::~ArchiveTableNameIterator()
155
 
{
156
 
  if (dirp)
157
 
    my_dirend(dirp);
158
 
}
159
 
 
160
 
int ArchiveTableNameIterator::next(string *name)
161
 
{
162
 
  char uname[NAME_LEN + 1];
163
 
  FILEINFO *file;
164
 
  char *ext;
165
 
  uint32_t file_name_len;
166
 
  const char *wild= NULL;
167
 
 
168
 
  if (dirp == NULL)
169
 
  {
170
 
    bool dir= false;
171
 
    char path[FN_REFLEN];
172
 
 
173
 
    build_table_filename(path, sizeof(path), db.c_str(), "", false);
174
 
    dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0));
175
 
    if (dirp == NULL)
176
 
    {
177
 
      if (my_errno == ENOENT)
178
 
        my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db.c_str());
179
 
      else
180
 
        my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
181
 
      return(ENOENT);
182
 
    }
183
 
    current_entry= -1;
184
 
  }
185
 
 
186
 
  while(true)
187
 
  {
188
 
    current_entry++;
189
 
 
190
 
    if (current_entry == dirp->number_off_files)
191
 
    {
192
 
      my_dirend(dirp);
193
 
      dirp= NULL;
194
 
      return -1;
195
 
    }
196
 
 
197
 
    file= dirp->dir_entry + current_entry;
198
 
 
199
 
    ext= strchr(file->name, '.');
200
 
 
201
 
    if (ext != NULL)
202
 
    {
203
 
      if (my_strcasecmp(system_charset_info, ext, ARZ) || 
204
 
          is_prefix(file->name, TMP_FILE_PREFIX))
205
 
        continue;
206
 
      *ext= 0;
207
 
    }
208
 
    file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
209
 
 
210
 
    uname[file_name_len]= '\0';
211
 
 
212
 
    if (wild && wild_compare(uname, wild, 0))
213
 
      continue;
214
 
    if (name)
215
 
      name->assign(uname);
216
 
 
217
 
    return 0;
218
 
  }
219
 
}
220
 
 
221
137
class ArchiveEngine : public drizzled::plugin::StorageEngine
222
138
{
223
139
public:
224
140
  ArchiveEngine(const string &name_arg)
225
141
   : drizzled::plugin::StorageEngine(name_arg,
226
142
                                     HTON_FILE_BASED
227
 
                                      | HTON_HAS_DATA_DICTIONARY) {}
 
143
                                      | HTON_HAS_DATA_DICTIONARY) 
 
144
  {
 
145
    table_definition_ext= ARZ;
 
146
  }
228
147
 
229
148
  virtual Cursor *create(TableShare *table,
230
149
                          MEM_ROOT *mem_root)
236
155
    return ha_archive_exts;
237
156
  }
238
157
 
239
 
  int createTableImplementation(Session *session, const char *table_name,
240
 
                                Table *table_arg, HA_CREATE_INFO *create_info,
241
 
                                drizzled::message::Table* proto);
242
 
 
243
 
  int getTableProtoImplementation(const char* path,
244
 
                                  drizzled::message::Table *table_proto);
245
 
 
246
 
  drizzled::plugin::TableNameIteratorImplementation* tableNameIterator(const std::string &database)
247
 
  {
248
 
    return new ArchiveTableNameIterator(database);
249
 
  }
 
158
  int doCreateTable(Session *session, const char *table_name,
 
159
                    Table& table_arg, HA_CREATE_INFO& create_info,
 
160
                    drizzled::message::Table& proto);
 
161
 
 
162
  int doGetTableDefinition(Session& session,
 
163
                           const char* path,
 
164
                           const char *db,
 
165
                           const char *table_name,
 
166
                           const bool is_tmp,
 
167
                           drizzled::message::Table *table_proto);
 
168
 
 
169
  void doGetTableNames(CachedDirectory &directory, string& , set<string>& set_of_names);
 
170
 
 
171
  int doDropTable(Session&, const string table_path);
250
172
};
251
173
 
252
 
int ArchiveEngine::getTableProtoImplementation(const char* path,
253
 
                                         drizzled::message::Table *table_proto)
 
174
 
 
175
void ArchiveEngine::doGetTableNames(CachedDirectory &directory, 
 
176
                                    string&, 
 
177
                                    set<string>& set_of_names)
 
178
{
 
179
  CachedDirectory::Entries entries= directory.getEntries();
 
180
 
 
181
  for (CachedDirectory::Entries::iterator entry_iter= entries.begin(); 
 
182
       entry_iter != entries.end(); ++entry_iter)
 
183
  {
 
184
    CachedDirectory::Entry *entry= *entry_iter;
 
185
    string *filename= &entry->filename;
 
186
 
 
187
    assert(filename->size());
 
188
 
 
189
    const char *ext= strchr(filename->c_str(), '.');
 
190
 
 
191
    if (ext == NULL || my_strcasecmp(system_charset_info, ext, ARZ) ||
 
192
        is_prefix(filename->c_str(), TMP_FILE_PREFIX))
 
193
    {  }
 
194
    else
 
195
    {
 
196
      char uname[NAME_LEN + 1];
 
197
      uint32_t file_name_len;
 
198
 
 
199
      file_name_len= filename_to_tablename(filename->c_str(), uname, sizeof(uname));
 
200
      // TODO: Remove need for memory copy here
 
201
      uname[file_name_len - sizeof(ARZ) + 1]= '\0'; // Subtract ending, place NULL 
 
202
      set_of_names.insert(uname);
 
203
    }
 
204
  }
 
205
}
 
206
 
 
207
 
 
208
int ArchiveEngine::doDropTable(Session&,
 
209
                               const string table_path)
 
210
{
 
211
  int error= 0;
 
212
  char buff[FN_REFLEN];
 
213
 
 
214
  fn_format(buff, table_path.c_str(), "", ARZ,
 
215
            MY_UNPACK_FILENAME|MY_APPEND_EXT);
 
216
  if (my_delete_with_symlink(buff, MYF(0)))
 
217
  {
 
218
    if (my_errno != ENOENT)
 
219
    {
 
220
      error= my_errno;
 
221
    }
 
222
  }
 
223
 
 
224
  return error;
 
225
}
 
226
 
 
227
int ArchiveEngine::doGetTableDefinition(Session&,
 
228
                                        const char* path,
 
229
                                        const char *,
 
230
                                        const char *,
 
231
                                        const bool,
 
232
                                        drizzled::message::Table *table_proto)
254
233
{
255
234
  struct stat stat_info;
256
235
  int error= 0;
644
623
  of creation.
645
624
*/
646
625
 
647
 
int ArchiveEngine::createTableImplementation(Session *,
648
 
                                             const char *table_name,
649
 
                                             Table *table_arg,
650
 
                                             HA_CREATE_INFO *create_info,
651
 
                                             drizzled::message::Table *proto)
 
626
int ArchiveEngine::doCreateTable(Session *,
 
627
                                 const char *table_name,
 
628
                                 Table& table_arg,
 
629
                                 HA_CREATE_INFO& create_info,
 
630
                                 drizzled::message::Table& proto)
652
631
{
653
632
  char name_buff[FN_REFLEN];
654
633
  int error= 0;
656
635
  uint64_t auto_increment_value;
657
636
  string serialized_proto;
658
637
 
659
 
  auto_increment_value= create_info->auto_increment_value;
 
638
  auto_increment_value= create_info.auto_increment_value;
660
639
 
661
 
  for (uint32_t key= 0; key < table_arg->sizeKeys(); key++)
 
640
  for (uint32_t key= 0; key < table_arg.sizeKeys(); key++)
662
641
  {
663
 
    KEY *pos= table_arg->key_info+key;
 
642
    KEY *pos= table_arg.key_info+key;
664
643
    KEY_PART_INFO *key_part=     pos->key_part;
665
644
    KEY_PART_INFO *key_part_end= key_part + pos->key_parts;
666
645
 
690
669
    goto error2;
691
670
  }
692
671
 
693
 
  proto->SerializeToString(&serialized_proto);
 
672
  proto.SerializeToString(&serialized_proto);
694
673
 
695
674
  if (azwrite_frm(&create_stream, serialized_proto.c_str(),
696
675
                  serialized_proto.length()))
697
676
    goto error2;
698
677
 
699
 
  if (proto->options().has_comment())
 
678
  if (proto.options().has_comment())
700
679
  {
701
680
    int write_length;
702
681
 
703
682
    write_length= azwrite_comment(&create_stream,
704
 
                                  proto->options().comment().c_str(),
705
 
                                  proto->options().comment().length());
 
683
                                  proto.options().comment().c_str(),
 
684
                                  proto.options().comment().length());
706
685
 
707
686
    if (write_length < 0)
708
687
    {
1459
1438
  NULL
1460
1439
};
1461
1440
 
1462
 
drizzle_declare_plugin(archive)
 
1441
drizzle_declare_plugin
1463
1442
{
1464
1443
  "ARCHIVE",
1465
1444
  "3.5",