~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Andrew Hutchings
  • Date: 2010-11-01 22:14:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1907.
  • Revision ID: andrew@linuxjedi.co.uk-20101101221418-9n9gmm4ms7fl8vo5
Fix copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    table_definition_ext= TABLEPROTOTESTER_EXT;
58
58
  }
59
59
 
60
 
  virtual Cursor *create(TableShare &table,
61
 
                         drizzled::memory::Root *mem_root)
 
60
  virtual Cursor *create(Table &table)
62
61
  {
63
 
    return new (mem_root) TableProtoTesterCursor(*this, table);
 
62
    return new TableProtoTesterCursor(*this, table);
64
63
  }
65
64
 
66
65
  const char **bas_ext() const {
69
68
 
70
69
  int doCreateTable(Session&,
71
70
                    Table&,
72
 
                    drizzled::TableIdentifier &identifier,
 
71
                    const drizzled::TableIdentifier &identifier,
73
72
                    drizzled::message::Table&);
74
73
 
75
 
  int doDropTable(Session&, drizzled::TableIdentifier &identifier);
 
74
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
76
75
 
77
76
  int doGetTableDefinition(Session &session,
78
 
                           drizzled::TableIdentifier &identifier,
 
77
                           const drizzled::TableIdentifier &identifier,
79
78
                           drizzled::message::Table &table_proto);
80
79
 
81
 
  void doGetTableNames(drizzled::CachedDirectory &directory,
82
 
                       SchemaIdentifier &,
83
 
                       set<string>& set_of_names)
84
 
  {
85
 
    (void)directory;
86
 
    set_of_names.insert("t1");
87
 
 
88
 
  }
89
 
 
90
80
  /* The following defines can be increased if necessary */
91
81
  uint32_t max_supported_keys()          const { return 64; }
92
82
  uint32_t max_supported_key_length()    const { return 1000; }
101
91
            HA_KEYREAD_ONLY);
102
92
  }
103
93
 
104
 
  bool doDoesTableExist(Session &session, TableIdentifier &identifier);
 
94
  bool doDoesTableExist(Session &session, const drizzled::TableIdentifier &identifier);
105
95
 
106
 
  int doRenameTable(Session&, TableIdentifier&, TableIdentifier&)
 
96
  int doRenameTable(Session&, const drizzled::TableIdentifier&, const drizzled::TableIdentifier&)
107
97
  {
108
98
    return EPERM;
109
99
  }
110
100
 
111
101
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
112
 
                             drizzled::SchemaIdentifier &schema_identifier,
 
102
                             const drizzled::SchemaIdentifier &schema_identifier,
113
103
                             drizzled::TableIdentifiers &set_of_identifiers);
114
104
};
115
105
 
116
106
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
117
 
                                                   drizzled::SchemaIdentifier &schema_identifier,
 
107
                                                   const drizzled::SchemaIdentifier &schema_identifier,
118
108
                                                   drizzled::TableIdentifiers &set_of_identifiers)
119
109
{
120
 
  set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1"));
 
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
  }
121
116
}
122
117
 
123
 
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
 
118
bool TableProtoTesterEngine::doDoesTableExist(Session&, const drizzled::TableIdentifier &identifier)
124
119
{
125
 
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
 
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"))
126
125
    return true;
127
126
 
128
127
  return false;
129
128
}
130
129
 
131
130
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
132
 
                           TableShare &table_arg) :
 
131
                                               Table &table_arg) :
133
132
  Cursor(engine_arg, table_arg)
134
133
{ }
135
134
 
145
144
 
146
145
int TableProtoTesterEngine::doCreateTable(Session&,
147
146
                                          Table&,
148
 
                                          drizzled::TableIdentifier&,
 
147
                                          const drizzled::TableIdentifier&,
149
148
                                          drizzled::message::Table&)
150
149
{
151
150
  return EEXIST;
152
151
}
153
152
 
154
153
 
155
 
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&)
 
154
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::TableIdentifier&)
156
155
{
157
156
  return EPERM;
158
157
}
175
174
  }
176
175
 
177
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
 
178
237
int TableProtoTesterEngine::doGetTableDefinition(Session&,
179
 
                                                 drizzled::TableIdentifier &identifier,
 
238
                                                 const drizzled::TableIdentifier &identifier,
180
239
                                                 drizzled::message::Table &table_proto)
181
240
{
182
 
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
 
241
  if (not identifier.getPath().compare("test/t1"))
183
242
  {
184
243
    fill_table1(table_proto);
185
244
    return EEXIST;
186
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
  }
187
256
  return ENOENT;
188
257
}
189
258
 
192
261
  return("BTREE");
193
262
}
194
263
 
195
 
int TableProtoTesterCursor::write_row(unsigned char *)
 
264
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
196
265
{
197
 
  return(table->next_number_field ? update_auto_increment() : 0);
 
266
  return(getTable()->next_number_field ? update_auto_increment() : 0);
198
267
}
199
268
 
200
 
int TableProtoTesterCursor::rnd_init(bool)
 
269
int TableProtoTesterCursor::doStartTableScan(bool)
201
270
{
202
271
  return(0);
203
272
}
277
346
 
278
347
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
279
348
 
280
 
static int tableprototester_init(drizzled::plugin::Context &context)
 
349
static int tableprototester_init(drizzled::module::Context &context)
281
350
{
282
351
 
283
352
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");