~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Brian Aker
  • Date: 2010-03-04 08:33:14 UTC
  • mfrom: (1320.1.12 build)
  • Revision ID: brian@gaz-20100304083314-pscg89hdw618s2j5
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
  const char *db;
310
310
  const char *table_name;
311
311
  const bool is_tmp;
312
 
  message::Table *table_proto;
 
312
  message::Table *table_message;
313
313
  int *err;
314
314
 
315
315
public:
318
318
                                  const char *db_arg,
319
319
                                  const char *table_name_arg,
320
320
                                  const bool is_tmp_arg,
321
 
                                  message::Table *table_proto_arg,
 
321
                                  message::Table *table_message_arg,
322
322
                                  int *err_arg) :
323
323
    session(session_arg), 
324
324
    path(path_arg), 
325
325
    db(db_arg),
326
326
    table_name(table_name_arg),
327
327
    is_tmp(is_tmp_arg),
328
 
    table_proto(table_proto_arg), 
 
328
    table_message(table_message_arg), 
329
329
    err(err_arg) {}
330
330
 
331
331
  result_type operator() (argument_type engine)
335
335
                                          db,
336
336
                                          table_name,
337
337
                                          is_tmp,
338
 
                                          table_proto);
 
338
                                          table_message);
339
339
 
340
340
    if (ret != ENOENT)
341
341
      *err= ret;
361
361
*/
362
362
int StorageEngine::getTableDefinition(Session& session,
363
363
                                      TableIdentifier &identifier,
364
 
                                      message::Table *table_proto,
 
364
                                      message::Table *table_message,
365
365
                                      bool include_temporary_tables)
366
366
{
367
367
  return getTableDefinition(session,
368
368
                            identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
369
 
                            table_proto, include_temporary_tables);
 
369
                            table_message, include_temporary_tables);
370
370
}
371
371
 
372
372
int StorageEngine::getTableDefinition(Session& session,
374
374
                                              const char *schema_name,
375
375
                                              const char *table_name,
376
376
                                              const bool,
377
 
                                              message::Table *table_proto,
 
377
                                              message::Table *table_message,
378
378
                                              bool include_temporary_tables)
379
379
{
380
380
  int err= ENOENT;
381
381
 
382
382
  if (include_temporary_tables)
383
383
  {
384
 
    if (session.doGetTableDefinition(path, schema_name, table_name, false, table_proto) == EEXIST)
 
384
    if (session.doGetTableDefinition(path, schema_name, table_name, false, table_message) == EEXIST)
385
385
      return EEXIST;
386
386
  }
387
387
 
388
388
  EngineVector::iterator iter=
389
389
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
390
 
            StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_proto, &err));
 
390
            StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_message, &err));
391
391
 
392
392
  if (iter == vector_of_engines.end())
393
393
  {
514
514
   @todo refactor to remove goto
515
515
*/
516
516
int StorageEngine::createTable(Session& session,
517
 
                                       TableIdentifier &identifier,
518
 
                                       bool update_create_info,
519
 
                                       message::Table& table_proto, bool proto_used)
 
517
                               TableIdentifier &identifier,
 
518
                               bool update_create_info,
 
519
                               message::Table& table_message)
520
520
{
521
521
  int error= 1;
522
522
  Table table;
523
523
  TableShare share(identifier.getDBName(), 0, identifier.getTableName(), identifier.getPath());
524
524
  message::Table tmp_proto;
525
525
 
526
 
  if (proto_used)
527
 
  {
528
 
    if (parse_table_proto(session, table_proto, &share))
529
 
      goto err;
530
 
  }
531
 
  else
532
 
  {
533
 
    if (open_table_def(session, &share))
534
 
      goto err;
535
 
  }
 
526
  if (parse_table_proto(session, table_message, &share))
 
527
    goto err;
536
528
 
537
529
  if (open_table_from_share(&session, &share, "", 0, 0,
538
530
                            &table))
539
531
    goto err;
540
532
 
541
533
  if (update_create_info)
542
 
    table.updateCreateInfo(&table_proto);
 
534
    table.updateCreateInfo(&table_message);
543
535
 
544
536
  /* Check for legal operations against the Engine using the proto (if used) */
545
 
  if (proto_used)
546
 
  {
547
 
    if (table_proto.type() == message::Table::TEMPORARY &&
548
 
        share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
549
 
    {
550
 
      error= HA_ERR_UNSUPPORTED;
551
 
      goto err2;
552
 
    }
553
 
    else if (table_proto.type() != message::Table::TEMPORARY &&
554
 
             share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
555
 
    {
556
 
      error= HA_ERR_UNSUPPORTED;
557
 
      goto err2;
558
 
    }
 
537
  if (table_message.type() == message::Table::TEMPORARY &&
 
538
      share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
 
539
  {
 
540
    error= HA_ERR_UNSUPPORTED;
 
541
    goto err2;
 
542
  }
 
543
  else if (table_message.type() != message::Table::TEMPORARY &&
 
544
           share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
 
545
  {
 
546
    error= HA_ERR_UNSUPPORTED;
 
547
    goto err2;
559
548
  }
560
549
 
561
550
  {
564
553
 
565
554
    table_name_arg= share.storage_engine->checkLowercaseNames(identifier.getPath(), name_buff);
566
555
 
 
556
    if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
557
    {
 
558
      int protoerr= StorageEngine::writeDefinitionFromPath(identifier, table_message);
 
559
 
 
560
      if (protoerr)
 
561
      {
 
562
        error= protoerr;
 
563
        goto err2;
 
564
      }
 
565
    }
 
566
 
567
567
    share.storage_engine->setTransactionReadWrite(session);
568
568
 
569
569
    error= share.storage_engine->doCreateTable(&session,
570
570
                                               table_name_arg,
571
571
                                               table,
572
 
                                               table_proto);
 
572
                                               table_message);
573
573
  }
574
574
 
575
575
err2:
 
576
  if (error)
 
577
  {
 
578
    if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
579
      plugin::StorageEngine::deleteDefinitionFromPath(identifier);
 
580
 
 
581
    my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
 
582
  }
 
583
 
576
584
  table.closefrm(false);
577
585
 
578
 
  if (error)
579
 
  {
580
 
    char name_buff[FN_REFLEN];
581
 
    sprintf(name_buff,"%s.%s", identifier.getDBName(), identifier.getTableName());
582
 
    my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
583
 
  }
584
586
err:
585
587
  share.free_table_share();
586
588
  return(error != 0);
1230
1232
  return internal::my_rename(src_path.c_str(), dest_path.c_str(), MYF(MY_WME));
1231
1233
}
1232
1234
 
1233
 
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_proto)
 
1235
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_message)
1234
1236
{
1235
1237
  string file_name(identifier.getPath());
1236
1238
 
1244
1246
  google::protobuf::io::ZeroCopyOutputStream* output=
1245
1247
    new google::protobuf::io::FileOutputStream(fd);
1246
1248
 
1247
 
  if (table_proto.SerializeToZeroCopyStream(output) == false)
 
1249
  if (table_message.SerializeToZeroCopyStream(output) == false)
1248
1250
  {
1249
1251
    delete output;
1250
1252
    close(fd);
1256
1258
  return 0;
1257
1259
}
1258
1260
 
 
1261
class CanCreateTable: public unary_function<StorageEngine *, bool>
 
1262
{
 
1263
  const TableIdentifier &identifier;
 
1264
 
 
1265
public:
 
1266
  CanCreateTable(const TableIdentifier &identifier_arg) :
 
1267
    identifier(identifier_arg)
 
1268
  { }
 
1269
 
 
1270
  result_type operator() (argument_type engine)
 
1271
  {
 
1272
    return not engine->doCanCreateTable(identifier);
 
1273
  }
 
1274
};
 
1275
 
 
1276
 
 
1277
/**
 
1278
  @note on success table can be created.
 
1279
*/
 
1280
bool StorageEngine::canCreateTable(drizzled::TableIdentifier &identifier)
 
1281
{
 
1282
  EngineVector::iterator iter=
 
1283
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
1284
            CanCreateTable(identifier));
 
1285
 
 
1286
  if (iter == vector_of_engines.end())
 
1287
  {
 
1288
    return true;
 
1289
  }
 
1290
 
 
1291
  return false;
 
1292
}
 
1293
 
1259
1294
} /* namespace plugin */
1260
1295
} /* namespace drizzled */