~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/myisam/mi_test1.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* Testing of the basic functions of a MyISAM table */
 
17
 
 
18
#include "myisam.h"
 
19
#include <my_getopt.h>
 
20
#include <m_string.h>
 
21
 
 
22
#define MAX_REC_LENGTH 1024
 
23
 
 
24
static void usage();
 
25
 
 
26
static int rec_pointer_size=0, flags[50];
 
27
static int key_field=FIELD_SKIP_PRESPACE,extra_field=FIELD_SKIP_ENDSPACE;
 
28
static int key_type=HA_KEYTYPE_NUM;
 
29
static int create_flag=0;
 
30
 
 
31
static uint insert_count, update_count, remove_count;
 
32
static uint pack_keys=0, pack_seg=0, key_length;
 
33
static uint unique_key=HA_NOSAME;
 
34
static my_bool key_cacheing, null_fields, silent, skip_update, opt_unique,
 
35
               verbose;
 
36
static MI_COLUMNDEF recinfo[4];
 
37
static MI_KEYDEF keyinfo[10];
 
38
static HA_KEYSEG keyseg[10];
 
39
static HA_KEYSEG uniqueseg[10];
 
40
 
 
41
static int run_test(const char *filename);
 
42
static void get_options(int argc, char *argv[]);
 
43
static void create_key(uchar *key,uint rownr);
 
44
static void create_record(uchar *record,uint rownr);
 
45
static void update_record(uchar *record);
 
46
 
 
47
int main(int argc,char *argv[])
 
48
{
 
49
  MY_INIT(argv[0]);
 
50
  my_init();
 
51
  if (key_cacheing)
 
52
    init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,IO_SIZE*16,0,0);
 
53
  get_options(argc,argv);
 
54
 
 
55
  exit(run_test("test1"));
 
56
}
 
57
 
 
58
 
 
59
static int run_test(const char *filename)
 
60
{
 
61
  MI_INFO *file;
 
62
  int i,j,error,deleted,rec_length,uniques=0;
 
63
  ha_rows found,row_count;
 
64
  my_off_t pos;
 
65
  uchar record[MAX_REC_LENGTH],key[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH];
 
66
  MI_UNIQUEDEF uniquedef;
 
67
  MI_CREATE_INFO create_info;
 
68
 
 
69
  bzero((char*) recinfo,sizeof(recinfo));
 
70
 
 
71
  /* First define 2 columns */
 
72
  recinfo[0].type=FIELD_NORMAL; recinfo[0].length=1; /* For NULL bits */
 
73
  recinfo[1].type=key_field;
 
74
  recinfo[1].length= (key_field == FIELD_BLOB ? 4+portable_sizeof_char_ptr :
 
75
                      key_length);
 
76
  if (key_field == FIELD_VARCHAR)
 
77
    recinfo[1].length+= HA_VARCHAR_PACKLENGTH(key_length);;
 
78
  recinfo[2].type=extra_field;
 
79
  recinfo[2].length= (extra_field == FIELD_BLOB ? 4 + portable_sizeof_char_ptr : 24);
 
80
  if (extra_field == FIELD_VARCHAR)
 
81
    recinfo[2].length+= HA_VARCHAR_PACKLENGTH(recinfo[2].length);
 
82
  if (opt_unique)
 
83
  {
 
84
    recinfo[3].type=FIELD_CHECK;
 
85
    recinfo[3].length=MI_UNIQUE_HASH_LENGTH;
 
86
  }
 
87
  rec_length=recinfo[0].length+recinfo[1].length+recinfo[2].length+
 
88
    recinfo[3].length;
 
89
 
 
90
  if (key_type == HA_KEYTYPE_VARTEXT1 &&
 
91
      key_length > 255)
 
92
    key_type= HA_KEYTYPE_VARTEXT2;
 
93
 
 
94
  /* Define a key over the first column */
 
95
  keyinfo[0].seg=keyseg;
 
96
  keyinfo[0].keysegs=1;
 
97
  keyinfo[0].block_length= 0;                   /* Default block length */
 
98
  keyinfo[0].key_alg=HA_KEY_ALG_BTREE;
 
99
  keyinfo[0].seg[0].type= key_type;
 
100
  keyinfo[0].seg[0].flag= pack_seg;
 
101
  keyinfo[0].seg[0].start=1;
 
102
  keyinfo[0].seg[0].length=key_length;
 
103
  keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0;
 
104
  keyinfo[0].seg[0].null_pos=0;
 
105
  keyinfo[0].seg[0].language= default_charset_info->number;
 
106
  if (pack_seg & HA_BLOB_PART)
 
107
  {
 
108
    keyinfo[0].seg[0].bit_start=4;              /* Length of blob length */
 
109
  }
 
110
  keyinfo[0].flag = (uint8) (pack_keys | unique_key);
 
111
 
 
112
  bzero((uchar*) flags,sizeof(flags));
 
113
  if (opt_unique)
 
114
  {
 
115
    uint start;
 
116
    uniques=1;
 
117
    bzero((char*) &uniquedef,sizeof(uniquedef));
 
118
    bzero((char*) uniqueseg,sizeof(uniqueseg));
 
119
    uniquedef.seg=uniqueseg;
 
120
    uniquedef.keysegs=2;
 
121
 
 
122
    /* Make a unique over all columns (except first NULL fields) */
 
123
    for (i=0, start=1 ; i < 2 ; i++)
 
124
    {
 
125
      uniqueseg[i].start=start;
 
126
      start+=recinfo[i+1].length;
 
127
      uniqueseg[i].length=recinfo[i+1].length;
 
128
      uniqueseg[i].language= default_charset_info->number;
 
129
    }
 
130
    uniqueseg[0].type= key_type;
 
131
    uniqueseg[0].null_bit= null_fields ? 2 : 0;
 
132
    uniqueseg[1].type= HA_KEYTYPE_TEXT;
 
133
    if (extra_field == FIELD_BLOB)
 
134
    {
 
135
      uniqueseg[1].length=0;                    /* The whole blob */
 
136
      uniqueseg[1].bit_start=4;                 /* long blob */
 
137
      uniqueseg[1].flag|= HA_BLOB_PART;
 
138
    }
 
139
    else if (extra_field == FIELD_VARCHAR)
 
140
      uniqueseg[1].flag|= HA_VAR_LENGTH_PART;
 
141
  }
 
142
  else
 
143
    uniques=0;
 
144
 
 
145
  if (!silent)
 
146
    printf("- Creating isam-file\n");
 
147
  bzero((char*) &create_info,sizeof(create_info));
 
148
  create_info.max_rows=(ulong) (rec_pointer_size ?
 
149
                                (1L << (rec_pointer_size*8))/40 :
 
150
                                0);
 
151
  if (mi_create(filename,1,keyinfo,3+opt_unique,recinfo,
 
152
                uniques, &uniquedef, &create_info,
 
153
                create_flag))
 
154
    goto err;
 
155
  if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
 
156
    goto err;
 
157
  if (!silent)
 
158
    printf("- Writing key:s\n");
 
159
 
 
160
  my_errno=0;
 
161
  row_count=deleted=0;
 
162
  for (i=49 ; i>=1 ; i-=2 )
 
163
  {
 
164
    if (insert_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
 
165
    j=i%25 +1;
 
166
    create_record(record,j);
 
167
    error=mi_write(file,record);
 
168
    if (!error)
 
169
      row_count++;
 
170
    flags[j]=1;
 
171
    if (verbose || error)
 
172
      printf("J= %2d  mi_write: %d  errno: %d\n", j,error,my_errno);
 
173
  }
 
174
 
 
175
  /* Insert 2 rows with null values */
 
176
  if (null_fields)
 
177
  {
 
178
    create_record(record,0);
 
179
    error=mi_write(file,record);
 
180
    if (!error)
 
181
      row_count++;
 
182
    if (verbose || error)
 
183
      printf("J= NULL  mi_write: %d  errno: %d\n", error,my_errno);
 
184
    error=mi_write(file,record);
 
185
    if (!error)
 
186
      row_count++;
 
187
    if (verbose || error)
 
188
      printf("J= NULL  mi_write: %d  errno: %d\n", error,my_errno);
 
189
    flags[0]=2;
 
190
  }
 
191
 
 
192
  if (!skip_update)
 
193
  {
 
194
    if (opt_unique)
 
195
    {
 
196
      if (!silent)
 
197
        printf("- Checking unique constraint\n");
 
198
      create_record(record,j);
 
199
      if (!mi_write(file,record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE)
 
200
      {
 
201
        printf("unique check failed\n");
 
202
      }
 
203
    }
 
204
    if (!silent)
 
205
      printf("- Updating rows\n");
 
206
 
 
207
    /* Update first last row to force extend of file */
 
208
    if (mi_rsame(file,read_record,-1))
 
209
    {
 
210
      printf("Can't find last row with mi_rsame\n");
 
211
    }
 
212
    else
 
213
    {
 
214
      memcpy(record,read_record,rec_length);
 
215
      update_record(record);
 
216
      if (mi_update(file,read_record,record))
 
217
      {
 
218
        printf("Can't update last row: %.*s\n",
 
219
               keyinfo[0].seg[0].length,read_record+1);
 
220
      }
 
221
    }
 
222
 
 
223
    /* Read through all rows and update them */
 
224
    pos=(my_off_t) 0;
 
225
    found=0;
 
226
    while ((error=mi_rrnd(file,read_record,pos)) == 0)
 
227
    {
 
228
      if (update_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
 
229
      memcpy(record,read_record,rec_length);
 
230
      update_record(record);
 
231
      if (mi_update(file,read_record,record))
 
232
      {
 
233
        printf("Can't update row: %.*s, error: %d\n",
 
234
               keyinfo[0].seg[0].length,record+1,my_errno);
 
235
      }
 
236
      found++;
 
237
      pos=HA_OFFSET_ERROR;
 
238
    }
 
239
    if (found != row_count)
 
240
      printf("Found %ld of %ld rows\n", (ulong) found, (ulong) row_count);
 
241
  }
 
242
 
 
243
  if (!silent)
 
244
    printf("- Reopening file\n");
 
245
  if (mi_close(file)) goto err;
 
246
  if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err;
 
247
  if (!skip_update)
 
248
  {
 
249
    if (!silent)
 
250
      printf("- Removing keys\n");
 
251
 
 
252
    for (i=0 ; i <= 10 ; i++)
 
253
    {
 
254
      /* testing */
 
255
      if (remove_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; }
 
256
      j=i*2;
 
257
      if (!flags[j])
 
258
        continue;
 
259
      create_key(key,j);
 
260
      my_errno=0;
 
261
      if ((error = mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,
 
262
                           HA_READ_KEY_EXACT)))
 
263
      {
 
264
        if (verbose || (flags[j] >= 1 ||
 
265
                        (error && my_errno != HA_ERR_KEY_NOT_FOUND)))
 
266
          printf("key: '%.*s'  mi_rkey:  %3d  errno: %3d\n",
 
267
                 (int) key_length,key+test(null_fields),error,my_errno);
 
268
      }
 
269
      else
 
270
      {
 
271
        error=mi_delete(file,read_record);
 
272
        if (verbose || error)
 
273
          printf("key: '%.*s'  mi_delete: %3d  errno: %3d\n",
 
274
                 (int) key_length, key+test(null_fields), error, my_errno);
 
275
        if (! error)
 
276
        {
 
277
          deleted++;
 
278
          flags[j]--;
 
279
        }
 
280
      }
 
281
    }
 
282
  }
 
283
  if (!silent)
 
284
    printf("- Reading rows with key\n");
 
285
  for (i=0 ; i <= 25 ; i++)
 
286
  {
 
287
    create_key(key,i);
 
288
    my_errno=0;
 
289
    error=mi_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT);
 
290
    if (verbose ||
 
291
        (error == 0 && flags[i] == 0 && unique_key) ||
 
292
        (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND)))
 
293
    {
 
294
      printf("key: '%.*s'  mi_rkey: %3d  errno: %3d  record: %s\n",
 
295
             (int) key_length,key+test(null_fields),error,my_errno,record+1);
 
296
    }
 
297
  }
 
298
 
 
299
  if (!silent)
 
300
    printf("- Reading rows with position\n");
 
301
  for (i=1,found=0 ; i <= 30 ; i++)
 
302
  {
 
303
    my_errno=0;
 
304
    if ((error=mi_rrnd(file,read_record,i == 1 ? 0L : HA_OFFSET_ERROR)) == -1)
 
305
    {
 
306
      if (found != row_count-deleted)
 
307
        printf("Found only %ld of %ld rows\n", (ulong) found,
 
308
               (ulong) (row_count - deleted));
 
309
      break;
 
310
    }
 
311
    if (!error)
 
312
      found++;
 
313
    if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED &&
 
314
                    error != HA_ERR_END_OF_FILE))
 
315
    {
 
316
      printf("pos: %2d  mi_rrnd: %3d  errno: %3d  record: %s\n",
 
317
             i-1,error,my_errno,read_record+1);
 
318
    }
 
319
  }
 
320
  if (mi_close(file)) goto err;
 
321
  my_end(MY_CHECK_ERROR);
 
322
 
 
323
  return (0);
 
324
err:
 
325
  printf("got error: %3d when using myisam-database\n",my_errno);
 
326
  return 1;                     /* skip warning */
 
327
}
 
328
 
 
329
 
 
330
static void create_key_part(uchar *key,uint rownr)
 
331
{
 
332
  if (!unique_key)
 
333
    rownr&=7;                                   /* Some identical keys */
 
334
  if (keyinfo[0].seg[0].type == HA_KEYTYPE_NUM)
 
335
  {
 
336
    sprintf((char*) key,"%*d",keyinfo[0].seg[0].length,rownr);
 
337
  }
 
338
  else if (keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT1 ||
 
339
           keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT2)
 
340
  {                                             /* Alpha record */
 
341
    /* Create a key that may be easily packed */
 
342
    bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B');
 
343
    sprintf((char*) key+keyinfo[0].seg[0].length-2,"%-2d",rownr);
 
344
    if ((rownr & 7) == 0)
 
345
    {
 
346
      /* Change the key to force a unpack of the next key */
 
347
      bfill(key+3,keyinfo[0].seg[0].length-4,rownr < 10 ? 'a' : 'b');
 
348
    }
 
349
  }
 
350
  else
 
351
  {                                             /* Alpha record */
 
352
    if (keyinfo[0].seg[0].flag & HA_SPACE_PACK)
 
353
      sprintf((char*) key,"%-*d",keyinfo[0].seg[0].length,rownr);
 
354
    else
 
355
    {
 
356
      /* Create a key that may be easily packed */
 
357
      bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B');
 
358
      sprintf((char*) key+keyinfo[0].seg[0].length-2,"%-2d",rownr);
 
359
      if ((rownr & 7) == 0)
 
360
      {
 
361
        /* Change the key to force a unpack of the next key */
 
362
        key[1]= (rownr < 10 ? 'a' : 'b');
 
363
      }
 
364
    }
 
365
  }
 
366
}
 
367
 
 
368
 
 
369
static void create_key(uchar *key,uint rownr)
 
370
{
 
371
  if (keyinfo[0].seg[0].null_bit)
 
372
  {
 
373
    if (rownr == 0)
 
374
    {
 
375
      key[0]=1;                                 /* null key */
 
376
      key[1]=0;                                 /* Fore easy print of key */
 
377
      return;
 
378
    }
 
379
    *key++=0;
 
380
  }
 
381
  if (keyinfo[0].seg[0].flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART))
 
382
  {
 
383
    uint tmp;
 
384
    create_key_part(key+2,rownr);
 
385
    tmp=strlen((char*) key+2);
 
386
    int2store(key,tmp);
 
387
  }
 
388
  else
 
389
    create_key_part(key,rownr);
 
390
}
 
391
 
 
392
 
 
393
static uchar blob_key[MAX_REC_LENGTH];
 
394
static uchar blob_record[MAX_REC_LENGTH+20*20];
 
395
 
 
396
 
 
397
static void create_record(uchar *record,uint rownr)
 
398
{
 
399
  uchar *pos;
 
400
  bzero((char*) record,MAX_REC_LENGTH);
 
401
  record[0]=1;                                  /* delete marker */
 
402
  if (rownr == 0 && keyinfo[0].seg[0].null_bit)
 
403
    record[0]|=keyinfo[0].seg[0].null_bit;      /* Null key */
 
404
 
 
405
  pos=record+1;
 
406
  if (recinfo[1].type == FIELD_BLOB)
 
407
  {
 
408
    uint tmp;
 
409
    uchar *ptr;
 
410
    create_key_part(blob_key,rownr);
 
411
    tmp=strlen((char*) blob_key);
 
412
    int4store(pos,tmp);
 
413
    ptr=blob_key;
 
414
    memcpy_fixed(pos+4,&ptr,sizeof(char*));
 
415
    pos+=recinfo[1].length;
 
416
  }
 
417
  else if (recinfo[1].type == FIELD_VARCHAR)
 
418
  {
 
419
    uint tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
 
420
    create_key_part(pos+pack_length,rownr);
 
421
    tmp= strlen((char*) pos+pack_length);
 
422
    if (pack_length == 1)
 
423
      *(uchar*) pos= (uchar) tmp;
 
424
    else
 
425
      int2store(pos,tmp);
 
426
    pos+= recinfo[1].length;
 
427
  }
 
428
  else
 
429
  {
 
430
    create_key_part(pos,rownr);
 
431
    pos+=recinfo[1].length;
 
432
  }
 
433
  if (recinfo[2].type == FIELD_BLOB)
 
434
  {
 
435
    uint tmp;
 
436
    uchar *ptr;;
 
437
    sprintf((char*) blob_record,"... row: %d", rownr);
 
438
    strappend((char*) blob_record,max(MAX_REC_LENGTH-rownr,10),' ');
 
439
    tmp=strlen((char*) blob_record);
 
440
    int4store(pos,tmp);
 
441
    ptr=blob_record;
 
442
    memcpy_fixed(pos+4,&ptr,sizeof(char*));
 
443
  }
 
444
  else if (recinfo[2].type == FIELD_VARCHAR)
 
445
  {
 
446
    uint tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
 
447
    sprintf((char*) pos+pack_length, "... row: %d", rownr);
 
448
    tmp= strlen((char*) pos+pack_length);
 
449
    if (pack_length == 1)
 
450
      *pos= (uchar) tmp;
 
451
    else
 
452
      int2store(pos,tmp);
 
453
  }
 
454
  else
 
455
  {
 
456
    sprintf((char*) pos,"... row: %d", rownr);
 
457
    strappend((char*) pos,recinfo[2].length,' ');
 
458
  }
 
459
}
 
460
 
 
461
/* change row to test re-packing of rows and reallocation of keys */
 
462
 
 
463
static void update_record(uchar *record)
 
464
{
 
465
  uchar *pos=record+1;
 
466
  if (recinfo[1].type == FIELD_BLOB)
 
467
  {
 
468
    uchar *column,*ptr;
 
469
    int length;
 
470
    length=uint4korr(pos);                      /* Long blob */
 
471
    memcpy_fixed(&column,pos+4,sizeof(char*));
 
472
    memcpy(blob_key,column,length);             /* Move old key */
 
473
    ptr=blob_key;
 
474
    memcpy_fixed(pos+4,&ptr,sizeof(char*));     /* Store pointer to new key */
 
475
    if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
 
476
      default_charset_info->cset->casedn(default_charset_info,
 
477
                                         (char*) blob_key, length,
 
478
                                         (char*) blob_key, length);
 
479
    pos+=recinfo[1].length;
 
480
  }
 
481
  else if (recinfo[1].type == FIELD_VARCHAR)
 
482
  {
 
483
    uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
 
484
    uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
 
485
    default_charset_info->cset->casedn(default_charset_info,
 
486
                                       (char*) pos + pack_length, length,
 
487
                                       (char*) pos + pack_length, length);
 
488
    pos+=recinfo[1].length;
 
489
  }
 
490
  else
 
491
  {
 
492
    if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
 
493
      default_charset_info->cset->casedn(default_charset_info,
 
494
                                         (char*) pos, keyinfo[0].seg[0].length,
 
495
                                         (char*) pos, keyinfo[0].seg[0].length);
 
496
    pos+=recinfo[1].length;
 
497
  }
 
498
 
 
499
  if (recinfo[2].type == FIELD_BLOB)
 
500
  {
 
501
    uchar *column;
 
502
    int length;
 
503
    length=uint4korr(pos);
 
504
    memcpy_fixed(&column,pos+4,sizeof(char*));
 
505
    memcpy(blob_record,column,length);
 
506
    bfill(blob_record+length,20,'.');   /* Make it larger */
 
507
    length+=20;
 
508
    int4store(pos,length);
 
509
    column= blob_record;
 
510
    memcpy_fixed(pos+4,&column,sizeof(char*));
 
511
  }
 
512
  else if (recinfo[2].type == FIELD_VARCHAR)
 
513
  {
 
514
    /* Second field is longer than 10 characters */
 
515
    uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
 
516
    uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
 
517
    bfill(pos+pack_length+length,recinfo[2].length-length-pack_length,'.');
 
518
    length=recinfo[2].length-pack_length;
 
519
    if (pack_length == 1)
 
520
      *(uchar*) pos= (uchar) length;
 
521
    else
 
522
      int2store(pos,length);
 
523
  }
 
524
  else
 
525
  {
 
526
    bfill(pos+recinfo[2].length-10,10,'.');
 
527
  }
 
528
}
 
529
 
 
530
 
 
531
static struct my_option my_long_options[] =
 
532
{
 
533
  {"checksum", 'c', "Undocumented",
 
534
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
535
#ifndef DBUG_OFF
 
536
  {"debug", '#', "Undocumented",
 
537
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
538
#endif
 
539
  {"delete_rows", 'd', "Undocumented", (uchar**) &remove_count,
 
540
   (uchar**) &remove_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
 
541
  {"help", '?', "Display help and exit",
 
542
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
543
  {"insert_rows", 'i', "Undocumented", (uchar**) &insert_count,
 
544
   (uchar**) &insert_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
 
545
  {"key_alpha", 'a', "Use a key of type HA_KEYTYPE_TEXT",
 
546
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
547
  {"key_binary_pack", 'B', "Undocumented",
 
548
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
549
  {"key_blob", 'b', "Undocumented",
 
550
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
551
  {"key_cache", 'K', "Undocumented", (uchar**) &key_cacheing,
 
552
   (uchar**) &key_cacheing, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
553
  {"key_length", 'k', "Undocumented", (uchar**) &key_length, (uchar**) &key_length,
 
554
   0, GET_UINT, REQUIRED_ARG, 6, 0, 0, 0, 0, 0},
 
555
  {"key_multiple", 'm', "Undocumented",
 
556
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
557
  {"key_prefix_pack", 'P', "Undocumented",
 
558
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
559
  {"key_space_pack", 'p', "Undocumented",
 
560
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
561
  {"key_varchar", 'w', "Test VARCHAR keys",
 
562
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
563
  {"null_fields", 'N', "Define fields with NULL",
 
564
   (uchar**) &null_fields, (uchar**) &null_fields, 0, GET_BOOL, NO_ARG,
 
565
   0, 0, 0, 0, 0, 0},
 
566
  {"row_fixed_size", 'S', "Undocumented",
 
567
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
568
  {"row_pointer_size", 'R', "Undocumented", (uchar**) &rec_pointer_size,
 
569
   (uchar**) &rec_pointer_size, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
570
  {"silent", 's', "Undocumented",
 
571
   (uchar**) &silent, (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
572
  {"skip_update", 'U', "Undocumented", (uchar**) &skip_update,
 
573
   (uchar**) &skip_update, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
574
  {"unique", 'C', "Undocumented", (uchar**) &opt_unique, (uchar**) &opt_unique, 0,
 
575
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
576
  {"update_rows", 'u', "Undocumented", (uchar**) &update_count,
 
577
   (uchar**) &update_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
 
578
  {"verbose", 'v', "Be more verbose", (uchar**) &verbose, (uchar**) &verbose, 0,
 
579
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
580
  {"version", 'V', "Print version number and exit",
 
581
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
582
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
583
};
 
584
 
 
585
 
 
586
static my_bool
 
587
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
 
588
               char *argument __attribute__((unused)))
 
589
{
 
590
  switch(optid) {
 
591
  case 'a':
 
592
    key_type= HA_KEYTYPE_TEXT;
 
593
    break;
 
594
  case 'c':
 
595
    create_flag|= HA_CREATE_CHECKSUM;
 
596
    break;
 
597
  case 'R':                             /* Length of record pointer */
 
598
    if (rec_pointer_size > 3)
 
599
      rec_pointer_size=0;
 
600
    break;
 
601
  case 'P':
 
602
    pack_keys= HA_PACK_KEY;             /* Use prefix compression */
 
603
    break;
 
604
  case 'B':
 
605
    pack_keys= HA_BINARY_PACK_KEY;      /* Use binary compression */
 
606
    break;
 
607
  case 'S':
 
608
    if (key_field == FIELD_VARCHAR)
 
609
    {
 
610
      create_flag=0;                    /* Static sized varchar */
 
611
    }
 
612
    else if (key_field != FIELD_BLOB)
 
613
    {
 
614
      key_field=FIELD_NORMAL;           /* static-size record */
 
615
      extra_field=FIELD_NORMAL;
 
616
    }
 
617
    break;
 
618
  case 'p':
 
619
    pack_keys=HA_PACK_KEY;              /* Use prefix + space packing */
 
620
    pack_seg=HA_SPACE_PACK;
 
621
    key_type=HA_KEYTYPE_TEXT;
 
622
    break;
 
623
  case 'm':
 
624
    unique_key=0;
 
625
    break;
 
626
  case 'b':
 
627
    key_field=FIELD_BLOB;                       /* blob key */
 
628
    extra_field= FIELD_BLOB;
 
629
    pack_seg|= HA_BLOB_PART;
 
630
    key_type= HA_KEYTYPE_VARTEXT1;
 
631
    break;
 
632
  case 'k':
 
633
    if (key_length < 4 || key_length > MI_MAX_KEY_LENGTH)
 
634
    {
 
635
      fprintf(stderr,"Wrong key length\n");
 
636
      exit(1);
 
637
    }
 
638
    break;
 
639
  case 'w':
 
640
    key_field=FIELD_VARCHAR;                    /* varchar keys */
 
641
    extra_field= FIELD_VARCHAR;
 
642
    key_type= HA_KEYTYPE_VARTEXT1;
 
643
    pack_seg|= HA_VAR_LENGTH_PART;
 
644
    create_flag|= HA_PACK_RECORD;
 
645
    break;
 
646
  case 'K':                                     /* Use key cacheing */
 
647
    key_cacheing=1;
 
648
    break;
 
649
  case 'V':
 
650
    printf("test1 Ver 1.2 \n");
 
651
    exit(0);
 
652
  case '#':
 
653
    DBUG_PUSH (argument);
 
654
    break;
 
655
  case '?':
 
656
    usage();
 
657
    exit(1);
 
658
  }
 
659
  return 0;
 
660
}
 
661
 
 
662
 
 
663
/* Read options */
 
664
 
 
665
static void get_options(int argc, char *argv[])
 
666
{
 
667
  int ho_error;
 
668
 
 
669
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
 
670
    exit(ho_error);
 
671
 
 
672
  return;
 
673
} /* get options */
 
674
 
 
675
 
 
676
static void usage()
 
677
{
 
678
  printf("Usage: %s [options]\n\n", my_progname);
 
679
  my_print_help(my_long_options);
 
680
  my_print_variables(my_long_options);
 
681
}