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.
21
#include "tableprototester.h"
29
#include <drizzled/error.h>
30
#include <drizzled/global_charset_info.h>
31
#include <drizzled/internal/m_string.h>
32
#include <drizzled/internal/my_pthread.h>
33
#include <drizzled/message/table.h>
34
#include <drizzled/plugin/storage_engine.h>
35
#include <drizzled/table.h>
39
using namespace google;
40
using namespace drizzled;
42
#define TABLEPROTOTESTER_EXT ".TBT"
44
static const char *TableProtoTesterCursor_exts[] = {
48
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
51
TableProtoTesterEngine(const string &name_arg)
52
: drizzled::plugin::StorageEngine(name_arg,
54
HTON_CAN_INDEX_BLOBS |
55
HTON_SKIP_STORE_LOCK |
58
table_definition_ext= TABLEPROTOTESTER_EXT;
61
virtual Cursor *create(Table &table)
63
return new TableProtoTesterCursor(*this, table);
66
const char **bas_ext() const {
67
return TableProtoTesterCursor_exts;
70
int doCreateTable(Session&,
72
const drizzled::identifier::Table &identifier,
73
drizzled::message::Table&);
75
int doDropTable(Session&, const drizzled::identifier::Table &identifier);
77
int doGetTableDefinition(Session &session,
78
const drizzled::identifier::Table &identifier,
79
drizzled::message::Table &table_proto);
81
/* The following defines can be increased if necessary */
82
uint32_t max_supported_keys() const { return 64; }
83
uint32_t max_supported_key_length() const { return 1000; }
84
uint32_t max_supported_key_part_length() const { return 1000; }
86
uint32_t index_flags(enum ha_key_alg) const
88
return (HA_READ_NEXT |
95
bool doDoesTableExist(Session &session, const drizzled::identifier::Table &identifier);
97
int doRenameTable(Session&, const drizzled::identifier::Table&, const drizzled::identifier::Table&)
99
return HA_ERR_NO_SUCH_TABLE;
102
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
103
const drizzled::identifier::Schema &schema_identifier,
104
drizzled::identifier::Table::vector &set_of_identifiers);
107
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
108
const drizzled::identifier::Schema &schema_identifier,
109
drizzled::identifier::Table::vector &set_of_identifiers)
111
if (schema_identifier.compare("test"))
113
set_of_identifiers.push_back(identifier::Table(schema_identifier, "t1"));
114
set_of_identifiers.push_back(identifier::Table(schema_identifier, "too_many_enum_values"));
115
set_of_identifiers.push_back(identifier::Table(schema_identifier, "invalid_table_collation"));
119
bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::identifier::Table &identifier)
121
if (not identifier.getPath().compare("test/t1"))
123
if (not identifier.getPath().compare("test/too_many_enum_values"))
125
if (not identifier.getPath().compare("test/invalid_table_collation"))
131
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
133
Cursor(engine_arg, table_arg)
136
int TableProtoTesterCursor::open(const char *, int, uint32_t)
141
int TableProtoTesterCursor::close(void)
146
int TableProtoTesterEngine::doCreateTable(Session&,
148
const drizzled::identifier::Table&,
149
drizzled::message::Table&)
155
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::identifier::Table&)
157
return HA_ERR_NO_SUCH_TABLE;
160
static void fill_table1(message::Table &table)
162
message::Table::Field *field;
163
message::Table::TableOptions *tableopts;
165
table.set_name("t1");
166
table.set_type(message::Table::INTERNAL);
168
tableopts= table.mutable_options();
169
tableopts->set_comment("Table without a StorageEngine message");
172
field= table.add_field();
173
field->set_name("number");
174
field->set_type(message::Table::Field::INTEGER);
179
static void fill_table_too_many_enum_values(message::Table &table)
181
message::Table::Field *field;
182
message::Table::TableOptions *tableopts;
184
table.set_schema("test");
185
table.set_name("too_many_enum_values");
186
table.set_type(message::Table::STANDARD);
187
table.mutable_engine()->set_name("tableprototester");
188
table.set_creation_timestamp(0);
189
table.set_update_timestamp(0);
191
tableopts= table.mutable_options();
192
tableopts->set_comment("Table with too many enum options");
193
tableopts->set_collation("utf8_general_ci");
194
tableopts->set_collation_id(45);
197
field= table.add_field();
198
field->set_name("many_values");
199
field->set_type(message::Table::Field::ENUM);
201
message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values();
202
for(int i=0; i<70000; i++)
204
char enum_value[100];
205
snprintf(enum_value, sizeof(enum_value), "a%d", i);
206
field_options->add_field_value(enum_value);
212
static void fill_table_invalid_table_collation(message::Table &table)
214
message::Table::Field *field;
215
message::Table::TableOptions *tableopts;
217
table.set_name("invalid_table_collation");
218
table.set_type(message::Table::STANDARD);
219
table.set_schema("test");
220
table.set_creation_timestamp(0);
221
table.set_update_timestamp(0);
222
table.mutable_engine()->set_name("tableprototester");
224
tableopts= table.mutable_options();
225
tableopts->set_comment("Invalid table collation ");
228
field= table.add_field();
229
field->set_name("number");
230
field->set_type(message::Table::Field::INTEGER);
233
tableopts->set_collation("pi_pi_pi");
234
tableopts->set_collation_id(123456);
238
int TableProtoTesterEngine::doGetTableDefinition(Session&,
239
const drizzled::identifier::Table &identifier,
240
drizzled::message::Table &table_proto)
242
if (not identifier.getPath().compare("test/t1"))
244
fill_table1(table_proto);
247
else if (not identifier.getPath().compare("test/too_many_enum_values"))
249
fill_table_too_many_enum_values(table_proto);
252
else if (not identifier.getPath().compare("test/invalid_table_collation"))
254
fill_table_invalid_table_collation(table_proto);
260
const char *TableProtoTesterCursor::index_type(uint32_t)
265
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
267
return(getTable()->next_number_field ? update_auto_increment() : 0);
270
int TableProtoTesterCursor::doStartTableScan(bool)
276
int TableProtoTesterCursor::rnd_next(unsigned char *)
278
return(HA_ERR_END_OF_FILE);
282
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
289
void TableProtoTesterCursor::position(const unsigned char *)
296
int TableProtoTesterCursor::info(uint32_t flag)
298
memset(&stats, 0, sizeof(stats));
299
if (flag & HA_STATUS_AUTO)
300
stats.auto_increment_value= 1;
305
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
306
key_part_map, enum ha_rkey_function)
308
return(HA_ERR_END_OF_FILE);
312
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
313
key_part_map, enum ha_rkey_function)
315
return(HA_ERR_END_OF_FILE);
319
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
321
return(HA_ERR_END_OF_FILE);
325
int TableProtoTesterCursor::index_next(unsigned char *)
327
return(HA_ERR_END_OF_FILE);
331
int TableProtoTesterCursor::index_prev(unsigned char *)
333
return(HA_ERR_END_OF_FILE);
337
int TableProtoTesterCursor::index_first(unsigned char *)
339
return(HA_ERR_END_OF_FILE);
343
int TableProtoTesterCursor::index_last(unsigned char *)
345
return(HA_ERR_END_OF_FILE);
348
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
350
static int tableprototester_init(drizzled::module::Context &context)
353
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
354
context.add(tableprototester_engine);
359
DRIZZLE_DECLARE_PLUGIN
365
"Used to test rest of server with various table proto messages",
367
tableprototester_init, /* Plugin Init */
369
NULL /* config options */
371
DRIZZLE_DECLARE_PLUGIN_END;