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>
88
87
int doCreateTable(Session &,
90
const drizzled::TableIdentifier &identifier,
89
const drizzled::identifier::Table &identifier,
91
90
drizzled::message::Table&);
93
92
int doGetTableDefinition(Session& ,
94
const drizzled::TableIdentifier &,
93
const drizzled::identifier::Table &,
95
94
drizzled::message::Table &);
97
int doDropTable(Session&, const TableIdentifier &);
96
int doDropTable(Session&, const identifier::Table &);
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);
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);
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)
124
123
drizzled::CachedDirectory::Entries entries= directory.getEntries();
141
140
char uname[NAME_LEN + 1];
142
141
uint32_t file_name_len;
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));
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)
158
157
getTableNamesFromFilesystem(directory, schema_identifier, NULL, &set_of_identifiers);
161
int FilesystemEngine::doDropTable(Session &, const TableIdentifier &identifier)
160
int FilesystemEngine::doDropTable(Session &, const identifier::Table &identifier)
163
162
string new_path(identifier.getPath());
164
163
new_path+= FILESYSTEM_EXT;
173
bool FilesystemEngine::doDoesTableExist(Session &, const TableIdentifier &identifier)
172
bool FilesystemEngine::doDoesTableExist(Session &, const identifier::Table &identifier)
175
174
string proto_path(identifier.getPath());
176
175
proto_path.append(FILESYSTEM_EXT);
284
283
int FilesystemEngine::doGetTableDefinition(Session &,
285
const drizzled::TableIdentifier &identifier,
284
const drizzled::identifier::Table &identifier,
286
285
drizzled::message::Table &table_proto)
288
287
string new_path(identifier.getPath());
305
304
if (not table_proto.IsInitialized())
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
310
return ER_CORRUPT_TABLE_DEFINITION;
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())
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)
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();
463
int FilesystemCursor::doOpen(const drizzled::TableIdentifier &identifier, int, uint32_t)
466
int FilesystemCursor::doOpen(const drizzled::identifier::Table &identifier, int, uint32_t)
465
468
if (!(share= get_share(identifier.getPath().c_str())))
561
564
if ((*field)->isReadSet() || (*field)->isWriteSet())
563
566
(*field)->setWriteSet();
564
(*field)->store(content.c_str(),
565
(uint32_t)content.length(),
567
(*field)->store_and_check(CHECK_FIELD_WARN,
569
(uint32_t)content.length(),
570
574
(*field)->set_default();
573
578
(*field)->set_null();
629
634
if ((*field)->isReadSet() || (*field)->isWriteSet())
631
636
(*field)->setWriteSet();
632
(*field)->store(content.c_str(),
633
(uint32_t)content.length(),
637
(*field)->store_and_check(CHECK_FIELD_WARN,
639
(uint32_t)content.length(),
891
int FilesystemEngine::doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to)
896
int FilesystemEngine::doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to)
893
898
if (rename_file_ext(from.getPath().c_str(), to.getPath().c_str(), FILESYSTEM_EXT))
904
909
int FilesystemEngine::doCreateTable(Session &,
906
const drizzled::TableIdentifier &identifier,
907
drizzled::message::Table &proto)
911
const drizzled::identifier::Table &identifier,
912
drizzled::message::Table &proto)
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 */
955
960
NULL /* config options */
957
962
DRIZZLE_DECLARE_PLUGIN_END;