21#include "tableprototester.h"
29#include <drizzled/error.h>
30#include <drizzled/charset.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>
39using namespace google;
42#define TABLEPROTOTESTER_EXT ".TBT"
44static const char *TableProtoTesterCursor_exts[] = {
51 TableProtoTesterEngine(
const string &name_arg)
54 HTON_CAN_INDEX_BLOBS |
55 HTON_SKIP_STORE_LOCK |
58 table_definition_ext= TABLEPROTOTESTER_EXT;
67 return TableProtoTesterCursor_exts;
73 const drizzled::message::Table&);
77 int doGetTableDefinition(
Session &session,
79 drizzled::message::Table &table_proto);
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(drizzled::message::Table::Index::IndexType)
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);
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"));
116 set_of_identifiers.push_back(identifier::Table(schema_identifier,
"lsmtree"));
122 if (not identifier.getPath().compare(
"local/test/t1"))
124 if (not identifier.getPath().compare(
"local/test/too_many_enum_values"))
126 if (not identifier.getPath().compare(
"local/test/invalid_table_collation"))
128 if (not identifier.getPath().compare(
"local/test/lsmtree"))
136 Cursor(engine_arg, table_arg)
139int TableProtoTesterCursor::open(
const char *,
int, uint32_t)
144int TableProtoTesterCursor::close(
void)
149int TableProtoTesterEngine::doCreateTable(
Session&,
152 const drizzled::message::Table& create_proto)
154 if (not identifier.getPath().compare(
"local/test/lsmtree_create"))
156 if (create_proto.indexes_size() < 1)
158 if (create_proto.indexes(0).type() != message::Table::Index::LSMTREE)
170 return HA_ERR_NO_SUCH_TABLE;
173static void fill_table1(message::Table &table)
175 message::Table::Field *field;
176 message::Table::TableOptions *tableopts;
178 table.set_name(
"t1");
179 table.set_type(message::Table::INTERNAL);
181 tableopts= table.mutable_options();
182 tableopts->set_comment(
"Table without a StorageEngine message");
185 field= table.add_field();
186 field->set_name(
"number");
187 field->set_type(message::Table::Field::INTEGER);
192static void fill_table_too_many_enum_values(message::Table &table)
194 message::Table::Field *field;
195 message::Table::TableOptions *tableopts;
197 table.set_schema(
"test");
198 table.set_name(
"too_many_enum_values");
199 table.set_type(message::Table::STANDARD);
200 table.mutable_engine()->set_name(
"tableprototester");
201 table.set_creation_timestamp(0);
202 table.set_update_timestamp(0);
204 tableopts= table.mutable_options();
205 tableopts->set_comment(
"Table with too many enum options");
206 tableopts->set_collation(
"utf8_general_ci");
207 tableopts->set_collation_id(45);
210 field= table.add_field();
211 field->set_name(
"many_values");
212 field->set_type(message::Table::Field::ENUM);
214 message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values();
215 for(
int i=0; i<70000; i++)
217 char enum_value[100];
218 snprintf(enum_value,
sizeof(enum_value),
"a%d", i);
219 field_options->add_field_value(enum_value);
225static void fill_table_invalid_table_collation(message::Table &table)
227 message::Table::Field *field;
228 message::Table::TableOptions *tableopts;
230 table.set_name(
"invalid_table_collation");
231 table.set_type(message::Table::STANDARD);
232 table.set_schema(
"test");
233 table.set_creation_timestamp(0);
234 table.set_update_timestamp(0);
235 table.mutable_engine()->set_name(
"tableprototester");
237 tableopts= table.mutable_options();
238 tableopts->set_comment(
"Invalid table collation ");
241 field= table.add_field();
242 field->set_name(
"number");
243 field->set_type(message::Table::Field::INTEGER);
246 tableopts->set_collation(
"pi_pi_pi");
247 tableopts->set_collation_id(123456);
251static void fill_lsmtree(message::Table &table)
253 message::Table::Field *field;
254 message::Table::TableOptions *tableopts;
256 table.set_name(
"lsmtree");
257 table.set_schema(
"test");
258 table.set_type(message::Table::STANDARD);
259 message::Engine *engine= table.mutable_engine();
260 engine->set_name(
"TABLEPROTOTESTER");
261 table.set_creation_timestamp(0);
262 table.set_update_timestamp(0);
264 tableopts= table.mutable_options();
265 tableopts->set_comment(
"LSM Tree test");
266 tableopts->set_collation_id(my_charset_bin.number);
267 tableopts->set_collation(my_charset_bin.name);
270 field= table.add_field();
271 field->set_name(
"a");
272 field->set_type(message::Table::Field::INTEGER);
275 field= table.add_field();
276 field->set_name(
"b");
277 field->set_type(message::Table::Field::INTEGER);
280 field= table.add_field();
281 field->set_name(
"c");
282 field->set_type(message::Table::Field::INTEGER);
286 message::Table::Index *index= table.add_indexes();
287 index->set_name(
"PRIMARY");
288 index->set_is_primary(
true);
289 index->set_is_unique(
true);
290 index->set_type(message::Table::Index::BTREE);
291 index->set_key_length(
sizeof(uint32_t));
292 message::Table::Index::IndexPart *part= index->add_index_part();
293 part->set_fieldnr(0);
294 part->set_compare_length(
sizeof(uint32_t));
298 message::Table::Index *index= table.add_indexes();
299 index->set_name(
"mylsm");
300 index->set_type(message::Table::Index::LSMTREE);
301 index->set_key_length(
sizeof(uint32_t));
302 message::Table::Index::IndexPart *part= index->add_index_part();
303 part->set_fieldnr(1);
304 part->set_compare_length(
sizeof(uint32_t));
309int TableProtoTesterEngine::doGetTableDefinition(
Session&,
311 drizzled::message::Table &table_proto)
313 if (not identifier.getPath().compare(
"local/test/t1"))
315 fill_table1(table_proto);
318 else if (not identifier.getPath().compare(
"local/test/too_many_enum_values"))
320 fill_table_too_many_enum_values(table_proto);
323 else if (not identifier.getPath().compare(
"local/test/invalid_table_collation"))
325 fill_table_invalid_table_collation(table_proto);
328 else if (not identifier.getPath().compare(
"local/test/lsmtree"))
330 fill_lsmtree(table_proto);
336const char *TableProtoTesterCursor::index_type(uint32_t idx)
338 if (strcmp(getShare()->getTableName(),
"lsmtree") == 0)
347int TableProtoTesterCursor::doInsertRecord(
unsigned char *)
349 return(getTable()->next_number_field ? update_auto_increment() : 0);
358int TableProtoTesterCursor::rnd_next(
unsigned char *)
360 return(HA_ERR_END_OF_FILE);
364int TableProtoTesterCursor::rnd_pos(
unsigned char *,
unsigned char *)
371void TableProtoTesterCursor::position(
const unsigned char *)
378int TableProtoTesterCursor::info(uint32_t flag)
380 stats= drizzled::ha_statistics();
381 if (flag & HA_STATUS_AUTO)
382 stats.auto_increment_value= 1;
388 key_part_map,
enum ha_rkey_function)
390 return(HA_ERR_END_OF_FILE);
395 key_part_map,
enum ha_rkey_function)
397 return(HA_ERR_END_OF_FILE);
403 return(HA_ERR_END_OF_FILE);
407int TableProtoTesterCursor::index_next(
unsigned char *)
409 return(HA_ERR_END_OF_FILE);
413int TableProtoTesterCursor::index_prev(
unsigned char *)
415 return(HA_ERR_END_OF_FILE);
419int TableProtoTesterCursor::index_first(
unsigned char *)
421 return(HA_ERR_END_OF_FILE);
425int TableProtoTesterCursor::index_last(
unsigned char *)
427 return(HA_ERR_END_OF_FILE);
436 context.add(tableprototester_engine);
441DRIZZLE_DECLARE_PLUGIN
447 N_(
"StorageEngine module for testing table proto messages"),
449 tableprototester_init,
453DRIZZLE_DECLARE_PLUGIN_END;
int index_read_idx_map(unsigned char *buf, uint32_t idx, const unsigned char *key, drizzled::key_part_map keypart_map, drizzled::ha_rkey_function find_flag)
Positions an index cursor to the index specified in the handle. Fetches the row if available....
int index_read_last_map(unsigned char *buf, const unsigned char *key, drizzled::key_part_map keypart_map)
The following functions works like index_read, but it find the last row with the current key value or...
int index_read_map(unsigned char *buf, const unsigned char *key, drizzled::key_part_map keypart_map, drizzled::ha_rkey_function find_flag)
Positions an index cursor to the index specified in the handle. Fetches the row if available....
int doStartTableScan(bool scan)
int doDropTable(Session &, const drizzled::identifier::Table &identifier)
const char ** bas_ext() const
TODO: Rename this file - func.h is stupid.