~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

Renamed more stuff to drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include <drizzled/table.h>
21
 
#include <drizzled/error.h>
22
 
#include "drizzled/internal/my_pthread.h"
23
 
 
24
 
#include "tableprototester.h"
25
 
 
26
 
#include <fcntl.h>
27
 
 
28
 
#include <string>
29
 
#include <map>
30
 
#include <fstream>
31
 
#include <drizzled/message/table.pb.h>
32
 
#include "drizzled/internal/m_string.h"
33
 
 
34
 
#include "drizzled/global_charset_info.h"
35
 
 
36
 
 
37
 
using namespace std;
38
 
using namespace google;
39
 
using namespace drizzled;
40
 
 
41
 
#define TABLEPROTOTESTER_EXT ".TBT"
42
 
 
43
 
static const char *TableProtoTesterCursor_exts[] = {
44
 
  NULL
45
 
};
46
 
 
47
 
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
48
 
{
49
 
public:
50
 
  TableProtoTesterEngine(const string &name_arg)
51
 
   : drizzled::plugin::StorageEngine(name_arg,
52
 
                                     HTON_NULL_IN_KEY |
53
 
                                     HTON_CAN_INDEX_BLOBS |
54
 
                                     HTON_SKIP_STORE_LOCK |
55
 
                                     HTON_AUTO_PART_KEY)
56
 
  {
57
 
    table_definition_ext= TABLEPROTOTESTER_EXT;
58
 
  }
59
 
 
60
 
  virtual Cursor *create(TableShare &table)
61
 
  {
62
 
    return new TableProtoTesterCursor(*this, table);
63
 
  }
64
 
 
65
 
  const char **bas_ext() const {
66
 
    return TableProtoTesterCursor_exts;
67
 
  }
68
 
 
69
 
  int doCreateTable(Session&,
70
 
                    Table&,
71
 
                    const drizzled::TableIdentifier &identifier,
72
 
                    drizzled::message::Table&);
73
 
 
74
 
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
75
 
 
76
 
  int doGetTableDefinition(Session &session,
77
 
                           const drizzled::TableIdentifier &identifier,
78
 
                           drizzled::message::Table &table_proto);
79
 
 
80
 
  /* The following defines can be increased if necessary */
81
 
  uint32_t max_supported_keys()          const { return 64; }
82
 
  uint32_t max_supported_key_length()    const { return 1000; }
83
 
  uint32_t max_supported_key_part_length() const { return 1000; }
84
 
 
85
 
  uint32_t index_flags(enum  ha_key_alg) const
86
 
  {
87
 
    return (HA_READ_NEXT |
88
 
            HA_READ_PREV |
89
 
            HA_READ_RANGE |
90
 
            HA_READ_ORDER |
91
 
            HA_KEYREAD_ONLY);
92
 
  }
93
 
 
94
 
  bool doDoesTableExist(Session &session, const drizzled::TableIdentifier &identifier);
95
 
 
96
 
  int doRenameTable(Session&, const drizzled::TableIdentifier&, const drizzled::TableIdentifier&)
97
 
  {
98
 
    return EPERM;
99
 
  }
100
 
 
101
 
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
102
 
                             const drizzled::SchemaIdentifier &schema_identifier,
103
 
                             drizzled::TableIdentifiers &set_of_identifiers);
104
 
};
105
 
 
106
 
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
107
 
                                                   const drizzled::SchemaIdentifier &schema_identifier,
108
 
                                                   drizzled::TableIdentifiers &set_of_identifiers)
109
 
{
110
 
  if (schema_identifier.compare("test"))
111
 
  {
112
 
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1"));
113
 
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, "too_many_enum_values"));
114
 
    set_of_identifiers.push_back(TableIdentifier(schema_identifier, "invalid_table_collation"));
115
 
  }
116
 
}
117
 
 
118
 
bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier &identifier)
119
 
{
120
 
  if (not identifier.getPath().compare("test/t1"))
121
 
    return true;
122
 
  if (not identifier.getPath().compare("test/too_many_enum_values"))
123
 
    return true;
124
 
  if (not identifier.getPath().compare("test/invalid_table_collation"))
125
 
    return true;
126
 
 
127
 
  return false;
128
 
}
129
 
 
130
 
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
131
 
                           TableShare &table_arg) :
132
 
  Cursor(engine_arg, table_arg)
133
 
{ }
134
 
 
135
 
int TableProtoTesterCursor::open(const char *, int, uint32_t)
136
 
{
137
 
  return 0;
138
 
}
139
 
 
140
 
int TableProtoTesterCursor::close(void)
141
 
{
142
 
  return 0;
143
 
}
144
 
 
145
 
int TableProtoTesterEngine::doCreateTable(Session&,
146
 
                                          Table&,
147
 
                                          const drizzled::TableIdentifier&,
148
 
                                          drizzled::message::Table&)
149
 
{
150
 
  return EEXIST;
151
 
}
152
 
 
153
 
 
154
 
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::TableIdentifier&)
155
 
{
156
 
  return EPERM;
157
 
}
158
 
 
159
 
static void fill_table1(message::Table &table)
160
 
{
161
 
  message::Table::Field *field;
162
 
  message::Table::TableOptions *tableopts;
163
 
 
164
 
  table.set_name("t1");
165
 
  table.set_type(message::Table::INTERNAL);
166
 
 
167
 
  tableopts= table.mutable_options();
168
 
  tableopts->set_comment("Table without a StorageEngine message");
169
 
 
170
 
  {
171
 
    field= table.add_field();
172
 
    field->set_name("number");
173
 
    field->set_type(message::Table::Field::INTEGER);
174
 
  }
175
 
 
176
 
}
177
 
 
178
 
static void fill_table_too_many_enum_values(message::Table &table)
179
 
{
180
 
  message::Table::Field *field;
181
 
  message::Table::TableOptions *tableopts;
182
 
 
183
 
  table.set_schema("test");
184
 
  table.set_name("too_many_enum_values");
185
 
  table.set_type(message::Table::STANDARD);
186
 
  table.mutable_engine()->set_name("tableprototester");
187
 
  table.set_creation_timestamp(0);
188
 
  table.set_update_timestamp(0);
189
 
 
190
 
  tableopts= table.mutable_options();
191
 
  tableopts->set_comment("Table with too many enum options");
192
 
  tableopts->set_collation("utf8_general_ci");
193
 
  tableopts->set_collation_id(45);
194
 
 
195
 
  {
196
 
    field= table.add_field();
197
 
    field->set_name("many_values");
198
 
    field->set_type(message::Table::Field::ENUM);
199
 
 
200
 
    message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values();
201
 
    for(int i=0; i<70000; i++)
202
 
    {
203
 
      char enum_value[100];
204
 
      snprintf(enum_value, sizeof(enum_value), "a%d", i);
205
 
      field_options->add_field_value(enum_value);
206
 
    }
207
 
  }
208
 
 
209
 
}
210
 
 
211
 
static void fill_table_invalid_table_collation(message::Table &table)
212
 
{
213
 
  message::Table::Field *field;
214
 
  message::Table::TableOptions *tableopts;
215
 
 
216
 
  table.set_name("invalid_table_collation");
217
 
  table.set_type(message::Table::STANDARD);
218
 
  table.set_schema("test");
219
 
  table.set_creation_timestamp(0);
220
 
  table.set_update_timestamp(0);
221
 
  table.mutable_engine()->set_name("tableprototester");
222
 
 
223
 
  tableopts= table.mutable_options();
224
 
  tableopts->set_comment("Invalid table collation ");
225
 
 
226
 
  {
227
 
    field= table.add_field();
228
 
    field->set_name("number");
229
 
    field->set_type(message::Table::Field::INTEGER);
230
 
  }
231
 
 
232
 
  tableopts->set_collation("pi_pi_pi");
233
 
  tableopts->set_collation_id(123456);
234
 
 
235
 
}
236
 
 
237
 
int TableProtoTesterEngine::doGetTableDefinition(Session&,
238
 
                                                 const drizzled::TableIdentifier &identifier,
239
 
                                                 drizzled::message::Table &table_proto)
240
 
{
241
 
  if (not identifier.getPath().compare("test/t1"))
242
 
  {
243
 
    fill_table1(table_proto);
244
 
    return EEXIST;
245
 
  }
246
 
  else if (not identifier.getPath().compare("test/too_many_enum_values"))
247
 
  {
248
 
    fill_table_too_many_enum_values(table_proto);
249
 
    return EEXIST;
250
 
  }
251
 
  else if (not identifier.getPath().compare("test/invalid_table_collation"))
252
 
  {
253
 
    fill_table_invalid_table_collation(table_proto);
254
 
    return EEXIST;
255
 
  }
256
 
  return ENOENT;
257
 
}
258
 
 
259
 
const char *TableProtoTesterCursor::index_type(uint32_t)
260
 
{
261
 
  return("BTREE");
262
 
}
263
 
 
264
 
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
265
 
{
266
 
  return(table->next_number_field ? update_auto_increment() : 0);
267
 
}
268
 
 
269
 
int TableProtoTesterCursor::doStartTableScan(bool)
270
 
{
271
 
  return(0);
272
 
}
273
 
 
274
 
 
275
 
int TableProtoTesterCursor::rnd_next(unsigned char *)
276
 
{
277
 
  return(HA_ERR_END_OF_FILE);
278
 
}
279
 
 
280
 
 
281
 
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
282
 
{
283
 
  assert(0);
284
 
  return(0);
285
 
}
286
 
 
287
 
 
288
 
void TableProtoTesterCursor::position(const unsigned char *)
289
 
{
290
 
  assert(0);
291
 
  return;
292
 
}
293
 
 
294
 
 
295
 
int TableProtoTesterCursor::info(uint32_t flag)
296
 
{
297
 
  memset(&stats, 0, sizeof(stats));
298
 
  if (flag & HA_STATUS_AUTO)
299
 
    stats.auto_increment_value= 1;
300
 
  return(0);
301
 
}
302
 
 
303
 
 
304
 
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
305
 
                                 key_part_map, enum ha_rkey_function)
306
 
{
307
 
  return(HA_ERR_END_OF_FILE);
308
 
}
309
 
 
310
 
 
311
 
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
312
 
                                     key_part_map, enum ha_rkey_function)
313
 
{
314
 
  return(HA_ERR_END_OF_FILE);
315
 
}
316
 
 
317
 
 
318
 
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
319
 
{
320
 
  return(HA_ERR_END_OF_FILE);
321
 
}
322
 
 
323
 
 
324
 
int TableProtoTesterCursor::index_next(unsigned char *)
325
 
{
326
 
  return(HA_ERR_END_OF_FILE);
327
 
}
328
 
 
329
 
 
330
 
int TableProtoTesterCursor::index_prev(unsigned char *)
331
 
{
332
 
  return(HA_ERR_END_OF_FILE);
333
 
}
334
 
 
335
 
 
336
 
int TableProtoTesterCursor::index_first(unsigned char *)
337
 
{
338
 
  return(HA_ERR_END_OF_FILE);
339
 
}
340
 
 
341
 
 
342
 
int TableProtoTesterCursor::index_last(unsigned char *)
343
 
{
344
 
  return(HA_ERR_END_OF_FILE);
345
 
}
346
 
 
347
 
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
348
 
 
349
 
static int tableprototester_init(drizzled::module::Context &context)
350
 
{
351
 
 
352
 
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
353
 
  context.add(tableprototester_engine);
354
 
 
355
 
  return 0;
356
 
}
357
 
 
358
 
DRIZZLE_DECLARE_PLUGIN
359
 
{
360
 
  DRIZZLE_VERSION_ID,
361
 
  "TABLEPROTOTESTER",
362
 
  "1.0",
363
 
  "Stewart Smith",
364
 
  "Used to test rest of server with various table proto messages",
365
 
  PLUGIN_LICENSE_GPL,
366
 
  tableprototester_init,     /* Plugin Init */
367
 
  NULL,               /* system variables */
368
 
  NULL                /* config options   */
369
 
}
370
 
DRIZZLE_DECLARE_PLUGIN_END;