~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Monty Taylor
  • Date: 2009-03-25 21:06:47 UTC
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090325210647-7j1tm98gvct3jxsu
Removed legacy_db_type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/session.h>
26
26
#include <drizzled/error.h>
27
27
#include <drizzled/gettext.h>
 
28
#include <map>
 
29
#include <string>
28
30
 
29
31
#include CSTDINT_H
30
32
 
31
 
/*
32
 
  While we have legacy_db_type, we have this array to
33
 
  check for dups and to find StorageEngine from legacy_db_type.
34
 
  Remove when legacy_db_type is finally gone
35
 
*/
 
33
using namespace std;
 
34
 
36
35
st_plugin_int *engine2plugin[MAX_HA];
37
36
 
38
 
static StorageEngine *installed_engines[128];
39
 
 
40
37
static const LEX_STRING sys_table_aliases[]=
41
38
{
42
39
  { C_STRING_WITH_LEN("INNOBASE") },  { C_STRING_WITH_LEN("INNODB") },
50
47
  return HA_ERR_NO_SUCH_TABLE;
51
48
}
52
49
 
53
 
StorageEngine *ha_resolve_by_legacy_type(Session *session,
54
 
                                      enum legacy_db_type db_type)
55
 
{
56
 
  plugin_ref plugin;
57
 
  switch (db_type) {
58
 
  case DB_TYPE_DEFAULT:
59
 
    return ha_default_storage_engine(session);
60
 
  default:
61
 
    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
62
 
        (plugin= ha_lock_engine(session, installed_engines[db_type])))
63
 
      return plugin_data(plugin, StorageEngine*);
64
 
    /* fall through */
65
 
  case DB_TYPE_UNKNOWN:
66
 
    return NULL;
67
 
  }
68
 
}
69
 
 
70
 
 
71
50
static plugin_ref ha_default_plugin(Session *session)
72
51
{
73
52
  if (session->variables.table_plugin)
159
138
}
160
139
 
161
140
 
162
 
/**
163
 
  Use other database handler if databasehandler is not compiled in.
164
 
*/
165
 
StorageEngine *ha_checktype(Session *session, enum legacy_db_type database_type,
166
 
                          bool no_substitute, bool report_error)
167
 
{
168
 
  StorageEngine *engine= ha_resolve_by_legacy_type(session, database_type);
169
 
  if (ha_storage_engine_is_enabled(engine))
170
 
    return engine;
171
 
 
172
 
  if (no_substitute)
173
 
  {
174
 
    if (report_error)
175
 
    {
176
 
      const char *engine_name= ha_resolve_storage_engine_name(engine);
177
 
      my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
178
 
    }
179
 
    return NULL;
180
 
  }
181
 
 
182
 
  return ha_default_storage_engine(session);
183
 
} /* ha_checktype */
184
 
 
185
 
 
186
141
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
187
142
                         StorageEngine *engine)
188
143
{
207
162
{
208
163
  StorageEngine *engine= static_cast<StorageEngine *>(plugin->data);
209
164
 
210
 
  switch (engine->state)
211
 
  {
212
 
  case SHOW_OPTION_NO:
213
 
  case SHOW_OPTION_DISABLED:
214
 
    break;
215
 
  case SHOW_OPTION_YES:
216
 
    if (installed_engines[engine->db_type] == engine)
217
 
      installed_engines[engine->db_type]= NULL;
218
 
    break;
219
 
  };
220
 
 
221
165
  if (engine && plugin->plugin->deinit)
222
166
    (void)plugin->plugin->deinit(engine);
223
167
 
251
195
  case SHOW_OPTION_YES:
252
196
    {
253
197
      uint32_t tmp;
254
 
      /* now check the db_type for conflict */
255
 
      if (engine->db_type <= DB_TYPE_UNKNOWN ||
256
 
          engine->db_type >= DB_TYPE_DEFAULT ||
257
 
          installed_engines[engine->db_type])
258
 
      {
259
 
        int idx= (int) DB_TYPE_FIRST_DYNAMIC;
260
 
 
261
 
        while (idx < (int) DB_TYPE_DEFAULT && installed_engines[idx])
262
 
          idx++;
263
 
 
264
 
        if (idx == (int) DB_TYPE_DEFAULT)
265
 
        {
266
 
          errmsg_printf(ERRMSG_LVL_WARN, _("Too many storage engines!"));
267
 
          return(1);
268
 
        }
269
 
        if (engine->db_type != DB_TYPE_UNKNOWN)
270
 
          errmsg_printf(ERRMSG_LVL_WARN,
271
 
                        _("Storage engine '%s' has conflicting typecode. Assigning value %d."),
272
 
                        plugin->plugin->name, idx);
273
 
        engine->db_type= (enum legacy_db_type) idx;
274
 
      }
275
 
      installed_engines[engine->db_type]= engine;
276
198
      tmp= engine->savepoint_offset;
277
199
      engine->savepoint_offset= savepoint_alloc_size;
278
200
      savepoint_alloc_size+= tmp;
305
227
  return(0);
306
228
}
307
229
 
308
 
enum legacy_db_type ha_legacy_type(const StorageEngine *db_type)
309
 
{
310
 
  return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
311
 
}
312
 
 
313
230
const char *ha_resolve_storage_engine_name(const StorageEngine *db_type)
314
231
{
315
232
  return db_type == NULL ? "UNKNOWN" : engine2plugin[db_type->slot]->name.str;
320
237
  return db_type == NULL ? false : db_type->flags.test(static_cast<size_t>(flag));
321
238
}
322
239
 
323
 
bool ha_storage_engine_is_enabled(const StorageEngine *db_type)
324
 
{
325
 
  return (db_type) ?
326
 
         (db_type->state == SHOW_OPTION_YES) : false;
327
 
}
328
240
 
329
241
LEX_STRING *ha_storage_engine_name(const StorageEngine *engine)
330
242
{