137
class ArchiveTableNameIterator: public drizzled::plugin::TableNameIteratorImplementation
141
uint32_t current_entry;
144
ArchiveTableNameIterator(const std::string &database)
145
: drizzled::plugin::TableNameIteratorImplementation(database), dirp(NULL), current_entry(-1)
148
~ArchiveTableNameIterator();
150
int next(std::string *name);
154
ArchiveTableNameIterator::~ArchiveTableNameIterator()
160
int ArchiveTableNameIterator::next(string *name)
162
char uname[NAME_LEN + 1];
165
uint32_t file_name_len;
166
const char *wild= NULL;
171
char path[FN_REFLEN];
173
build_table_filename(path, sizeof(path), db.c_str(), "", false);
174
dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0));
177
if (my_errno == ENOENT)
178
my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db.c_str());
180
my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
190
if (current_entry == dirp->number_off_files)
197
file= dirp->dir_entry + current_entry;
199
if (my_strcasecmp(system_charset_info, ext=strchr(file->name,'.'), ARZ) ||
200
is_prefix(file->name, TMP_FILE_PREFIX))
204
file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
206
uname[file_name_len]= '\0';
208
if (wild && wild_compare(uname, wild, 0))
217
137
class ArchiveEngine : public drizzled::plugin::StorageEngine
220
140
ArchiveEngine(const string &name_arg)
221
141
: drizzled::plugin::StorageEngine(name_arg,
223
| HTON_HAS_DATA_DICTIONARY) {}
143
| HTON_HAS_DATA_DICTIONARY)
145
table_definition_ext= ARZ;
225
virtual handler *create(TableShare *table,
148
virtual Cursor *create(TableShare *table,
226
149
MEM_ROOT *mem_root)
228
151
return new (mem_root) ha_archive(this, table);
232
155
return ha_archive_exts;
235
int createTableImplementation(Session *session, const char *table_name,
236
Table *table_arg, HA_CREATE_INFO *create_info,
237
drizzled::message::Table* proto);
239
int getTableProtoImplementation(const char* path,
240
drizzled::message::Table *table_proto);
242
drizzled::plugin::TableNameIteratorImplementation* tableNameIterator(const std::string &database)
244
return new ArchiveTableNameIterator(database);
158
int doCreateTable(Session *session, const char *table_name,
159
Table& table_arg, HA_CREATE_INFO& create_info,
160
drizzled::message::Table& proto);
162
int doGetTableDefinition(Session& session,
165
const char *table_name,
167
drizzled::message::Table *table_proto);
169
void doGetTableNames(CachedDirectory &directory, string& , set<string>& set_of_names);
171
int doDropTable(Session&, const string table_path);
248
int ArchiveEngine::getTableProtoImplementation(const char* path,
249
drizzled::message::Table *table_proto)
175
void ArchiveEngine::doGetTableNames(CachedDirectory &directory,
177
set<string>& set_of_names)
179
CachedDirectory::Entries entries= directory.getEntries();
181
for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
182
entry_iter != entries.end(); ++entry_iter)
184
CachedDirectory::Entry *entry= *entry_iter;
185
string *filename= &entry->filename;
187
assert(filename->size());
189
const char *ext= strchr(filename->c_str(), '.');
191
if (ext == NULL || my_strcasecmp(system_charset_info, ext, ARZ) ||
192
is_prefix(filename->c_str(), TMP_FILE_PREFIX))
196
char uname[NAME_LEN + 1];
197
uint32_t file_name_len;
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);
208
int ArchiveEngine::doDropTable(Session&,
209
const string table_path)
212
char buff[FN_REFLEN];
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)))
218
if (my_errno != ENOENT)
227
int ArchiveEngine::doGetTableDefinition(Session&,
232
drizzled::message::Table *table_proto)
251
234
struct stat stat_info;
338
321
ha_archive::ha_archive(drizzled::plugin::StorageEngine *engine_arg,
339
322
TableShare *table_arg)
340
:handler(engine_arg, table_arg), delayed_insert(0), bulk_insert(0)
323
:Cursor(engine_arg, table_arg), delayed_insert(0), bulk_insert(0)
342
325
/* Set our original buffer from pre-allocated memory */
343
326
buffer.set((char *)byte_buffer, IO_SIZE, system_charset_info);
643
int ArchiveEngine::createTableImplementation(Session *,
644
const char *table_name,
646
HA_CREATE_INFO *create_info,
647
drizzled::message::Table *proto)
626
int ArchiveEngine::doCreateTable(Session *,
627
const char *table_name,
629
HA_CREATE_INFO& create_info,
630
drizzled::message::Table& proto)
649
632
char name_buff[FN_REFLEN];
652
635
uint64_t auto_increment_value;
653
636
string serialized_proto;
655
auto_increment_value= create_info->auto_increment_value;
638
auto_increment_value= create_info.auto_increment_value;
657
for (uint32_t key= 0; key < table_arg->sizeKeys(); key++)
640
for (uint32_t key= 0; key < table_arg.sizeKeys(); key++)
659
KEY *pos= table_arg->key_info+key;
642
KEY *pos= table_arg.key_info+key;
660
643
KEY_PART_INFO *key_part= pos->key_part;
661
644
KEY_PART_INFO *key_part_end= key_part + pos->key_parts;
689
proto->SerializeToString(&serialized_proto);
672
proto.SerializeToString(&serialized_proto);
691
674
if (azwrite_frm(&create_stream, serialized_proto.c_str(),
692
675
serialized_proto.length()))
695
if (proto->options().has_comment())
678
if (proto.options().has_comment())
697
680
int write_length;
699
682
write_length= azwrite_comment(&create_stream,
700
proto->options().comment().c_str(),
701
proto->options().comment().length());
683
proto.options().comment().c_str(),
684
proto.options().comment().length());
703
686
if (write_length < 0)