~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Brian Aker
  • Date: 2009-10-30 15:58:06 UTC
  • mfrom: (1183.1.30 merge)
  • Revision ID: brian@gaz-20091030155806-bq7mu2f5ljtodn0h
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "drizzled/memory/multi_malloc.h"
33
33
 
34
34
#include <string>
 
35
#include <map>
35
36
#include <algorithm>
36
37
 
37
38
using namespace std;
61
62
  MyisamEngine(string name_arg)
62
63
   : drizzled::plugin::StorageEngine(name_arg, 
63
64
                                     HTON_CAN_RECREATE | 
 
65
                                     HTON_HAS_DATA_DICTIONARY |
64
66
                                     HTON_TEMPORARY_ONLY | 
65
67
                                     HTON_FILE_BASED ) {}
66
68
 
 
69
  ~MyisamEngine()
 
70
  { }
 
71
 
67
72
  virtual Cursor *create(TableShare *table,
68
73
                          MEM_ROOT *mem_root)
69
74
  {
74
79
    return ha_myisam_exts;
75
80
  }
76
81
 
77
 
  int createTableImplementation(Session *, const char *table_name,
78
 
                                Table *table_arg,
79
 
                                HA_CREATE_INFO *ha_create_info,
80
 
                                drizzled::message::Table*);
81
 
 
82
 
  int renameTableImplementation(Session*, const char *from, const char *to);
83
 
 
84
 
  int deleteTableImplementation(Session*, const string table_name);
 
82
  int doCreateTable(Session *, const char *table_name,
 
83
                    Table& table_arg,
 
84
                    HA_CREATE_INFO& ha_create_info,
 
85
                    drizzled::message::Table&);
 
86
 
 
87
  int doRenameTable(Session*, const char *from, const char *to);
 
88
 
 
89
  int doDropTable(Session&, const string table_name);
 
90
 
 
91
  int doGetTableDefinition(Session& session,
 
92
                           const char* path,
 
93
                           const char *db,
 
94
                           const char *table_name,
 
95
                           const bool is_tmp,
 
96
                           drizzled::message::Table *table_proto);
 
97
 
 
98
  /* Temp only engine, so do not return values. */
 
99
  void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
 
100
 
85
101
};
86
102
 
 
103
int MyisamEngine::doGetTableDefinition(Session&,
 
104
                                       const char* path,
 
105
                                       const char *,
 
106
                                       const char *,
 
107
                                       const bool,
 
108
                                       drizzled::message::Table *table_proto)
 
109
{
 
110
  int error= 1;
 
111
  ProtoCache::iterator iter;
 
112
 
 
113
  pthread_mutex_lock(&proto_cache_mutex);
 
114
  iter= proto_cache.find(path);
 
115
 
 
116
  if (iter!= proto_cache.end())
 
117
  {
 
118
    if (table_proto)
 
119
      table_proto->CopyFrom(((*iter).second));
 
120
    error= EEXIST;
 
121
  }
 
122
  pthread_mutex_unlock(&proto_cache_mutex);
 
123
 
 
124
  return error;
 
125
}
 
126
 
87
127
/* 
88
128
  Convert to push_Warnings if you ever care about this, otherwise, it is a no-op.
89
129
*/
1278
1318
  return mi_delete_all_rows(file);
1279
1319
}
1280
1320
 
1281
 
int MyisamEngine::deleteTableImplementation(Session*, const string table_name)
 
1321
int MyisamEngine::doDropTable(Session&, const string table_path)
1282
1322
{
1283
 
  return mi_delete_table(table_name.c_str());
 
1323
  ProtoCache::iterator iter;
 
1324
 
 
1325
  pthread_mutex_lock(&proto_cache_mutex);
 
1326
  iter= proto_cache.find(table_path.c_str());
 
1327
 
 
1328
  if (iter!= proto_cache.end())
 
1329
    proto_cache.erase(iter);
 
1330
 
 
1331
  pthread_mutex_unlock(&proto_cache_mutex);
 
1332
 
 
1333
  return mi_delete_table(table_path.c_str());
1284
1334
}
1285
1335
 
1286
1336
 
1303
1353
  return to;
1304
1354
}
1305
1355
 
1306
 
int MyisamEngine::createTableImplementation(Session *, const char *table_name,
1307
 
                                            Table *table_arg,
1308
 
                                            HA_CREATE_INFO *ha_create_info,
1309
 
                                            drizzled::message::Table* create_proto)
 
1356
int MyisamEngine::doCreateTable(Session *, const char *table_name,
 
1357
                                Table& table_arg,
 
1358
                                HA_CREATE_INFO& ha_create_info,
 
1359
                                drizzled::message::Table& create_proto)
1310
1360
{
1311
1361
  int error;
1312
1362
  uint32_t create_flags= 0, create_records;
1314
1364
  MI_KEYDEF *keydef;
1315
1365
  MI_COLUMNDEF *recinfo;
1316
1366
  MI_CREATE_INFO create_info;
1317
 
  TableShare *share= table_arg->s;
 
1367
  TableShare *share= table_arg.s;
1318
1368
  uint32_t options= share->db_options_in_use;
1319
 
  if ((error= table2myisam(table_arg, &keydef, &recinfo, &create_records)))
 
1369
  if ((error= table2myisam(&table_arg, &keydef, &recinfo, &create_records)))
1320
1370
    return(error);
1321
1371
  memset(&create_info, 0, sizeof(create_info));
1322
 
  create_info.max_rows= create_proto->options().max_rows();
1323
 
  create_info.reloc_rows= create_proto->options().min_rows();
 
1372
  create_info.max_rows= create_proto.options().max_rows();
 
1373
  create_info.reloc_rows= create_proto.options().min_rows();
1324
1374
  create_info.with_auto_increment= share->next_number_key_offset == 0;
1325
 
  create_info.auto_increment= (ha_create_info->auto_increment_value ?
1326
 
                               ha_create_info->auto_increment_value -1 :
 
1375
  create_info.auto_increment= (ha_create_info.auto_increment_value ?
 
1376
                               ha_create_info.auto_increment_value -1 :
1327
1377
                               (uint64_t) 0);
1328
 
  create_info.data_file_length= (create_proto->options().max_rows() *
1329
 
                                 create_proto->options().avg_row_length());
 
1378
  create_info.data_file_length= (create_proto.options().max_rows() *
 
1379
                                 create_proto.options().avg_row_length());
1330
1380
  create_info.data_file_name= NULL;
1331
1381
  create_info.index_file_name=  NULL;
1332
1382
  create_info.language= share->table_charset->number;
1333
1383
 
1334
 
  if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE)
 
1384
  if (ha_create_info.options & HA_LEX_CREATE_TMP_TABLE)
1335
1385
    create_flags|= HA_CREATE_TMP_TABLE;
1336
 
  if (ha_create_info->options & HA_CREATE_KEEP_FILES)
 
1386
  if (ha_create_info.options & HA_CREATE_KEEP_FILES)
1337
1387
    create_flags|= HA_CREATE_KEEP_FILES;
1338
1388
  if (options & HA_OPTION_PACK_RECORD)
1339
1389
    create_flags|= HA_PACK_RECORD;
1346
1396
                   0, (MI_UNIQUEDEF*) 0,
1347
1397
                   &create_info, create_flags);
1348
1398
  free((unsigned char*) recinfo);
1349
 
  return(error);
 
1399
 
 
1400
  pthread_mutex_lock(&proto_cache_mutex);
 
1401
  proto_cache.insert(make_pair(table_name, create_proto));
 
1402
  pthread_mutex_unlock(&proto_cache_mutex);
 
1403
 
 
1404
  return error;
1350
1405
}
1351
1406
 
1352
1407
 
1353
 
int MyisamEngine::renameTableImplementation(Session*,
1354
 
                                            const char *from, const char *to)
 
1408
int MyisamEngine::doRenameTable(Session*,
 
1409
                                const char *from, const char *to)
1355
1410
{
1356
1411
  return mi_rename(from,to);
1357
1412
}