~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Monty Taylor
  • Date: 2010-03-23 08:23:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1398.
  • Revision ID: mordred@inaugust.com-20100323082332-r8tktlbu82wlamzv
Set the default plugin version for plugins not specifying a version to be
tied to the actual server version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                                     HTON_NULL_IN_KEY |
53
53
                                     HTON_CAN_INDEX_BLOBS |
54
54
                                     HTON_SKIP_STORE_LOCK |
55
 
                                     HTON_AUTO_PART_KEY)
 
55
                                     HTON_AUTO_PART_KEY |
 
56
                                     HTON_HAS_DATA_DICTIONARY)
56
57
  {
57
58
    table_definition_ext= TABLEPROTOTESTER_EXT;
58
59
  }
59
60
 
60
 
  virtual Cursor *create(Table &table)
 
61
  virtual Cursor *create(TableShare &table,
 
62
                         drizzled::memory::Root *mem_root)
61
63
  {
62
 
    return new TableProtoTesterCursor(*this, table);
 
64
    return new (mem_root) TableProtoTesterCursor(*this, table);
63
65
  }
64
66
 
65
67
  const char **bas_ext() const {
66
68
    return TableProtoTesterCursor_exts;
67
69
  }
68
70
 
69
 
  int doCreateTable(Session&,
 
71
  int doCreateTable(Session*,
70
72
                    Table&,
71
 
                    const drizzled::TableIdentifier &identifier,
 
73
                    drizzled::TableIdentifier &identifier,
72
74
                    drizzled::message::Table&);
73
75
 
74
 
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
 
76
  int doDropTable(Session&, drizzled::TableIdentifier &identifier);
75
77
 
76
 
  int doGetTableDefinition(Session &session,
77
 
                           const drizzled::TableIdentifier &identifier,
 
78
  int doGetTableDefinition(Session& session,
 
79
                           drizzled::TableIdentifier &identifier,
78
80
                           drizzled::message::Table &table_proto);
79
81
 
 
82
  void doGetTableNames(drizzled::CachedDirectory &directory,
 
83
                       string&, set<string>& set_of_names)
 
84
  {
 
85
    (void)directory;
 
86
    set_of_names.insert("t1");
 
87
 
 
88
  }
 
89
 
80
90
  /* The following defines can be increased if necessary */
81
91
  uint32_t max_supported_keys()          const { return 64; }
82
92
  uint32_t max_supported_key_length()    const { return 1000; }
91
101
            HA_KEYREAD_ONLY);
92
102
  }
93
103
 
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::TableIdentifier::vector &set_of_identifiers);
 
104
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
104
105
};
105
106
 
106
 
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
107
 
                                                   const drizzled::SchemaIdentifier &schema_identifier,
108
 
                                                   drizzled::TableIdentifier::vector &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
107
 
118
 
bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier &identifier)
 
108
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
119
109
{
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"))
 
110
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
125
111
    return true;
126
112
 
127
113
  return false;
128
114
}
129
115
 
130
116
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
131
 
                                               Table &table_arg) :
 
117
                           TableShare &table_arg) :
132
118
  Cursor(engine_arg, table_arg)
133
119
{ }
134
120
 
142
128
  return 0;
143
129
}
144
130
 
145
 
int TableProtoTesterEngine::doCreateTable(Session&,
 
131
int TableProtoTesterEngine::doCreateTable(Session*,
146
132
                                          Table&,
147
 
                                          const drizzled::TableIdentifier&,
 
133
                                          drizzled::TableIdentifier &,
148
134
                                          drizzled::message::Table&)
149
135
{
150
136
  return EEXIST;
151
137
}
152
138
 
153
139
 
154
 
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::TableIdentifier&)
 
140
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&)
155
141
{
156
142
  return EPERM;
157
143
}
174
160
  }
175
161
 
176
162
}
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
163
int TableProtoTesterEngine::doGetTableDefinition(Session&,
238
 
                                                 const drizzled::TableIdentifier &identifier,
 
164
                                                 drizzled::TableIdentifier &identifier,
239
165
                                                 drizzled::message::Table &table_proto)
240
166
{
241
 
  if (not identifier.getPath().compare("test/t1"))
 
167
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
242
168
  {
243
169
    fill_table1(table_proto);
244
170
    return EEXIST;
245
171
  }
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
172
  return ENOENT;
257
173
}
258
174
 
261
177
  return("BTREE");
262
178
}
263
179
 
264
 
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
 
180
int TableProtoTesterCursor::write_row(unsigned char *)
265
181
{
266
 
  return(getTable()->next_number_field ? update_auto_increment() : 0);
 
182
  return(table->next_number_field ? update_auto_increment() : 0);
267
183
}
268
184
 
269
 
int TableProtoTesterCursor::doStartTableScan(bool)
 
185
int TableProtoTesterCursor::rnd_init(bool)
270
186
{
271
187
  return(0);
272
188
}
346
262
 
347
263
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
348
264
 
349
 
static int tableprototester_init(drizzled::module::Context &context)
 
265
static int tableprototester_init(drizzled::plugin::Registry &registry)
350
266
{
351
267
 
352
268
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
353
 
  context.add(tableprototester_engine);
 
269
  registry.add(tableprototester_engine);
 
270
 
 
271
  return 0;
 
272
}
 
273
 
 
274
static int tableprototester_fini(drizzled::plugin::Registry &registry)
 
275
{
 
276
  registry.remove(tableprototester_engine);
 
277
  delete tableprototester_engine;
354
278
 
355
279
  return 0;
356
280
}
364
288
  "Used to test rest of server with various table proto messages",
365
289
  PLUGIN_LICENSE_GPL,
366
290
  tableprototester_init,     /* Plugin Init */
 
291
  tableprototester_fini,     /* Plugin Deinit */
367
292
  NULL,               /* system variables */
368
293
  NULL                /* config options   */
369
294
}