~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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