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,
61
drizzled::memory::Root *mem_root)
63
return new (mem_root) TableProtoTesterCursor(*this, table);
66
const char **bas_ext() const {
67
return TableProtoTesterCursor_exts;
70
int doCreateTable(Session&,
72
drizzled::TableIdentifier &identifier,
73
drizzled::message::Table&);
75
int doDropTable(Session&, drizzled::TableIdentifier &identifier);
77
int doGetTableDefinition(Session &session,
78
drizzled::TableIdentifier &identifier,
79
drizzled::message::Table &table_proto);
81
void doGetTableNames(drizzled::CachedDirectory &directory,
83
set<string>& set_of_names)
86
set_of_names.insert("t1");
90
/* The following defines can be increased if necessary */
91
uint32_t max_supported_keys() const { return 64; }
92
uint32_t max_supported_key_length() const { return 1000; }
93
uint32_t max_supported_key_part_length() const { return 1000; }
95
uint32_t index_flags(enum ha_key_alg) const
97
return (HA_READ_NEXT |
104
bool doDoesTableExist(Session &session, TableIdentifier &identifier);
106
int doRenameTable(Session&, TableIdentifier&, TableIdentifier&)
111
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
112
drizzled::SchemaIdentifier &schema_identifier,
113
drizzled::TableIdentifiers &set_of_identifiers);
116
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
117
drizzled::SchemaIdentifier &schema_identifier,
118
drizzled::TableIdentifiers &set_of_identifiers)
120
set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1"));
123
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
125
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
131
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
132
TableShare &table_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
drizzled::TableIdentifier&,
149
drizzled::message::Table&)
155
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&)
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);
178
int TableProtoTesterEngine::doGetTableDefinition(Session&,
179
drizzled::TableIdentifier &identifier,
180
drizzled::message::Table &table_proto)
182
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
184
fill_table1(table_proto);
190
const char *TableProtoTesterCursor::index_type(uint32_t)
195
int TableProtoTesterCursor::write_row(unsigned char *)
197
return(table->next_number_field ? update_auto_increment() : 0);
200
int TableProtoTesterCursor::rnd_init(bool)
206
int TableProtoTesterCursor::rnd_next(unsigned char *)
208
return(HA_ERR_END_OF_FILE);
212
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
219
void TableProtoTesterCursor::position(const unsigned char *)
226
int TableProtoTesterCursor::info(uint32_t flag)
228
memset(&stats, 0, sizeof(stats));
229
if (flag & HA_STATUS_AUTO)
230
stats.auto_increment_value= 1;
235
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
236
key_part_map, enum ha_rkey_function)
238
return(HA_ERR_END_OF_FILE);
242
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
243
key_part_map, enum ha_rkey_function)
245
return(HA_ERR_END_OF_FILE);
249
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
251
return(HA_ERR_END_OF_FILE);
255
int TableProtoTesterCursor::index_next(unsigned char *)
257
return(HA_ERR_END_OF_FILE);
261
int TableProtoTesterCursor::index_prev(unsigned char *)
263
return(HA_ERR_END_OF_FILE);
267
int TableProtoTesterCursor::index_first(unsigned char *)
269
return(HA_ERR_END_OF_FILE);
273
int TableProtoTesterCursor::index_last(unsigned char *)
275
return(HA_ERR_END_OF_FILE);
278
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
280
static int tableprototester_init(drizzled::plugin::Context &context)
283
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
284
context.add(tableprototester_engine);
289
DRIZZLE_DECLARE_PLUGIN
295
"Used to test rest of server with various table proto messages",
297
tableprototester_init, /* Plugin Init */
298
NULL, /* system variables */
299
NULL /* config options */
301
DRIZZLE_DECLARE_PLUGIN_END;