~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.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:
39
39
 
40
40
namespace drizzled {
41
41
 
42
 
int fill_table_proto(message::Table *table_proto,
43
 
                     const char *table_name,
44
 
                     List<CreateField> &create_fields,
45
 
                     HA_CREATE_INFO *create_info,
46
 
                     uint32_t keys,
47
 
                     KEY *key_info)
 
42
static int fill_table_proto(message::Table &table_proto,
 
43
                            const char *table_name,
 
44
                            List<CreateField> &create_fields,
 
45
                            HA_CREATE_INFO *create_info,
 
46
                            uint32_t keys,
 
47
                            KEY *key_info)
48
48
{
49
49
  CreateField *field_arg;
50
50
  List_iterator<CreateField> it(create_fields);
51
 
  message::Table::TableOptions *table_options= table_proto->mutable_options();
 
51
  message::Table::TableOptions *table_options= table_proto.mutable_options();
52
52
 
53
53
  if (create_fields.elements > MAX_FIELDS)
54
54
  {
56
56
    return(1);
57
57
  }
58
58
 
59
 
  assert(strcmp(table_proto->engine().name().c_str(),
 
59
  assert(strcmp(table_proto.engine().name().c_str(),
60
60
                create_info->db_type->getName().c_str())==0);
61
61
 
62
 
  assert(strcmp(table_proto->name().c_str(),table_name)==0);
 
62
  assert(strcmp(table_proto.name().c_str(),table_name)==0);
63
63
 
64
64
  int field_number= 0;
65
 
  bool use_existing_fields= table_proto->field_size() > 0;
 
65
  bool use_existing_fields= table_proto.field_size() > 0;
66
66
  while ((field_arg= it++))
67
67
  {
68
68
    message::Table::Field *attribute;
72
72
       filled out Field messages */
73
73
 
74
74
    if (use_existing_fields)
75
 
      attribute= table_proto->mutable_field(field_number++);
 
75
      attribute= table_proto.mutable_field(field_number++);
76
76
    else
77
77
    {
78
78
      /* Other code paths still have to fill out the proto */
79
 
      attribute= table_proto->add_field();
 
79
      attribute= table_proto.add_field();
80
80
 
81
81
      if(field_arg->flags & NOT_NULL_FLAG)
82
82
      {
304
304
 
305
305
  }
306
306
 
307
 
  assert(! use_existing_fields || (field_number == table_proto->field_size()));
 
307
  assert(! use_existing_fields || (field_number == table_proto.field_size()));
308
308
 
309
309
  switch(create_info->row_type)
310
310
  {
364
364
  if (create_info->auto_increment_value)
365
365
    table_options->set_auto_increment_value(create_info->auto_increment_value);
366
366
 
367
 
  for (unsigned int i= 0; i < keys; i++)
 
367
  for (uint32_t i= 0; i < keys; i++)
368
368
  {
369
369
    message::Table::Index *idx;
370
370
 
371
 
    idx= table_proto->add_indexes();
 
371
    idx= table_proto.add_indexes();
372
372
 
373
373
    assert(test(key_info[i].flags & HA_USES_COMMENT) ==
374
374
           (key_info[i].comment.length > 0));
492
492
  return internal::my_delete(new_path.c_str(), MYF(0));
493
493
}
494
494
 
495
 
int drizzle_write_proto_file(const std::string file_name,
496
 
                             message::Table *table_proto)
497
 
{
498
 
  int fd= open(file_name.c_str(), O_RDWR|O_CREAT|O_TRUNC, internal::my_umask);
499
 
 
500
 
  if (fd == -1)
501
 
    return errno;
502
 
 
503
 
  google::protobuf::io::ZeroCopyOutputStream* output=
504
 
    new google::protobuf::io::FileOutputStream(fd);
505
 
 
506
 
  if (table_proto->SerializeToZeroCopyStream(output) == false)
507
 
  {
508
 
    delete output;
509
 
    close(fd);
510
 
    return errno;
511
 
  }
512
 
 
513
 
  delete output;
514
 
  close(fd);
515
 
  return 0;
516
 
}
517
 
 
518
495
/*
519
496
  Create a table definition proto file and the tables
520
497
 
536
513
 
537
514
int rea_create_table(Session *session,
538
515
                     TableIdentifier &identifier,
539
 
                     message::Table *table_proto,
 
516
                     message::Table &table_proto,
540
517
                     HA_CREATE_INFO *create_info,
541
518
                     List<CreateField> &create_fields,
542
519
                     uint32_t keys, KEY *key_info)
545
522
                      keys, key_info))
546
523
    return 1;
547
524
 
548
 
  string new_path(identifier.getPath());
549
 
  string file_ext = ".dfe";
550
 
 
551
 
  new_path.append(file_ext);
552
 
 
553
 
  int err= 0;
554
 
 
555
 
  plugin::StorageEngine* engine= plugin::StorageEngine::findByName(*session,
556
 
                                                                   table_proto->engine().name());
557
 
  if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY) == false)
558
 
    err= drizzle_write_proto_file(new_path, table_proto);
559
 
 
560
 
  if (err != 0)
561
 
  {
562
 
    if (err == ENOENT)
563
 
      my_error(ER_BAD_DB_ERROR,MYF(0), identifier.getDBName());
564
 
    else
565
 
      my_error(ER_CANT_CREATE_TABLE, MYF(0), identifier.getTableName(), err);
566
 
 
567
 
    goto err_handler;
568
 
  }
569
 
 
570
525
  if (plugin::StorageEngine::createTable(*session,
571
526
                                         identifier,
572
 
                                         false, *table_proto))
 
527
                                         false, table_proto))
573
528
  {
574
 
    goto err_handler;
 
529
    return 1;
575
530
  }
576
531
 
577
532
  return 0;
578
533
 
579
 
err_handler:
580
 
  if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY) == false)
581
 
    plugin::StorageEngine::deleteDefinitionFromPath(identifier);
582
 
 
583
 
  return 1;
584
534
} /* rea_create_table */
585
535
 
586
536
} /* namespace drizzled */