2
Copyright (C) 2010 Stewart Smith
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include <drizzled/table.h>
21
#include <drizzled/error.h>
22
#include "drizzled/internal/my_pthread.h"
24
#include "tableprototester.h"
31
#include <drizzled/message/table.pb.h>
32
#include "drizzled/internal/m_string.h"
34
#include "drizzled/global_charset_info.h"
38
using namespace google;
39
using namespace drizzled;
41
#define TABLEPROTOTESTER_EXT ".TBT"
43
static const char *TableProtoTesterCursor_exts[] = {
47
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
50
TableProtoTesterEngine(const string &name_arg)
51
: drizzled::plugin::StorageEngine(name_arg,
53
HTON_CAN_INDEX_BLOBS |
54
HTON_SKIP_STORE_LOCK |
57
table_definition_ext= TABLEPROTOTESTER_EXT;
60
virtual Cursor *create(TableShare &table)
62
return new TableProtoTesterCursor(*this, table);
65
const char **bas_ext() const {
66
return TableProtoTesterCursor_exts;
69
int doCreateTable(Session&,
71
const drizzled::TableIdentifier &identifier,
72
drizzled::message::Table&);
74
int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
76
int doGetTableDefinition(Session &session,
77
const drizzled::TableIdentifier &identifier,
78
drizzled::message::Table &table_proto);
80
/* The following defines can be increased if necessary */
81
uint32_t max_supported_keys() const { return 64; }
82
uint32_t max_supported_key_length() const { return 1000; }
83
uint32_t max_supported_key_part_length() const { return 1000; }
85
uint32_t index_flags(enum ha_key_alg) const
87
return (HA_READ_NEXT |
94
bool doDoesTableExist(Session &session, const drizzled::TableIdentifier &identifier);
96
int doRenameTable(Session&, const drizzled::TableIdentifier&, const drizzled::TableIdentifier&)
101
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
102
const drizzled::SchemaIdentifier &schema_identifier,
103
drizzled::TableIdentifiers &set_of_identifiers);
106
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
107
const drizzled::SchemaIdentifier &schema_identifier,
108
drizzled::TableIdentifiers &set_of_identifiers)
110
if (schema_identifier.compare("test"))
112
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1"));
113
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "too_many_enum_values"));
114
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "invalid_table_collation"));
118
bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier &identifier)
120
if (not identifier.getPath().compare("test/t1"))
122
if (not identifier.getPath().compare("test/too_many_enum_values"))
124
if (not identifier.getPath().compare("test/invalid_table_collation"))
130
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
131
TableShare &table_arg) :
132
Cursor(engine_arg, table_arg)
135
int TableProtoTesterCursor::open(const char *, int, uint32_t)
140
int TableProtoTesterCursor::close(void)
145
int TableProtoTesterEngine::doCreateTable(Session&,
147
const drizzled::TableIdentifier&,
148
drizzled::message::Table&)
154
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::TableIdentifier&)
159
static void fill_table1(message::Table &table)
161
message::Table::Field *field;
162
message::Table::TableOptions *tableopts;
164
table.set_name("t1");
165
table.set_type(message::Table::INTERNAL);
167
tableopts= table.mutable_options();
168
tableopts->set_comment("Table without a StorageEngine message");
171
field= table.add_field();
172
field->set_name("number");
173
field->set_type(message::Table::Field::INTEGER);
178
static void fill_table_too_many_enum_values(message::Table &table)
180
message::Table::Field *field;
181
message::Table::TableOptions *tableopts;
183
table.set_schema("test");
184
table.set_name("too_many_enum_values");
185
table.set_type(message::Table::STANDARD);
186
table.mutable_engine()->set_name("tableprototester");
187
table.set_creation_timestamp(0);
188
table.set_update_timestamp(0);
190
tableopts= table.mutable_options();
191
tableopts->set_comment("Table with too many enum options");
192
tableopts->set_collation("utf8_general_ci");
193
tableopts->set_collation_id(45);
196
field= table.add_field();
197
field->set_name("many_values");
198
field->set_type(message::Table::Field::ENUM);
200
message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values();
201
for(int i=0; i<70000; i++)
203
char enum_value[100];
204
snprintf(enum_value, sizeof(enum_value), "a%d", i);
205
field_options->add_field_value(enum_value);
211
static void fill_table_invalid_table_collation(message::Table &table)
213
message::Table::Field *field;
214
message::Table::TableOptions *tableopts;
216
table.set_name("invalid_table_collation");
217
table.set_type(message::Table::STANDARD);
218
table.set_schema("test");
219
table.set_creation_timestamp(0);
220
table.set_update_timestamp(0);
221
table.mutable_engine()->set_name("tableprototester");
223
tableopts= table.mutable_options();
224
tableopts->set_comment("Invalid table collation ");
227
field= table.add_field();
228
field->set_name("number");
229
field->set_type(message::Table::Field::INTEGER);
232
tableopts->set_collation("pi_pi_pi");
233
tableopts->set_collation_id(123456);
237
int TableProtoTesterEngine::doGetTableDefinition(Session&,
238
const drizzled::TableIdentifier &identifier,
239
drizzled::message::Table &table_proto)
241
if (not identifier.getPath().compare("test/t1"))
243
fill_table1(table_proto);
246
else if (not identifier.getPath().compare("test/too_many_enum_values"))
248
fill_table_too_many_enum_values(table_proto);
251
else if (not identifier.getPath().compare("test/invalid_table_collation"))
253
fill_table_invalid_table_collation(table_proto);
259
const char *TableProtoTesterCursor::index_type(uint32_t)
264
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
266
return(table->next_number_field ? update_auto_increment() : 0);
269
int TableProtoTesterCursor::doStartTableScan(bool)
275
int TableProtoTesterCursor::rnd_next(unsigned char *)
277
return(HA_ERR_END_OF_FILE);
281
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
288
void TableProtoTesterCursor::position(const unsigned char *)
295
int TableProtoTesterCursor::info(uint32_t flag)
297
memset(&stats, 0, sizeof(stats));
298
if (flag & HA_STATUS_AUTO)
299
stats.auto_increment_value= 1;
304
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
305
key_part_map, enum ha_rkey_function)
307
return(HA_ERR_END_OF_FILE);
311
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
312
key_part_map, enum ha_rkey_function)
314
return(HA_ERR_END_OF_FILE);
318
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
320
return(HA_ERR_END_OF_FILE);
324
int TableProtoTesterCursor::index_next(unsigned char *)
326
return(HA_ERR_END_OF_FILE);
330
int TableProtoTesterCursor::index_prev(unsigned char *)
332
return(HA_ERR_END_OF_FILE);
336
int TableProtoTesterCursor::index_first(unsigned char *)
338
return(HA_ERR_END_OF_FILE);
342
int TableProtoTesterCursor::index_last(unsigned char *)
344
return(HA_ERR_END_OF_FILE);
347
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
349
static int tableprototester_init(drizzled::module::Context &context)
352
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
353
context.add(tableprototester_engine);
358
DRIZZLE_DECLARE_PLUGIN
364
"Used to test rest of server with various table proto messages",
366
tableprototester_init, /* Plugin Init */
367
NULL, /* system variables */
368
NULL /* config options */
370
DRIZZLE_DECLARE_PLUGIN_END;