~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/tableprototester/tableprototester.cc

  • Committer: Brian Aker
  • Date: 2010-02-09 21:18:30 UTC
  • mfrom: (1273.2.42)
  • Revision ID: brian@gaz-20100209211830-7vf91n0yasi0r28y
Merge Stewart.

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