~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-17 00:08:20 UTC
  • mto: (1126.9.3 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090917000820-urd6p46qngi1okjp
Updated calls to some dtrace probes to cast the parameter to const char *
appropriately. Also, removed the additional variable in places that I was
using.

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
 
                         drizzled::memory::Root *mem_root)
62
 
  {
63
 
    return new (mem_root) TableProtoTesterCursor(*this, table);
64
 
  }
65
 
 
66
 
  const char **bas_ext() const {
67
 
    return TableProtoTesterCursor_exts;
68
 
  }
69
 
 
70
 
  int doCreateTable(Session&,
71
 
                    Table&,
72
 
                    drizzled::TableIdentifier &identifier,
73
 
                    drizzled::message::Table&);
74
 
 
75
 
  int doDropTable(Session&, drizzled::TableIdentifier &identifier);
76
 
 
77
 
  int doGetTableDefinition(Session &session,
78
 
                           drizzled::TableIdentifier &identifier,
79
 
                           drizzled::message::Table &table_proto);
80
 
 
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
 
  /* The following defines can be increased if necessary */
91
 
  uint32_t max_supported_keys()          const { return 64; }
92
 
  uint32_t max_supported_key_length()    const { return 1000; }
93
 
  uint32_t max_supported_key_part_length() const { return 1000; }
94
 
 
95
 
  uint32_t index_flags(enum  ha_key_alg) const
96
 
  {
97
 
    return (HA_READ_NEXT |
98
 
            HA_READ_PREV |
99
 
            HA_READ_RANGE |
100
 
            HA_READ_ORDER |
101
 
            HA_KEYREAD_ONLY);
102
 
  }
103
 
 
104
 
  bool doDoesTableExist(Session &session, TableIdentifier &identifier);
105
 
 
106
 
  int doRenameTable(Session&, TableIdentifier&, TableIdentifier&)
107
 
  {
108
 
    return EPERM;
109
 
  }
110
 
 
111
 
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
112
 
                             drizzled::SchemaIdentifier &schema_identifier,
113
 
                             drizzled::TableIdentifiers &set_of_identifiers);
114
 
};
115
 
 
116
 
void TableProtoTesterEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
117
 
                                                   drizzled::SchemaIdentifier &schema_identifier,
118
 
                                                   drizzled::TableIdentifiers &set_of_identifiers)
119
 
{
120
 
  set_of_identifiers.push_back(TableIdentifier(schema_identifier, "t1"));
121
 
}
122
 
 
123
 
bool TableProtoTesterEngine::doDoesTableExist(Session&, TableIdentifier &identifier)
124
 
{
125
 
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
126
 
    return true;
127
 
 
128
 
  return false;
129
 
}
130
 
 
131
 
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
132
 
                           TableShare &table_arg) :
133
 
  Cursor(engine_arg, table_arg)
134
 
{ }
135
 
 
136
 
int TableProtoTesterCursor::open(const char *, int, uint32_t)
137
 
{
138
 
  return 0;
139
 
}
140
 
 
141
 
int TableProtoTesterCursor::close(void)
142
 
{
143
 
  return 0;
144
 
}
145
 
 
146
 
int TableProtoTesterEngine::doCreateTable(Session&,
147
 
                                          Table&,
148
 
                                          drizzled::TableIdentifier&,
149
 
                                          drizzled::message::Table&)
150
 
{
151
 
  return EEXIST;
152
 
}
153
 
 
154
 
 
155
 
int TableProtoTesterEngine::doDropTable(Session&, drizzled::TableIdentifier&)
156
 
{
157
 
  return EPERM;
158
 
}
159
 
 
160
 
static void fill_table1(message::Table &table)
161
 
{
162
 
  message::Table::Field *field;
163
 
  message::Table::TableOptions *tableopts;
164
 
 
165
 
  table.set_name("t1");
166
 
  table.set_type(message::Table::INTERNAL);
167
 
 
168
 
  tableopts= table.mutable_options();
169
 
  tableopts->set_comment("Table without a StorageEngine message");
170
 
 
171
 
  {
172
 
    field= table.add_field();
173
 
    field->set_name("number");
174
 
    field->set_type(message::Table::Field::INTEGER);
175
 
  }
176
 
 
177
 
}
178
 
int TableProtoTesterEngine::doGetTableDefinition(Session&,
179
 
                                                 drizzled::TableIdentifier &identifier,
180
 
                                                 drizzled::message::Table &table_proto)
181
 
{
182
 
  if (strcmp(identifier.getPath().c_str(), "./test/t1") == 0)
183
 
  {
184
 
    fill_table1(table_proto);
185
 
    return EEXIST;
186
 
  }
187
 
  return ENOENT;
188
 
}
189
 
 
190
 
const char *TableProtoTesterCursor::index_type(uint32_t)
191
 
{
192
 
  return("BTREE");
193
 
}
194
 
 
195
 
int TableProtoTesterCursor::write_row(unsigned char *)
196
 
{
197
 
  return(table->next_number_field ? update_auto_increment() : 0);
198
 
}
199
 
 
200
 
int TableProtoTesterCursor::rnd_init(bool)
201
 
{
202
 
  return(0);
203
 
}
204
 
 
205
 
 
206
 
int TableProtoTesterCursor::rnd_next(unsigned char *)
207
 
{
208
 
  return(HA_ERR_END_OF_FILE);
209
 
}
210
 
 
211
 
 
212
 
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
213
 
{
214
 
  assert(0);
215
 
  return(0);
216
 
}
217
 
 
218
 
 
219
 
void TableProtoTesterCursor::position(const unsigned char *)
220
 
{
221
 
  assert(0);
222
 
  return;
223
 
}
224
 
 
225
 
 
226
 
int TableProtoTesterCursor::info(uint32_t flag)
227
 
{
228
 
  memset(&stats, 0, sizeof(stats));
229
 
  if (flag & HA_STATUS_AUTO)
230
 
    stats.auto_increment_value= 1;
231
 
  return(0);
232
 
}
233
 
 
234
 
 
235
 
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
236
 
                                 key_part_map, enum ha_rkey_function)
237
 
{
238
 
  return(HA_ERR_END_OF_FILE);
239
 
}
240
 
 
241
 
 
242
 
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
243
 
                                     key_part_map, enum ha_rkey_function)
244
 
{
245
 
  return(HA_ERR_END_OF_FILE);
246
 
}
247
 
 
248
 
 
249
 
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
250
 
{
251
 
  return(HA_ERR_END_OF_FILE);
252
 
}
253
 
 
254
 
 
255
 
int TableProtoTesterCursor::index_next(unsigned char *)
256
 
{
257
 
  return(HA_ERR_END_OF_FILE);
258
 
}
259
 
 
260
 
 
261
 
int TableProtoTesterCursor::index_prev(unsigned char *)
262
 
{
263
 
  return(HA_ERR_END_OF_FILE);
264
 
}
265
 
 
266
 
 
267
 
int TableProtoTesterCursor::index_first(unsigned char *)
268
 
{
269
 
  return(HA_ERR_END_OF_FILE);
270
 
}
271
 
 
272
 
 
273
 
int TableProtoTesterCursor::index_last(unsigned char *)
274
 
{
275
 
  return(HA_ERR_END_OF_FILE);
276
 
}
277
 
 
278
 
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
279
 
 
280
 
static int tableprototester_init(drizzled::plugin::Context &context)
281
 
{
282
 
 
283
 
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
284
 
  context.add(tableprototester_engine);
285
 
 
286
 
  return 0;
287
 
}
288
 
 
289
 
DRIZZLE_DECLARE_PLUGIN
290
 
{
291
 
  DRIZZLE_VERSION_ID,
292
 
  "TABLEPROTOTESTER",
293
 
  "1.0",
294
 
  "Stewart Smith",
295
 
  "Used to test rest of server with various table proto messages",
296
 
  PLUGIN_LICENSE_GPL,
297
 
  tableprototester_init,     /* Plugin Init */
298
 
  NULL,               /* system variables */
299
 
  NULL                /* config options   */
300
 
}
301
 
DRIZZLE_DECLARE_PLUGIN_END;