~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/example/ha_example.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
  This program is free software; you can redistribute it and/or modify
 
4
  it under the terms of the GNU General Public License as published by
 
5
  the Free Software Foundation; version 2 of the License.
 
6
 
 
7
  This program is distributed in the hope that it will be useful,
 
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
  GNU General Public License for more details.
 
11
 
 
12
  You should have received a copy of the GNU General Public License
 
13
  along with this program; if not, write to the Free Software
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/** @file ha_example.h
 
17
 
 
18
    @brief
 
19
  The ha_example engine is a stubbed storage engine for example purposes only;
 
20
  it does nothing at this point. Its purpose is to provide a source
 
21
  code illustration of how to begin writing new storage engines; see also
 
22
  /storage/example/ha_example.cc.
 
23
 
 
24
    @note
 
25
  Please read ha_example.cc before reading this file.
 
26
  Reminder: The example storage engine implements all methods that are *required*
 
27
  to be implemented. For a full list of all methods that you can implement, see
 
28
  handler.h.
 
29
 
 
30
   @see
 
31
  /sql/handler.h and /storage/example/ha_example.cc
 
32
*/
 
33
 
 
34
#ifdef USE_PRAGMA_INTERFACE
 
35
#pragma interface                       /* gcc class implementation */
 
36
#endif
 
37
 
 
38
/** @brief
 
39
  EXAMPLE_SHARE is a structure that will be shared among all open handlers.
 
40
  This example implements the minimum of what you will probably need.
 
41
*/
 
42
typedef struct st_example_share {
 
43
  char *table_name;
 
44
  uint table_name_length,use_count;
 
45
  pthread_mutex_t mutex;
 
46
  THR_LOCK lock;
 
47
} EXAMPLE_SHARE;
 
48
 
 
49
/** @brief
 
50
  Class definition for the storage engine
 
51
*/
 
52
class ha_example: public handler
 
53
{
 
54
  THR_LOCK_DATA lock;      ///< MySQL lock
 
55
  EXAMPLE_SHARE *share;    ///< Shared lock info
 
56
 
 
57
public:
 
58
  ha_example(handlerton *hton, TABLE_SHARE *table_arg);
 
59
  ~ha_example()
 
60
  {
 
61
  }
 
62
 
 
63
  /** @brief
 
64
    The name that will be used for display purposes.
 
65
   */
 
66
  const char *table_type() const { return "EXAMPLE"; }
 
67
 
 
68
  /** @brief
 
69
    The name of the index type that will be used for display.
 
70
    Don't implement this method unless you really have indexes.
 
71
   */
 
72
  const char *index_type(uint inx) { return "HASH"; }
 
73
 
 
74
  /** @brief
 
75
    The file extensions.
 
76
   */
 
77
  const char **bas_ext() const;
 
78
 
 
79
  /** @brief
 
80
    This is a list of flags that indicate what functionality the storage engine
 
81
    implements. The current table flags are documented in handler.h
 
82
  */
 
83
  ulonglong table_flags() const
 
84
  {
 
85
    /*
 
86
      We are saying that this engine is just row capable to have an
 
87
      engine that can only handle row-based logging. This is used in
 
88
      testing.
 
89
    */
 
90
    return HA_BINLOG_ROW_CAPABLE;
 
91
  }
 
92
 
 
93
  /** @brief
 
94
    This is a bitmap of flags that indicates how the storage engine
 
95
    implements indexes. The current index flags are documented in
 
96
    handler.h. If you do not implement indexes, just return zero here.
 
97
 
 
98
      @details
 
99
    part is the key part to check. First key part is 0.
 
100
    If all_parts is set, MySQL wants to know the flags for the combined
 
101
    index, up to and including 'part'.
 
102
  */
 
103
  ulong index_flags(uint inx, uint part, bool all_parts) const
 
104
  {
 
105
    return 0;
 
106
  }
 
107
 
 
108
  /** @brief
 
109
    unireg.cc will call max_supported_record_length(), max_supported_keys(),
 
110
    max_supported_key_parts(), uint max_supported_key_length()
 
111
    to make sure that the storage engine can handle the data it is about to
 
112
    send. Return *real* limits of your storage engine here; MySQL will do
 
113
    min(your_limits, MySQL_limits) automatically.
 
114
   */
 
115
  uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
 
116
 
 
117
  /** @brief
 
118
    unireg.cc will call this to make sure that the storage engine can handle
 
119
    the data it is about to send. Return *real* limits of your storage engine
 
120
    here; MySQL will do min(your_limits, MySQL_limits) automatically.
 
121
 
 
122
      @details
 
123
    There is no need to implement ..._key_... methods if your engine doesn't
 
124
    support indexes.
 
125
   */
 
126
  uint max_supported_keys()          const { return 0; }
 
127
 
 
128
  /** @brief
 
129
    unireg.cc will call this to make sure that the storage engine can handle
 
130
    the data it is about to send. Return *real* limits of your storage engine
 
131
    here; MySQL will do min(your_limits, MySQL_limits) automatically.
 
132
 
 
133
      @details
 
134
    There is no need to implement ..._key_... methods if your engine doesn't
 
135
    support indexes.
 
136
   */
 
137
  uint max_supported_key_parts()     const { return 0; }
 
138
 
 
139
  /** @brief
 
140
    unireg.cc will call this to make sure that the storage engine can handle
 
141
    the data it is about to send. Return *real* limits of your storage engine
 
142
    here; MySQL will do min(your_limits, MySQL_limits) automatically.
 
143
 
 
144
      @details
 
145
    There is no need to implement ..._key_... methods if your engine doesn't
 
146
    support indexes.
 
147
   */
 
148
  uint max_supported_key_length()    const { return 0; }
 
149
 
 
150
  /** @brief
 
151
    Called in test_quick_select to determine if indexes should be used.
 
152
  */
 
153
  virtual double scan_time() { return (double) (stats.records+stats.deleted) / 20.0+10; }
 
154
 
 
155
  /** @brief
 
156
    This method will never be called if you do not implement indexes.
 
157
  */
 
158
  virtual double read_time(ha_rows rows) { return (double) rows /  20.0+1; }
 
159
 
 
160
  /*
 
161
    Everything below are methods that we implement in ha_example.cc.
 
162
 
 
163
    Most of these methods are not obligatory, skip them and
 
164
    MySQL will treat them as not implemented
 
165
  */
 
166
  /** @brief
 
167
    We implement this in ha_example.cc; it's a required method.
 
168
  */
 
169
  int open(const char *name, int mode, uint test_if_locked);    // required
 
170
 
 
171
  /** @brief
 
172
    We implement this in ha_example.cc; it's a required method.
 
173
  */
 
174
  int close(void);                                              // required
 
175
 
 
176
  /** @brief
 
177
    We implement this in ha_example.cc. It's not an obligatory method;
 
178
    skip it and and MySQL will treat it as not implemented.
 
179
  */
 
180
  int write_row(uchar *buf);
 
181
 
 
182
  /** @brief
 
183
    We implement this in ha_example.cc. It's not an obligatory method;
 
184
    skip it and and MySQL will treat it as not implemented.
 
185
  */
 
186
  int update_row(const uchar *old_data, uchar *new_data);
 
187
 
 
188
  /** @brief
 
189
    We implement this in ha_example.cc. It's not an obligatory method;
 
190
    skip it and and MySQL will treat it as not implemented.
 
191
  */
 
192
  int delete_row(const uchar *buf);
 
193
 
 
194
  /** @brief
 
195
    We implement this in ha_example.cc. It's not an obligatory method;
 
196
    skip it and and MySQL will treat it as not implemented.
 
197
  */
 
198
  int index_read_map(uchar *buf, const uchar *key,
 
199
                     key_part_map keypart_map, enum ha_rkey_function find_flag);
 
200
 
 
201
  /** @brief
 
202
    We implement this in ha_example.cc. It's not an obligatory method;
 
203
    skip it and and MySQL will treat it as not implemented.
 
204
  */
 
205
  int index_next(uchar *buf);
 
206
 
 
207
  /** @brief
 
208
    We implement this in ha_example.cc. It's not an obligatory method;
 
209
    skip it and and MySQL will treat it as not implemented.
 
210
  */
 
211
  int index_prev(uchar *buf);
 
212
 
 
213
  /** @brief
 
214
    We implement this in ha_example.cc. It's not an obligatory method;
 
215
    skip it and and MySQL will treat it as not implemented.
 
216
  */
 
217
  int index_first(uchar *buf);
 
218
 
 
219
  /** @brief
 
220
    We implement this in ha_example.cc. It's not an obligatory method;
 
221
    skip it and and MySQL will treat it as not implemented.
 
222
  */
 
223
  int index_last(uchar *buf);
 
224
 
 
225
  /** @brief
 
226
    Unlike index_init(), rnd_init() can be called two consecutive times
 
227
    without rnd_end() in between (it only makes sense if scan=1). In this
 
228
    case, the second call should prepare for the new table scan (e.g if
 
229
    rnd_init() allocates the cursor, the second call should position the
 
230
    cursor to the start of the table; no need to deallocate and allocate
 
231
    it again. This is a required method.
 
232
  */
 
233
  int rnd_init(bool scan);                                      //required
 
234
  int rnd_end();
 
235
  int rnd_next(uchar *buf);                                     ///< required
 
236
  int rnd_pos(uchar *buf, uchar *pos);                          ///< required
 
237
  void position(const uchar *record);                           ///< required
 
238
  int info(uint);                                               ///< required
 
239
  int extra(enum ha_extra_function operation);
 
240
  int external_lock(THD *thd, int lock_type);                   ///< required
 
241
  int delete_all_rows(void);
 
242
  ha_rows records_in_range(uint inx, key_range *min_key,
 
243
                           key_range *max_key);
 
244
  int delete_table(const char *from);
 
245
  int rename_table(const char * from, const char * to);
 
246
  int create(const char *name, TABLE *form,
 
247
             HA_CREATE_INFO *create_info);                      ///< required
 
248
 
 
249
  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
 
250
                             enum thr_lock_type lock_type);     ///< required
 
251
};