~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unireg.cc

  • Committer: Andrew Hutchings
  • Date: 2009-01-06 13:26:38 UTC
  • mfrom: (759 drizzle)
  • mto: (779.1.21 devel)
  • mto: This revision was merged to the branch mainline in revision 799.
  • Revision ID: linuxjedi@linuxjedi-laptop-20090106132638-gwo842uqbjz5ge1o
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
622
622
  return my_delete(new_path.c_str(), MYF(0));
623
623
}
624
624
 
625
 
int create_table_proto_file(char *file_name,
626
 
                            const char *table_name,
627
 
                            HA_CREATE_INFO *create_info,
628
 
                            List<Create_field> &create_fields,
629
 
                            uint32_t keys,
630
 
                            KEY *key_info)
 
625
bool create_table_proto_file(const char *file_name,
 
626
                             const char *table_name,
 
627
                             HA_CREATE_INFO *create_info,
 
628
                             List<Create_field> &create_fields,
 
629
                             uint32_t keys,
 
630
                             KEY *key_info)
631
631
{
632
 
  (void)key_info;
633
 
 
634
632
  drizzle::Table table_proto;
635
633
  string new_path(file_name);
636
634
  string file_ext = ".tabledefinition";
643
641
  fstream output(new_path.c_str(), ios::out | ios::trunc | ios::binary);
644
642
  if (!table_proto.SerializeToOstream(&output))
645
643
  {
646
 
    printf("Failed to write schema.\n");
647
644
    fprintf(stderr, "Failed to write schema.\n");
648
 
    return -1;
 
645
 
 
646
    return true;
649
647
  }
650
648
 
651
 
  return 0;
 
649
  return false;
652
650
}
653
651
 
654
652
/*
665
663
    keys                number of keys to create
666
664
    key_info            Keys to create
667
665
    file                Handler to use
 
666
    is_like             is true for mysql_create_like_schema_frm
668
667
 
669
668
  RETURN
670
669
    0  ok
675
674
                     const char *db, const char *table_name,
676
675
                     HA_CREATE_INFO *create_info,
677
676
                     List<Create_field> &create_fields,
678
 
                     uint32_t keys, KEY *key_info, handler *file)
 
677
                     uint32_t keys, KEY *key_info, handler *file,
 
678
                     bool is_like)
679
679
{
680
680
  char frm_name[FN_REFLEN];
681
 
  sprintf(frm_name,"%s%s",path,reg_ext);
682
 
  if (mysql_create_frm(session, frm_name, db, table_name, create_info,
683
 
                       create_fields, keys, key_info, file))
684
 
 
685
 
    return(1);
686
 
 
687
 
  if (create_table_proto_file(frm_name, table_name, create_info,
688
 
                              create_fields, keys, key_info) != 0)
689
 
    return 1;
 
681
 
 
682
  /* Proto will blow up unless we give a name */
 
683
  assert(table_name);
 
684
 
 
685
  /* For is_like we return once the file has been created */
 
686
  if (is_like)
 
687
  {
 
688
    if (mysql_create_frm(session, path, db, table_name, create_info,
 
689
                         create_fields, keys, key_info, file))
 
690
      return 1;
 
691
 
 
692
    if (create_table_proto_file(path, table_name, create_info,
 
693
                                create_fields, keys, key_info))
 
694
      return 1;
 
695
 
 
696
    return 0;
 
697
  }
 
698
  /* Here we need to build the full frm from the path */
 
699
  else
 
700
  {
 
701
    sprintf(frm_name,"%s%s", path, reg_ext);
 
702
 
 
703
    if (mysql_create_frm(session, frm_name, db, table_name, create_info,
 
704
                         create_fields, keys, key_info, file))
 
705
      return 1;
 
706
 
 
707
    if (create_table_proto_file(frm_name, table_name, create_info,
 
708
                                create_fields, keys, key_info))
 
709
      return 1;
 
710
  }
690
711
 
691
712
  // Make sure mysql_create_frm din't remove extension
692
713
  assert(*fn_rext(frm_name));
694
715
    create_info->options|= HA_CREATE_KEEP_FILES;
695
716
  if (file->ha_create_handler_files(path, NULL, CHF_CREATE_FLAG, create_info))
696
717
    goto err_handler;
697
 
  if ( ha_create_table(session, path, db, table_name,
698
 
                                                create_info,0))
 
718
  if (ha_create_table(session, path, db, table_name,
 
719
                      create_info,0))
699
720
    goto err_handler;
700
 
  return(0);
 
721
  return 0;
701
722
 
702
723
err_handler:
703
724
  file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info);
704
725
  my_delete(frm_name, MYF(0));
705
 
  return(1);
 
726
  delete_table_proto_file(frm_name);
 
727
 
 
728
  return 1;
706
729
} /* rea_create_table */
707
730
 
708
731