~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_create.c

  • Committer: Monty Taylor
  • Date: 2008-07-24 22:51:52 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080724225152-1t1vnoj93kr9tb39
Added very initial gettextize stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* Create a MyISAM table */
17
17
 
18
18
#include "myisamdef.h"
19
 
#include <mysys/my_tree.h>
20
 
#include <mysys/queues.h>
21
 
#include <mysys/my_bit.h>
 
19
#include <m_ctype.h>
 
20
#include <my_tree.h>
 
21
#include <queues.h>
 
22
#include <my_bit.h>
22
23
 
23
 
#include <drizzled/util/test.h>
 
24
#include <m_ctype.h>
24
25
 
25
26
/*
26
27
  Old options is used when recreating database, from myisamchk
27
28
*/
28
29
 
29
 
int mi_create(const char *name,uint32_t keys,MI_KEYDEF *keydefs,
30
 
              uint32_t columns, MI_COLUMNDEF *recinfo,
31
 
              uint32_t uniques, MI_UNIQUEDEF *uniquedefs,
32
 
              MI_CREATE_INFO *ci,uint32_t flags)
 
30
int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
 
31
              uint columns, MI_COLUMNDEF *recinfo,
 
32
              uint uniques, MI_UNIQUEDEF *uniquedefs,
 
33
              MI_CREATE_INFO *ci,uint flags)
33
34
{
34
 
  register uint32_t i, j;
35
 
  File dfile= 0, file= 0;
 
35
  register uint i, j;
 
36
  File dfile= 0, file;
36
37
  int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
37
38
  myf create_flag;
38
 
  uint32_t fields,length,max_key_length,packed,pointer,real_length_diff,
 
39
  uint fields,length,max_key_length,packed,pointer,real_length_diff,
39
40
       key_length,info_length,key_segs,options,min_key_length_skip,
40
41
       base_pos,long_varchar_count,varchar_length,
41
42
       max_key_block_length,unique_key_parts,fulltext_keys,offset;
42
 
  uint32_t aligned_key_start, block_length;
 
43
  uint aligned_key_start, block_length;
43
44
  ulong reclength, real_reclength,min_pack_length;
44
45
  char filename[FN_REFLEN],linkname[FN_REFLEN], *linkname_ptr;
45
46
  ulong pack_reclength;
56
57
 
57
58
  if (!ci)
58
59
  {
59
 
    memset(&tmp_create_info, 0, sizeof(tmp_create_info));
 
60
    bzero((char*) &tmp_create_info,sizeof(tmp_create_info));
60
61
    ci=&tmp_create_info;
61
62
  }
62
63
 
66
67
  }
67
68
  errpos= 0;
68
69
  options= 0;
69
 
  memset(&share, 0, sizeof(share));
 
70
  bzero((uchar*) &share,sizeof(share));
70
71
 
71
72
  if (flags & HA_DONT_TOUCH_DATA)
72
73
  {
170
171
  if (flags & HA_CREATE_TMP_TABLE)
171
172
  {
172
173
    options|= HA_OPTION_TMP_TABLE;
173
 
    create_mode|= O_EXCL;
 
174
    create_mode|= O_EXCL | O_NOFOLLOW;
174
175
  }
175
176
  if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM))
176
177
  {
355
356
    block_length= (keydef->block_length ? 
356
357
                   my_round_up_to_next_power(keydef->block_length) :
357
358
                   myisam_block_size);
358
 
    block_length= cmax(block_length, MI_MIN_KEY_BLOCK_LENGTH);
359
 
    block_length= cmin(block_length, MI_MAX_KEY_BLOCK_LENGTH);
 
359
    block_length= max(block_length, MI_MIN_KEY_BLOCK_LENGTH);
 
360
    block_length= min(block_length, MI_MAX_KEY_BLOCK_LENGTH);
360
361
 
361
362
    keydef->block_length= (uint16_t) MI_BLOCK_SIZE(length-real_length_diff,
362
363
                                                 pointer,MI_MAX_KEYPTR_SIZE,
414
415
    goto err;
415
416
  }
416
417
 
417
 
  memcpy(share.state.header.file_version,myisam_file_magic,4);
 
418
  bmove(share.state.header.file_version,(uchar*) myisam_file_magic,4);
418
419
  ci->old_options=options| (ci->old_options & HA_OPTION_TEMP_COMPRESS_RECORD ?
419
420
                        HA_OPTION_COMPRESS_RECORD |
420
421
                        HA_OPTION_TEMP_COMPRESS_RECORD: 0);
432
433
  share.state.unique=   (ulong) 0;
433
434
  share.state.update_count=(ulong) 0;
434
435
  share.state.version=  (ulong) time((time_t*) 0);
435
 
  share.state.sortkey=  UINT16_MAX;
 
436
  share.state.sortkey=  (ushort) ~0;
436
437
  share.state.auto_increment=ci->auto_increment;
437
438
  share.options=options;
438
439
  share.base.rec_reflength=pointer;
444
445
    got from MYI file header (see also myisampack.c:save_state)
445
446
  */
446
447
  share.base.key_reflength=
447
 
    mi_get_pointer_length(cmax(ci->key_file_length,tmp),3);
 
448
    mi_get_pointer_length(max(ci->key_file_length,tmp),3);
448
449
  share.base.keys= share.state.header.keys= keys;
449
450
  share.state.header.uniques= uniques;
450
451
  share.state.header.fulltext_keys= fulltext_keys;
477
478
  share.base.min_block_length=
478
479
    (share.base.pack_reclength+3 < MI_EXTEND_BLOCK_LENGTH &&
479
480
     ! share.base.blobs) ?
480
 
    cmax(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
 
481
    max(share.base.pack_reclength,MI_MIN_BLOCK_LENGTH) :
481
482
    MI_EXTEND_BLOCK_LENGTH;
482
483
  if (! (flags & HA_DONT_TOUCH_DATA))
483
484
    share.state.create_time= (long) time((time_t*) 0);
604
605
  /* Write key and keyseg definitions */
605
606
  for (i=0 ; i < share.base.keys - uniques; i++)
606
607
  {
607
 
    uint32_t sp_segs= 0;
 
608
    uint sp_segs= 0;
608
609
 
609
610
    if (mi_keydef_write(file, &keydefs[i]))
610
611
      goto err;
614
615
  }
615
616
  /* Create extra keys for unique definitions */
616
617
  offset=reclength-uniques*MI_UNIQUE_HASH_LENGTH;
617
 
  memset(&tmp_keydef, 0, sizeof(tmp_keydef));
618
 
  memset(&tmp_keyseg, 0, sizeof(tmp_keyseg));
 
618
  bzero((char*) &tmp_keydef,sizeof(tmp_keydef));
 
619
  bzero((char*) &tmp_keyseg,sizeof(tmp_keyseg));
619
620
  for (i=0; i < uniques ; i++)
620
621
  {
621
622
    tmp_keydef.keysegs=1;
685
686
  pthread_mutex_unlock(&THR_LOCK_myisam);
686
687
  if (my_close(file,MYF(0)))
687
688
    goto err;
688
 
  free((char*) rec_per_key_part);
 
689
  my_free((char*) rec_per_key_part,MYF(0));
689
690
  return(0);
690
691
 
691
692
err:
693
694
  save_errno=my_errno;
694
695
  switch (errpos) {
695
696
  case 3:
696
 
    my_close(dfile,MYF(0));
 
697
    VOID(my_close(dfile,MYF(0)));
697
698
    /* fall through */
698
699
  case 2:
 
700
    /* QQ: T�nu should add a call to my_raid_delete() here */
699
701
  if (! (flags & HA_DONT_TOUCH_DATA))
700
702
    my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT,
701
703
                                     MY_UNPACK_FILENAME | MY_APPEND_EXT),
702
704
                           MYF(0));
703
705
    /* fall through */
704
706
  case 1:
705
 
    my_close(file,MYF(0));
 
707
    VOID(my_close(file,MYF(0)));
706
708
    if (! (flags & HA_DONT_TOUCH_DATA))
707
709
      my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT,
708
710
                                       MY_UNPACK_FILENAME | MY_APPEND_EXT),
709
711
                             MYF(0));
710
712
  }
711
 
  free((char*) rec_per_key_part);
 
713
  my_free((char*) rec_per_key_part, MYF(0));
712
714
  return(my_errno=save_errno);          /* return the fatal errno */
713
715
}
714
716
 
715
717
 
716
 
uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def)
 
718
uint mi_get_pointer_length(uint64_t file_length, uint def)
717
719
{
718
720
  assert(def >= 2 && def <= 7);
719
721
  if (file_length)                              /* If not default */