1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
/*
Copyright (C) 2010 Stewart Smith
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <drizzled/table.h>
#include <drizzled/error.h>
#include "drizzled/internal/my_pthread.h"
#include "tableprototester.h"
#include <fcntl.h>
#include <string>
#include <map>
#include <fstream>
#include <drizzled/message/table.pb.h>
#include "drizzled/internal/m_string.h"
#include "drizzled/global_charset_info.h"
using namespace std;
using namespace google;
using namespace drizzled;
#define TABLEPROTOTESTER_EXT ".TBT"
static const char *TableProtoTesterCursor_exts[] = {
NULL
};
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
{
public:
TableProtoTesterEngine(const string &name_arg)
: drizzled::plugin::StorageEngine(name_arg,
HTON_NULL_IN_KEY |
HTON_CAN_INDEX_BLOBS |
HTON_SKIP_STORE_LOCK |
HTON_AUTO_PART_KEY)
{
table_definition_ext= TABLEPROTOTESTER_EXT;
}
virtual Cursor *create(TableShare &table,
drizzled::memory::Root *mem_root)
{
return new (mem_root) TableProtoTesterCursor(*this, table);
}
const char **bas_ext() const {
return TableProtoTesterCursor_exts;
}
int doCreateTable(Session&,
Table&,
drizzled::TableIdentifier &identifier,
drizzled::message::Table&);
int doDropTable(Session&, drizzled::TableIdentifier &identifier);
int doGetTableDefinition(Session &session,
drizzled::TableIdentifier &identifier,
drizzled::message::Table &table_proto);
void doGetTableNames(drizzled::CachedDirectory &directory,
SchemaIdentifier &,
set<string>& set_of_names)
{
(void)directory;
set_of_names.insert("t1");
}
/* The following defines can be increased if necessary */
uint32_t max_supported_keys() const { return 64; }
uint32_t max_supported_key_length() const { return 1000; }
uint32_t max_supported_key_part_length() const { return 1000; }
uint32_t index_flags(enum ha_key_alg) const
{
return (HA_READ_NEXT |
HA_READ_PREV |
HA_READ_RANGE |
HA_READ_ORDER |
HA_KEYREAD_ONLY);
}
bool doDoesTableExist(Session &session, TableIdentifier &identifier);
int doRenameTable(Session&, TableIdentifier&, TableIdentifier&)
{
return EPERM;
}
};
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
{
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
return true;
return false;
}
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
TableShare &table_arg) :
Cursor(engine_arg, table_arg)
{ }
int TableProtoTesterCursor::open(const char *, int, uint32_t)
{
return 0;
}
int TableProtoTesterCursor::close(void)
{
return 0;
}
int TableProtoTesterEngine::doCreateTable(Session&,
Table&,
drizzled::TableIdentifier&,
drizzled::message::Table&)
{
return EEXIST;
}
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&)
{
return EPERM;
}
static void fill_table1(message::Table &table)
{
message::Table::Field *field;
message::Table::TableOptions *tableopts;
table.set_name("t1");
table.set_type(message::Table::INTERNAL);
tableopts= table.mutable_options();
tableopts->set_comment("Table without a StorageEngine message");
{
field= table.add_field();
field->set_name("number");
field->set_type(message::Table::Field::INTEGER);
}
}
int TableProtoTesterEngine::doGetTableDefinition(Session&,
drizzled::TableIdentifier &identifier,
drizzled::message::Table &table_proto)
{
if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
{
fill_table1(table_proto);
return EEXIST;
}
return ENOENT;
}
const char *TableProtoTesterCursor::index_type(uint32_t)
{
return("BTREE");
}
int TableProtoTesterCursor::write_row(unsigned char *)
{
return(table->next_number_field ? update_auto_increment() : 0);
}
int TableProtoTesterCursor::rnd_init(bool)
{
return(0);
}
int TableProtoTesterCursor::rnd_next(unsigned char *)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
{
assert(0);
return(0);
}
void TableProtoTesterCursor::position(const unsigned char *)
{
assert(0);
return;
}
int TableProtoTesterCursor::info(uint32_t flag)
{
memset(&stats, 0, sizeof(stats));
if (flag & HA_STATUS_AUTO)
stats.auto_increment_value= 1;
return(0);
}
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
key_part_map, enum ha_rkey_function)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
key_part_map, enum ha_rkey_function)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_next(unsigned char *)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_prev(unsigned char *)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_first(unsigned char *)
{
return(HA_ERR_END_OF_FILE);
}
int TableProtoTesterCursor::index_last(unsigned char *)
{
return(HA_ERR_END_OF_FILE);
}
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
static int tableprototester_init(drizzled::plugin::Context &context)
{
tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
context.add(tableprototester_engine);
return 0;
}
DRIZZLE_DECLARE_PLUGIN
{
DRIZZLE_VERSION_ID,
"TABLEPROTOTESTER",
"1.0",
"Stewart Smith",
"Used to test rest of server with various table proto messages",
PLUGIN_LICENSE_GPL,
tableprototester_init, /* Plugin Init */
NULL, /* system variables */
NULL /* config options */
}
DRIZZLE_DECLARE_PLUGIN_END;
|