~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Stewart Smith
  • Date: 2010-02-05 01:20:18 UTC
  • mto: (1286.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1287.
  • Revision ID: stewart@flamingspork.com-20100205012018-blvmeky20wze8eyg
initial TableProtoTester engine. We can't just use table_write as some protobuf library versions don't let us write invalid protobuf messages :(

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
 
 
40
#define TABLEPROTOTESTER_EXT ".TBT"
 
41
 
 
42
static const char *TableProtoTesterCursor_exts[] = {
 
43
  NULL
 
44
};
 
45
 
 
46
class TableProtoTesterEngine : public drizzled::plugin::StorageEngine
 
47
{
 
48
public:
 
49
  TableProtoTesterEngine(const string &name_arg)
 
50
   : drizzled::plugin::StorageEngine(name_arg,
 
51
                                     HTON_NULL_IN_KEY |
 
52
                                     HTON_CAN_INDEX_BLOBS |
 
53
                                     HTON_SKIP_STORE_LOCK |
 
54
                                     HTON_AUTO_PART_KEY |
 
55
                                     HTON_HAS_DATA_DICTIONARY)
 
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
                    const char *,
 
72
                    Table&,
 
73
                    drizzled::message::Table&);
 
74
 
 
75
  int doDropTable(Session&, const string table_name);
 
76
 
 
77
  int doGetTableDefinition(Session& session,
 
78
                           const char* path,
 
79
                           const char *db,
 
80
                           const char *table_name,
 
81
                           const bool is_tmp,
 
82
                           drizzled::message::Table *table_proto);
 
83
 
 
84
  void doGetTableNames(drizzled::CachedDirectory &directory,
 
85
                       string&, set<string>& set_of_names)
 
86
  {
 
87
//    set_of_names.insert();
 
88
    (void)directory;
 
89
    (void)set_of_names;
 
90
  }
 
91
 
 
92
  /* The following defines can be increased if necessary */
 
93
  uint32_t max_supported_keys()          const { return 64; }
 
94
  uint32_t max_supported_key_length()    const { return 1000; }
 
95
  uint32_t max_supported_key_part_length() const { return 1000; }
 
96
 
 
97
  uint32_t index_flags(enum  ha_key_alg) const
 
98
  {
 
99
    return (HA_READ_NEXT |
 
100
            HA_READ_PREV |
 
101
            HA_READ_RANGE |
 
102
            HA_READ_ORDER |
 
103
            HA_KEYREAD_ONLY);
 
104
  }
 
105
 
 
106
};
 
107
 
 
108
TableProtoTesterCursor::TableProtoTesterCursor(drizzled::plugin::StorageEngine &engine_arg,
 
109
                           TableShare &table_arg)
 
110
  :Cursor(engine_arg, table_arg)
 
111
{ }
 
112
 
 
113
int TableProtoTesterCursor::open(const char *, int, uint32_t)
 
114
{
 
115
  return(0);
 
116
}
 
117
 
 
118
int TableProtoTesterCursor::close(void)
 
119
{
 
120
  return 0;
 
121
}
 
122
 
 
123
int TableProtoTesterEngine::doCreateTable(Session*, const char *,
 
124
                                   Table&,
 
125
                                   drizzled::message::Table&)
 
126
{
 
127
  return EEXIST;
 
128
}
 
129
 
 
130
 
 
131
int TableProtoTesterEngine::doDropTable(Session&, const string)
 
132
{
 
133
  return EPERM;
 
134
}
 
135
 
 
136
int TableProtoTesterEngine::doGetTableDefinition(Session&,
 
137
                                          const char* path,
 
138
                                          const char *,
 
139
                                          const char *,
 
140
                                          const bool,
 
141
                                          drizzled::message::Table *table_proto)
 
142
{
 
143
  (void)path;
 
144
  (void)table_proto;
 
145
  return ENOENT;
 
146
}
 
147
 
 
148
const char *TableProtoTesterCursor::index_type(uint32_t)
 
149
{
 
150
  return("BTREE");
 
151
}
 
152
 
 
153
int TableProtoTesterCursor::write_row(unsigned char *)
 
154
{
 
155
  return(table->next_number_field ? update_auto_increment() : 0);
 
156
}
 
157
 
 
158
int TableProtoTesterCursor::rnd_init(bool)
 
159
{
 
160
  return(0);
 
161
}
 
162
 
 
163
 
 
164
int TableProtoTesterCursor::rnd_next(unsigned char *)
 
165
{
 
166
  return(HA_ERR_END_OF_FILE);
 
167
}
 
168
 
 
169
 
 
170
int TableProtoTesterCursor::rnd_pos(unsigned char *, unsigned char *)
 
171
{
 
172
  assert(0);
 
173
  return(0);
 
174
}
 
175
 
 
176
 
 
177
void TableProtoTesterCursor::position(const unsigned char *)
 
178
{
 
179
  assert(0);
 
180
  return;
 
181
}
 
182
 
 
183
 
 
184
int TableProtoTesterCursor::info(uint32_t flag)
 
185
{
 
186
  memset(&stats, 0, sizeof(stats));
 
187
  if (flag & HA_STATUS_AUTO)
 
188
    stats.auto_increment_value= 1;
 
189
  return(0);
 
190
}
 
191
 
 
192
 
 
193
int TableProtoTesterCursor::index_read_map(unsigned char *, const unsigned char *,
 
194
                                 key_part_map, enum ha_rkey_function)
 
195
{
 
196
  return(HA_ERR_END_OF_FILE);
 
197
}
 
198
 
 
199
 
 
200
int TableProtoTesterCursor::index_read_idx_map(unsigned char *, uint32_t, const unsigned char *,
 
201
                                     key_part_map, enum ha_rkey_function)
 
202
{
 
203
  return(HA_ERR_END_OF_FILE);
 
204
}
 
205
 
 
206
 
 
207
int TableProtoTesterCursor::index_read_last_map(unsigned char *, const unsigned char *, key_part_map)
 
208
{
 
209
  return(HA_ERR_END_OF_FILE);
 
210
}
 
211
 
 
212
 
 
213
int TableProtoTesterCursor::index_next(unsigned char *)
 
214
{
 
215
  return(HA_ERR_END_OF_FILE);
 
216
}
 
217
 
 
218
 
 
219
int TableProtoTesterCursor::index_prev(unsigned char *)
 
220
{
 
221
  return(HA_ERR_END_OF_FILE);
 
222
}
 
223
 
 
224
 
 
225
int TableProtoTesterCursor::index_first(unsigned char *)
 
226
{
 
227
  return(HA_ERR_END_OF_FILE);
 
228
}
 
229
 
 
230
 
 
231
int TableProtoTesterCursor::index_last(unsigned char *)
 
232
{
 
233
  return(HA_ERR_END_OF_FILE);
 
234
}
 
235
 
 
236
static drizzled::plugin::StorageEngine *tableprototester_engine= NULL;
 
237
 
 
238
static int tableprototester_init(drizzled::plugin::Registry &registry)
 
239
{
 
240
 
 
241
  tableprototester_engine= new TableProtoTesterEngine("TABLEPROTOTESTER");
 
242
  registry.add(tableprototester_engine);
 
243
 
 
244
  return 0;
 
245
}
 
246
 
 
247
static int tableprototester_fini(drizzled::plugin::Registry &registry)
 
248
{
 
249
  registry.remove(tableprototester_engine);
 
250
  delete tableprototester_engine;
 
251
 
 
252
  return 0;
 
253
}
 
254
 
 
255
DRIZZLE_DECLARE_PLUGIN
 
256
{
 
257
  DRIZZLE_VERSION_ID,
 
258
  "TABLEPROTOTESTER",
 
259
  "1.0",
 
260
  "Stewart Smith",
 
261
  "Used to test rest of server with various table proto messages",
 
262
  PLUGIN_LICENSE_GPL,
 
263
  tableprototester_init,     /* Plugin Init */
 
264
  tableprototester_fini,     /* Plugin Deinit */
 
265
  NULL,               /* status variables */
 
266
  NULL,               /* system variables */
 
267
  NULL                /* config options   */
 
268
}
 
269
DRIZZLE_DECLARE_PLUGIN_END;