drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
tableprototester.cc
1/*
2 Copyright (C) 2010 Stewart Smith
3
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.
8
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.
13
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.
17*/
18
19#include <config.h>
20
21#include "tableprototester.h"
22
23#include <fcntl.h>
24
25#include <string>
26#include <map>
27#include <fstream>
28
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>
36
37
38using namespace std;
39using namespace google;
40using namespace drizzled;
41
42#define TABLEPROTOTESTER_EXT ".TBT"
43
44static const char *TableProtoTesterCursor_exts[] = {
45 NULL
46};
47
48class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
49{
50public:
51 TableProtoTesterEngine(const string &name_arg)
53 HTON_NULL_IN_KEY |
54 HTON_CAN_INDEX_BLOBS |
55 HTON_SKIP_STORE_LOCK |
56 HTON_AUTO_PART_KEY)
57 {
58 table_definition_ext= TABLEPROTOTESTER_EXT;
59 }
60
61 virtual Cursor *create(Table &table)
62 {
63 return new TableProtoTesterCursor(*this, table);
64 }
65
66 const char **bas_ext() const {
67 return TableProtoTesterCursor_exts;
68 }
69
70 int doCreateTable(Session&,
71 Table&,
72 const drizzled::identifier::Table &identifier,
73 const drizzled::message::Table&);
74
75 int doDropTable(Session&, const drizzled::identifier::Table &identifier);
76
77 int doGetTableDefinition(Session &session,
78 const drizzled::identifier::Table &identifier,
79 drizzled::message::Table &table_proto);
80
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; }
85
86 uint32_t index_flags(drizzled::message::Table::Index::IndexType) const
87 {
88 return (HA_READ_NEXT |
89 HA_READ_PREV |
90 HA_READ_RANGE |
91 HA_READ_ORDER |
92 HA_KEYREAD_ONLY);
93 }
94
95 bool doDoesTableExist(Session &session, const drizzled::identifier::Table &identifier);
96
97 int doRenameTable(Session&, const drizzled::identifier::Table&, const drizzled::identifier::Table&)
98 {
99 return HA_ERR_NO_SUCH_TABLE;
100 }
101
102 void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
103 const drizzled::identifier::Schema &schema_identifier,
104 drizzled::identifier::table::vector &set_of_identifiers);
105};
106
107void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
108 const drizzled::identifier::Schema &schema_identifier,
109 drizzled::identifier::table::vector &set_of_identifiers)
110{
111 if (schema_identifier.compare("test"))
112 {
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"));
117 }
118}
119
120bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::identifier::Table &identifier)
121{
122 if (not identifier.getPath().compare("local/test/t1"))
123 return true;
124 if (not identifier.getPath().compare("local/test/too_many_enum_values"))
125 return true;
126 if (not identifier.getPath().compare("local/test/invalid_table_collation"))
127 return true;
128 if (not identifier.getPath().compare("local/test/lsmtree"))
129 return true;
130
131 return false;
132}
133
134TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
135 Table &table_arg) :
136 Cursor(engine_arg, table_arg)
137{ }
138
139int TableProtoTesterCursor::open(const char *, int, uint32_t)
140{
141 return 0;
142}
143
144int TableProtoTesterCursor::close(void)
145{
146 return 0;
147}
148
149int TableProtoTesterEngine::doCreateTable(Session&,
150 Table&,
151 const drizzled::identifier::Table& identifier,
152 const drizzled::message::Table& create_proto)
153{
154 if (not identifier.getPath().compare("local/test/lsmtree_create"))
155 {
156 if (create_proto.indexes_size() < 1)
157 return -1;
158 if (create_proto.indexes(0).type() != message::Table::Index::LSMTREE)
159 return -2;
160
161 return 0;
162 }
163
164 return EEXIST;
165}
166
167
169{
170 return HA_ERR_NO_SUCH_TABLE;
171}
172
173static void fill_table1(message::Table &table)
174{
175 message::Table::Field *field;
176 message::Table::TableOptions *tableopts;
177
178 table.set_name("t1");
179 table.set_type(message::Table::INTERNAL);
180
181 tableopts= table.mutable_options();
182 tableopts->set_comment("Table without a StorageEngine message");
183
184 {
185 field= table.add_field();
186 field->set_name("number");
187 field->set_type(message::Table::Field::INTEGER);
188 }
189
190}
191
192static void fill_table_too_many_enum_values(message::Table &table)
193{
194 message::Table::Field *field;
195 message::Table::TableOptions *tableopts;
196
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);
203
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);
208
209 {
210 field= table.add_field();
211 field->set_name("many_values");
212 field->set_type(message::Table::Field::ENUM);
213
214 message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values();
215 for(int i=0; i<70000; i++)
216 {
217 char enum_value[100];
218 snprintf(enum_value, sizeof(enum_value), "a%d", i);
219 field_options->add_field_value(enum_value);
220 }
221 }
222
223}
224
225static void fill_table_invalid_table_collation(message::Table &table)
226{
227 message::Table::Field *field;
228 message::Table::TableOptions *tableopts;
229
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");
236
237 tableopts= table.mutable_options();
238 tableopts->set_comment("Invalid table collation ");
239
240 {
241 field= table.add_field();
242 field->set_name("number");
243 field->set_type(message::Table::Field::INTEGER);
244 }
245
246 tableopts->set_collation("pi_pi_pi");
247 tableopts->set_collation_id(123456);
248
249}
250
251static void fill_lsmtree(message::Table &table)
252{
253 message::Table::Field *field;
254 message::Table::TableOptions *tableopts;
255
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);
263
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);
268
269 {
270 field= table.add_field();
271 field->set_name("a");
272 field->set_type(message::Table::Field::INTEGER);
273 }
274 {
275 field= table.add_field();
276 field->set_name("b");
277 field->set_type(message::Table::Field::INTEGER);
278 }
279 {
280 field= table.add_field();
281 field->set_name("c");
282 field->set_type(message::Table::Field::INTEGER);
283 }
284
285 {
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));
295 }
296
297 {
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));
305 }
306
307}
308
309int TableProtoTesterEngine::doGetTableDefinition(Session&,
310 const drizzled::identifier::Table &identifier,
311 drizzled::message::Table &table_proto)
312{
313 if (not identifier.getPath().compare("local/test/t1"))
314 {
315 fill_table1(table_proto);
316 return EEXIST;
317 }
318 else if (not identifier.getPath().compare("local/test/too_many_enum_values"))
319 {
320 fill_table_too_many_enum_values(table_proto);
321 return EEXIST;
322 }
323 else if (not identifier.getPath().compare("local/test/invalid_table_collation"))
324 {
325 fill_table_invalid_table_collation(table_proto);
326 return EEXIST;
327 }
328 else if (not identifier.getPath().compare("local/test/lsmtree"))
329 {
330 fill_lsmtree(table_proto);
331 return EEXIST;
332 }
333 return ENOENT;
334}
335
336const char *TableProtoTesterCursor::index_type(uint32_t idx)
337{
338 if (strcmp(getShare()->getTableName(), "lsmtree") == 0)
339 {
340 if (idx == 1)
341 return "LSMTREE";
342 }
343
344 return("BTREE");
345}
346
347int TableProtoTesterCursor::doInsertRecord(unsigned char *)
348{
349 return(getTable()->next_number_field ? update_auto_increment() : 0);
350}
351
353{
354 return(0);
355}
356
357
358int TableProtoTesterCursor::rnd_next(unsigned char *)
359{
360 return(HA_ERR_END_OF_FILE);
361}
362
363
364int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
365{
366 assert(0);
367 return(0);
368}
369
370
371void TableProtoTesterCursor::position(const unsigned char *)
372{
373 assert(0);
374 return;
375}
376
377
378int TableProtoTesterCursor::info(uint32_t flag)
379{
380 stats= drizzled::ha_statistics();
381 if (flag & HA_STATUS_AUTO)
382 stats.auto_increment_value= 1;
383 return(0);
384}
385
386
387int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
388 key_part_map, enum ha_rkey_function)
389{
390 return(HA_ERR_END_OF_FILE);
391}
392
393
394int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
395 key_part_map, enum ha_rkey_function)
396{
397 return(HA_ERR_END_OF_FILE);
398}
399
400
401int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
402{
403 return(HA_ERR_END_OF_FILE);
404}
405
406
407int TableProtoTesterCursor::index_next(unsigned char *)
408{
409 return(HA_ERR_END_OF_FILE);
410}
411
412
413int TableProtoTesterCursor::index_prev(unsigned char *)
414{
415 return(HA_ERR_END_OF_FILE);
416}
417
418
419int TableProtoTesterCursor::index_first(unsigned char *)
420{
421 return(HA_ERR_END_OF_FILE);
422}
423
424
425int TableProtoTesterCursor::index_last(unsigned char *)
426{
427 return(HA_ERR_END_OF_FILE);
428}
429
430static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
431
432static int tableprototester_init(drizzled::module::Context &context)
433{
434
435 tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
436 context.add(tableprototester_engine);
437
438 return 0;
439}
440
441DRIZZLE_DECLARE_PLUGIN
442{
443 DRIZZLE_VERSION_ID,
444 "TABLEPROTOTESTER",
445 "1.0",
446 "Stewart Smith",
447 N_("StorageEngine module for testing table proto messages"),
448 PLUGIN_LICENSE_GPL,
449 tableprototester_init,
450 NULL,
451 NULL
452}
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.
STL namespace.