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 |
56
HTON_HAS_DATA_DICTIONARY)
58
table_definition_ext= TABLEPROTOTESTER_EXT;
61
virtual Cursor *create(TableShare &table,
62
drizzled::memory::Root *mem_root)
64
return new (mem_root) TableProtoTesterCursor(*this, table);
67
const char **bas_ext() const {
68
return TableProtoTesterCursor_exts;
71
int doCreateTable(Session*,
74
drizzled::message::Table&);
76
int doDropTable(Session&, const string table_name);
78
int doGetTableDefinition(Session& session,
81
const char *table_name,
83
drizzled::message::Table *table_proto);
85
void doGetTableNames(drizzled::CachedDirectory &directory,
86
string&, set<string>& set_of_names)
89
set_of_names.insert("t1");
93
/* The following defines can be increased if necessary */
94
uint32_t max_supported_keys() const { return 64; }
95
uint32_t max_supported_key_length() const { return 1000; }
96
uint32_t max_supported_key_part_length() const { return 1000; }
98
uint32_t index_flags(enum ha_key_alg) const
100
return (HA_READ_NEXT |
109
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
110
TableShare &table_arg)
111
:Cursor(engine_arg, table_arg)
114
int TableProtoTesterCursor::open(const char *, int, uint32_t)
119
int TableProtoTesterCursor::close(void)
124
int TableProtoTesterEngine::doCreateTable(Session*, const char *,
126
drizzled::message::Table&)
132
int TableProtoTesterEngine::doDropTable(Session&, const string)
137
static void fill_table1(message::Table *table)
139
message::Table::Field *field;
140
message::Table::TableOptions *tableopts;
142
table->set_name("t1");
143
table->set_type(message::Table::INTERNAL);
145
tableopts= table->mutable_options();
146
tableopts->set_comment("Table without a StorageEngine message");
149
field= table->add_field();
150
field->set_name("number");
151
field->set_type(message::Table::Field::INTEGER);
155
int TableProtoTesterEngine::doGetTableDefinition(Session&,
160
drizzled::message::Table *table_proto)
162
if (strcmp(path, "./test/t1") == 0)
165
fill_table1(table_proto);
171
const char *TableProtoTesterCursor::index_type(uint32_t)
176
int TableProtoTesterCursor::write_row(unsigned char *)
178
return(table->next_number_field ? update_auto_increment() : 0);
181
int TableProtoTesterCursor::rnd_init(bool)
187
int TableProtoTesterCursor::rnd_next(unsigned char *)
189
return(HA_ERR_END_OF_FILE);
193
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
200
void TableProtoTesterCursor::position(const unsigned char *)
207
int TableProtoTesterCursor::info(uint32_t flag)
209
memset(&stats, 0, sizeof(stats));
210
if (flag & HA_STATUS_AUTO)
211
stats.auto_increment_value= 1;
216
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
217
key_part_map, enum ha_rkey_function)
219
return(HA_ERR_END_OF_FILE);
223
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
224
key_part_map, enum ha_rkey_function)
226
return(HA_ERR_END_OF_FILE);
230
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
232
return(HA_ERR_END_OF_FILE);
236
int TableProtoTesterCursor::index_next(unsigned char *)
238
return(HA_ERR_END_OF_FILE);
242
int TableProtoTesterCursor::index_prev(unsigned char *)
244
return(HA_ERR_END_OF_FILE);
248
int TableProtoTesterCursor::index_first(unsigned char *)
250
return(HA_ERR_END_OF_FILE);
254
int TableProtoTesterCursor::index_last(unsigned char *)
256
return(HA_ERR_END_OF_FILE);
259
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
261
static int tableprototester_init(drizzled::plugin::Registry ®istry)
264
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
265
registry.add(tableprototester_engine);
270
static int tableprototester_fini(drizzled::plugin::Registry ®istry)
272
registry.remove(tableprototester_engine);
273
delete tableprototester_engine;
278
DRIZZLE_DECLARE_PLUGIN
284
"Used to test rest of server with various table proto messages",
286
tableprototester_init, /* Plugin Init */
287
tableprototester_fini, /* Plugin Deinit */
288
NULL, /* status variables */
289
NULL, /* system variables */
290
NULL /* config options */
292
DRIZZLE_DECLARE_PLUGIN_END;