~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unireg.cc

  • Committer: Brian Aker
  • Date: 2009-02-02 18:19:36 UTC
  • mfrom: (820.1.14 nofrm)
  • Revision ID: brian@tangent.org-20090202181936-l03a2jb3vpndr1k3
Merge from Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <string>
34
34
#include <fstream>
35
35
#include <drizzled/serialize/serialize.h>
 
36
#include <drizzled/serialize/table.pb.h>
36
37
using namespace std;
37
38
 
38
39
#define FCOMP                   17              /* Bytes for a packed field */
88
89
  return is_handled;
89
90
}
90
91
 
91
 
int mysql_frm_type(char *path, enum legacy_db_type *dbt)
 
92
int drizzle_read_table_proto(const char* path, drizzle::Table* table)
92
93
{
93
 
  int file;
94
 
  unsigned char header[10];
95
 
  int error;
96
 
 
97
 
  *dbt= DB_TYPE_UNKNOWN;
98
 
 
99
 
  file= open(path, O_RDONLY);
100
 
 
101
 
  if(file < 1)
102
 
    return 1;
103
 
 
104
 
  error= read(file, header, sizeof(header));
105
 
  close(file);
106
 
 
107
 
  if (error!=sizeof(header))
108
 
    return 1;
109
 
 
110
 
  /*
111
 
    This is just a check for DB_TYPE. We'll return default unknown type
112
 
    if the following test is true (arg #3). This should not have effect
113
 
    on return value from this function (default FRMTYPE_TABLE)
114
 
  */
115
 
  if (header[0] != (unsigned char)254 || header[1] != 1 ||
116
 
      (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
117
 
       (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
118
 
    return 0;
119
 
 
120
 
  *dbt= (enum legacy_db_type) (uint) *(header + 3);
 
94
  {
 
95
    fstream input(path, ios::in | ios::binary);
 
96
    if (!table->ParseFromIstream(&input))
 
97
    {
 
98
      return 1;
 
99
    }
 
100
  }
121
101
  return 0;
122
102
}
123
103
 
481
461
        {
482
462
          const char *src= field_arg->interval->type_names[pos];
483
463
 
484
 
          set_field_options->add_value(src);
 
464
          set_field_options->add_field_value(src);
485
465
        }
486
 
        set_field_options->set_count_elements(set_field_options->value_size());
 
466
        set_field_options->set_count_elements(set_field_options->field_value_size());
487
467
        break;
488
468
      }
489
469
    case DRIZZLE_TYPE_BLOB:
503
483
      attribute->set_comment(field_arg->comment.str);
504
484
  }
505
485
 
 
486
  if (create_info->used_fields & HA_CREATE_USED_PACK_KEYS)
 
487
  {
 
488
    if(create_info->table_options & HA_OPTION_PACK_KEYS)
 
489
      table_options->set_pack_keys(true);
 
490
    else if(create_info->table_options & HA_OPTION_NO_PACK_KEYS)
 
491
      table_options->set_pack_keys(false);
 
492
  }
 
493
 
 
494
  if (create_info->used_fields & HA_CREATE_USED_CHECKSUM)
 
495
  {
 
496
    assert(create_info->table_options & (HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM));
 
497
 
 
498
    if(create_info->table_options & HA_OPTION_CHECKSUM)
 
499
      table_options->set_checksum(true);
 
500
    else
 
501
      table_options->set_checksum(false);
 
502
  }
 
503
 
 
504
  if (create_info->used_fields & HA_CREATE_USED_PAGE_CHECKSUM)
 
505
  {
 
506
    if (create_info->page_checksum == HA_CHOICE_YES)
 
507
      table_options->set_page_checksum(true);
 
508
    else if (create_info->page_checksum == HA_CHOICE_NO)
 
509
      table_options->set_page_checksum(false);
 
510
  }
 
511
 
 
512
  if (create_info->used_fields & HA_CREATE_USED_DELAY_KEY_WRITE)
 
513
  {
 
514
    if(create_info->table_options & HA_OPTION_DELAY_KEY_WRITE)
 
515
      table_options->set_delay_key_write(true);
 
516
    else if(create_info->table_options & HA_OPTION_NO_DELAY_KEY_WRITE)
 
517
      table_options->set_delay_key_write(false);
 
518
  }
 
519
 
 
520
  switch(create_info->row_type)
 
521
  {
 
522
  case ROW_TYPE_DEFAULT:
 
523
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_DEFAULT);
 
524
    break;
 
525
  case ROW_TYPE_FIXED:
 
526
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_FIXED);
 
527
    break;
 
528
  case ROW_TYPE_DYNAMIC:
 
529
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_DYNAMIC);
 
530
    break;
 
531
  case ROW_TYPE_COMPRESSED:
 
532
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_COMPRESSED);
 
533
    break;
 
534
  case ROW_TYPE_REDUNDANT:
 
535
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_REDUNDANT);
 
536
    break;
 
537
  case ROW_TYPE_COMPACT:
 
538
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_COMPACT);
 
539
    break;
 
540
  case ROW_TYPE_PAGE:
 
541
    table_options->set_row_type(drizzle::Table::TableOptions::ROW_TYPE_PAGE);
 
542
    break;
 
543
  default:
 
544
    abort();
 
545
  }
 
546
 
506
547
  if (create_info->comment.length)
507
548
    table_options->set_comment(create_info->comment.str);
508
549
 
509
 
  if (create_info->table_charset)
 
550
  if (create_info->default_table_charset)
510
551
  {
511
 
    table_options->set_collation_id(field_arg->charset->number);
512
 
    table_options->set_collation(field_arg->charset->name);
 
552
    table_options->set_collation_id(
 
553
                               create_info->default_table_charset->number);
 
554
    table_options->set_collation(create_info->default_table_charset->name);
513
555
  }
514
556
 
515
557
  if (create_info->connect_string.length)
543
585
  {
544
586
    drizzle::Table::Index *idx;
545
587
 
546
 
    idx= table_proto->add_index();
 
588
    idx= table_proto->add_indexes();
547
589
 
548
590
    assert(test(key_info[i].flags & HA_USES_COMMENT) ==
549
591
           (key_info[i].comment.length > 0));
613
655
  return my_rename(from_path.c_str(),to_path.c_str(),MYF(MY_WME));
614
656
}
615
657
 
616
 
int delete_table_proto_file(char *file_name)
 
658
int delete_table_proto_file(const char *file_name)
617
659
{
618
660
  string new_path(file_name);
619
661
  string file_ext = ".dfe";
723
765
err_handler:
724
766
  file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info);
725
767
  my_delete(frm_name, MYF(0));
726
 
  delete_table_proto_file(frm_name);
 
768
 
 
769
  delete_table_proto_file(path);
727
770
 
728
771
  return 1;
729
772
} /* rea_create_table */