19
19
#include "config.h"
20
20
#include <drizzled/field.h>
21
21
#include <drizzled/field/blob.h>
22
#include <drizzled/field/timestamp.h>
22
23
#include <drizzled/error.h>
23
24
#include <drizzled/table.h>
24
25
#include <drizzled/session.h>
73
74
pthread_mutex_destroy(&filesystem_mutex);
76
virtual Cursor *create(Table &table)
77
virtual Cursor *create(TableShare &table)
78
79
return new FilesystemCursor(*this, table);
87
88
int doCreateTable(Session &,
89
const drizzled::identifier::Table &identifier,
90
const drizzled::TableIdentifier &identifier,
90
91
drizzled::message::Table&);
92
93
int doGetTableDefinition(Session& ,
93
const drizzled::identifier::Table &,
94
const drizzled::TableIdentifier &,
94
95
drizzled::message::Table &);
96
int doDropTable(Session&, const identifier::Table &);
97
int doDropTable(Session&, const TableIdentifier &);
98
99
/* operations on FilesystemTableShare */
99
100
FilesystemTableShare *findOpenTable(const string table_name);
103
104
uint32_t max_keys() const { return 0; }
104
105
uint32_t max_key_parts() const { return 0; }
105
106
uint32_t max_key_length() const { return 0; }
106
bool doDoesTableExist(Session& , const identifier::Table &);
107
int doRenameTable(Session&, const identifier::Table &, const identifier::Table &);
107
bool doDoesTableExist(Session& , const TableIdentifier &);
108
int doRenameTable(Session&, const TableIdentifier &, const TableIdentifier &);
108
109
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
109
const drizzled::identifier::Schema &schema_identifier,
110
drizzled::identifier::Table::vector &set_of_identifiers);
110
const drizzled::SchemaIdentifier &schema_identifier,
111
drizzled::TableIdentifiers &set_of_identifiers);
112
113
void getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
113
const drizzled::identifier::Schema &schema_identifier,
114
const drizzled::SchemaIdentifier &schema_identifier,
114
115
drizzled::plugin::TableNameList *set_of_names,
115
drizzled::identifier::Table::vector *set_of_identifiers);
116
drizzled::TableIdentifiers *set_of_identifiers);
118
119
void FilesystemEngine::getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
119
const drizzled::identifier::Schema &schema_identifier,
120
const drizzled::SchemaIdentifier &schema_identifier,
120
121
drizzled::plugin::TableNameList *set_of_names,
121
drizzled::identifier::Table::vector *set_of_identifiers)
122
drizzled::TableIdentifiers *set_of_identifiers)
123
124
drizzled::CachedDirectory::Entries entries= directory.getEntries();
140
141
char uname[NAME_LEN + 1];
141
142
uint32_t file_name_len;
143
file_name_len= identifier::Table::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
144
file_name_len= TableIdentifier::filename_to_tablename(filename->c_str(), uname, sizeof(uname));
144
145
uname[file_name_len - sizeof(FILESYSTEM_EXT) + 1]= '\0';
145
146
if (set_of_names)
146
147
set_of_names->insert(uname);
147
148
if (set_of_identifiers)
148
set_of_identifiers->push_back(identifier::Table(schema_identifier, uname));
149
set_of_identifiers->push_back(TableIdentifier(schema_identifier, uname));
153
154
void FilesystemEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
154
const drizzled::identifier::Schema &schema_identifier,
155
drizzled::identifier::Table::vector &set_of_identifiers)
155
const drizzled::SchemaIdentifier &schema_identifier,
156
drizzled::TableIdentifiers &set_of_identifiers)
157
158
getTableNamesFromFilesystem(directory, schema_identifier, NULL, &set_of_identifiers);
160
int FilesystemEngine::doDropTable(Session &, const identifier::Table &identifier)
161
int FilesystemEngine::doDropTable(Session &, const TableIdentifier &identifier)
162
163
string new_path(identifier.getPath());
163
164
new_path+= FILESYSTEM_EXT;
172
bool FilesystemEngine::doDoesTableExist(Session &, const identifier::Table &identifier)
173
bool FilesystemEngine::doDoesTableExist(Session &, const TableIdentifier &identifier)
174
175
string proto_path(identifier.getPath());
175
176
proto_path.append(FILESYSTEM_EXT);
283
284
int FilesystemEngine::doGetTableDefinition(Session &,
284
const drizzled::identifier::Table &identifier,
285
const drizzled::TableIdentifier &identifier,
285
286
drizzled::message::Table &table_proto)
287
288
string new_path(identifier.getPath());
304
305
if (not table_proto.IsInitialized())
306
307
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());
310
309
return ER_CORRUPT_TABLE_DEFINITION;
318
317
// then columns of this table are added dynamically here.
319
318
FormatInfo format;
320
319
format.parseFromTable(&table_proto);
321
if (not format.isTagFormat() || not format.isFileGiven())
320
if (!format.isTagFormat() || !format.isFileGiven()) {
327
std::vector< std::map<std::string, std::string> > vm;
328
if (parseTaggedFile(format, vm) != 0)
325
vector< map<string, string> > vm;
326
if (parseTaggedFile(format, vm) != 0) {
339
336
// we don't care what user provides, just clear them all
340
337
table_proto.clear_field();
341
338
// we take the first section as sample
342
std::map<string, string> kv= vm[0];
343
for (std::map<string, string>::iterator iter= kv.begin();
339
map<string, string> kv= vm[0];
340
for (map<string, string>::iterator iter= kv.begin();
344
341
iter != kv.end();
373
370
Guard g(filesystem_mutex);
375
FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
372
FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
376
373
share= a_engine->findOpenTable(table_name);
417
414
Guard g(filesystem_mutex);
419
416
if (!--share->use_count){
420
FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
417
FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
421
418
a_engine->deleteOpenTable(share->table_name);
422
419
pthread_mutex_destroy(&share->mutex);
456
453
thread_locked = false;
459
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, Table &table_arg)
456
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, TableShare &table_arg)
460
457
: Cursor(engine_arg, table_arg),
461
458
file_buff(new TransparentFile),
462
459
thread_locked(false)
466
int FilesystemCursor::doOpen(const drizzled::identifier::Table &identifier, int, uint32_t)
463
int FilesystemCursor::doOpen(const drizzled::TableIdentifier &identifier, int, uint32_t)
468
465
if (!(share= get_share(identifier.getPath().c_str())))
519
516
int FilesystemCursor::find_current_row(unsigned char *buf)
521
ptrdiff_t row_offset= buf - getTable()->record[0];
518
ptrdiff_t row_offset= buf - table->record[0];
523
520
next_position= current_position;
526
523
bool line_done= false;
527
524
bool line_blank= true;
528
Field **field= getTable()->getFields();
525
Field **field= table->getFields();
529
526
for (; !line_done && *field; ++next_position)
531
528
char ch= file_buff->get_value(next_position);
564
561
if ((*field)->isReadSet() || (*field)->isWriteSet())
566
563
(*field)->setWriteSet();
567
(*field)->store_and_check(CHECK_FIELD_WARN,
569
(uint32_t)content.length(),
564
(*field)->store(content.c_str(),
565
(uint32_t)content.length(),
574
570
(*field)->set_default();
578
573
(*field)->set_null();
621
616
if (tag_depth >= share->vm.size())
622
617
return HA_ERR_END_OF_FILE;
624
ptrdiff_t row_offset= buf - getTable()->record[0];
625
for (Field **field= getTable()->getFields(); *field; field++)
619
ptrdiff_t row_offset= buf - table->record[0];
620
for (Field **field= table->getFields(); *field; field++)
627
622
string key((*field)->field_name);
628
623
string content= share->vm[tag_depth][key];
634
629
if ((*field)->isReadSet() || (*field)->isWriteSet())
636
631
(*field)->setWriteSet();
637
(*field)->store_and_check(CHECK_FIELD_WARN,
639
(uint32_t)content.length(),
632
(*field)->store(content.c_str(),
633
(uint32_t)content.length(),
896
int FilesystemEngine::doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to)
891
int FilesystemEngine::doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to)
898
893
if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), FILESYSTEM_EXT))
909
904
int FilesystemEngine::doCreateTable(Session &,
911
const drizzled::identifier::Table &identifier,
912
drizzled::message::Table &proto)
906
const drizzled::TableIdentifier &identifier,
907
drizzled::message::Table &proto)
914
909
FormatInfo format;
915
910
format.parseFromTable(&proto);
956
951
"Filesystem Engine",
957
952
PLUGIN_LICENSE_GPL,
958
953
filesystem_init_func, /* Plugin Init */
954
NULL, /* system variables */
960
955
NULL /* config options */
962
957
DRIZZLE_DECLARE_PLUGIN_END;