~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Stewart Smith
  • Date: 2010-03-02 06:41:59 UTC
  • mto: (1309.2.13 build)
  • mto: This revision was merged to the branch mainline in revision 1318.
  • Revision ID: stewart@flamingspork.com-20100302064159-gktw6hcbs3u0fflm
move Item_result out to its own header file and out of common.h

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*,
 
72
                    const char *,
70
73
                    Table&,
71
 
                    const drizzled::TableIdentifier &identifier,
72
74
                    drizzled::message::Table&);
73
75
 
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);
 
76
  int doDropTable(Session&, const string table_name);
 
77
 
 
78
  int doGetTableDefinition(Session& session,
 
79
                           const char* path,
 
80
                           const char *db,
 
81
                           const char *table_name,
 
82
                           const bool is_tmp,
 
83
                           drizzled::message::Table *table_proto);
 
84
 
 
85
  void doGetTableNames(drizzled::CachedDirectory &directory,
 
86
                       string&, set<string>& set_of_names)
 
87
  {
 
88
    (void)directory;
 
89
    set_of_names.insert("t1");
 
90
 
 
91
  }
79
92
 
80
93
  /* The following defines can be increased if necessary */
81
94
  uint32_t max_supported_keys()          const { return 64; }
91
104
            HA_KEYREAD_ONLY);
92
105
  }
93
106
 
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
107
};
105
108
 
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
 
 
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
109
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
131
 
                                               Table &table_arg) :
132
 
  Cursor(engine_arg, table_arg)
 
110
                           TableShare &table_arg)
 
111
  :Cursor(engine_arg, table_arg)
133
112
{ }
134
113
 
135
114
int TableProtoTesterCursor::open(const char *, int, uint32_t)
136
115
{
137
 
  return 0;
 
116
  return(0);
138
117
}
139
118
 
140
119
int TableProtoTesterCursor::close(void)
142
121
  return 0;
143
122
}
144
123
 
145
 
int TableProtoTesterEngine::doCreateTable(Session&,
146
 
                                          Table&,
147
 
                                          const drizzled::TableIdentifier&,
148
 
                                          drizzled::message::Table&)
 
124
int TableProtoTesterEngine::doCreateTable(Session*, const char *,
 
125
                                   Table&,
 
126
                                   drizzled::message::Table&)
149
127
{
150
128
  return EEXIST;
151
129
}
152
130
 
153
131
 
154
 
int TableProtoTesterEngine::doDropTable(Session&, const drizzled::TableIdentifier&)
 
132
int TableProtoTesterEngine::doDropTable(Session&, const string)
155
133
{
156
134
  return EPERM;
157
135
}
158
136
 
159
 
static void fill_table1(message::Table &table)
 
137
static void fill_table1(message::Table *table)
160
138
{
161
139
  message::Table::Field *field;
162
140
  message::Table::TableOptions *tableopts;
163
141
 
164
 
  table.set_name("t1");
165
 
  table.set_type(message::Table::INTERNAL);
 
142
  table->set_name("t1");
 
143
  table->set_type(message::Table::INTERNAL);
166
144
 
167
 
  tableopts= table.mutable_options();
 
145
  tableopts= table->mutable_options();
168
146
  tableopts->set_comment("Table without a StorageEngine message");
169
147
 
170
148
  {
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
 
 
 
149
    field= table->add_field();
 
150
    field->set_name("number");
 
151
    field->set_type(message::Table::Field::INTEGER);
 
152
  }
 
153
 
 
154
}
237
155
int TableProtoTesterEngine::doGetTableDefinition(Session&,
238
 
                                                 const drizzled::TableIdentifier &identifier,
239
 
                                                 drizzled::message::Table &table_proto)
 
156
                                          const char* path,
 
157
                                          const char *,
 
158
                                          const char *,
 
159
                                          const bool,
 
160
                                          drizzled::message::Table *table_proto)
240
161
{
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);
 
162
  if (strcmp(path, "./test/t1") == 0)
 
163
  {
 
164
    if (table_proto)
 
165
      fill_table1(table_proto);
254
166
    return EEXIST;
255
167
  }
256
168
  return ENOENT;
261
173
  return("BTREE");
262
174
}
263
175
 
264
 
int TableProtoTesterCursor::doInsertRecord(unsigned char *)
 
176
int TableProtoTesterCursor::write_row(unsigned char *)
265
177
{
266
 
  return(getTable()->next_number_field ? update_auto_increment() : 0);
 
178
  return(table->next_number_field ? update_auto_increment() : 0);
267
179
}
268
180
 
269
 
int TableProtoTesterCursor::doStartTableScan(bool)
 
181
int TableProtoTesterCursor::rnd_init(bool)
270
182
{
271
183
  return(0);
272
184
}
346
258
 
347
259
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
348
260
 
349
 
static int tableprototester_init(drizzled::module::Context &context)
 
261
static int tableprototester_init(drizzled::plugin::Registry &registry)
350
262
{
351
263
 
352
264
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
353
 
  context.add(tableprototester_engine);
 
265
  registry.add(tableprototester_engine);
 
266
 
 
267
  return 0;
 
268
}
 
269
 
 
270
static int tableprototester_fini(drizzled::plugin::Registry &registry)
 
271
{
 
272
  registry.remove(tableprototester_engine);
 
273
  delete tableprototester_engine;
354
274
 
355
275
  return 0;
356
276
}
364
284
  "Used to test rest of server with various table proto messages",
365
285
  PLUGIN_LICENSE_GPL,
366
286
  tableprototester_init,     /* Plugin Init */
 
287
  tableprototester_fini,     /* Plugin Deinit */
367
288
  NULL,               /* system variables */
368
289
  NULL                /* config options   */
369
290
}