00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* Testing of the basic functions of a MyISAM table */ 00018 00019 #include "myisam.h" 00020 #include <my_getopt.h> 00021 #include <m_string.h> 00022 00023 #define MAX_REC_LENGTH 1024 00024 00025 static void usage(); 00026 00027 static int rec_pointer_size=0, flags[50]; 00028 static int key_field=FIELD_SKIP_PRESPACE,extra_field=FIELD_SKIP_ENDSPACE; 00029 static int key_type=HA_KEYTYPE_NUM; 00030 static int create_flag=0; 00031 00032 static uint insert_count, update_count, remove_count; 00033 static uint pack_keys=0, pack_seg=0, key_length; 00034 static uint unique_key=HA_NOSAME; 00035 static my_bool key_cacheing, null_fields, silent, skip_update, opt_unique, 00036 verbose; 00037 static MI_COLUMNDEF recinfo[4]; 00038 static MI_KEYDEF keyinfo[10]; 00039 static HA_KEYSEG keyseg[10]; 00040 static HA_KEYSEG uniqueseg[10]; 00041 00042 static int run_test(const char *filename); 00043 static void get_options(int argc, char *argv[]); 00044 static void create_key(char *key,uint rownr); 00045 static void create_record(char *record,uint rownr); 00046 static void update_record(char *record); 00047 00048 int main(int argc,char *argv[]) 00049 { 00050 MY_INIT(argv[0]); 00051 my_init(); 00052 if (key_cacheing) 00053 init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,IO_SIZE*16,0,0); 00054 get_options(argc,argv); 00055 00056 exit(run_test("test1")); 00057 } 00058 00059 00060 static int run_test(const char *filename) 00061 { 00062 MI_INFO *file; 00063 int i,j,error,deleted,rec_length,uniques=0; 00064 ha_rows found,row_count; 00065 my_off_t pos; 00066 char record[MAX_REC_LENGTH],key[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH]; 00067 MI_UNIQUEDEF uniquedef; 00068 MI_CREATE_INFO create_info; 00069 00070 bzero((char*) recinfo,sizeof(recinfo)); 00071 00072 /* First define 2 columns */ 00073 recinfo[0].type=FIELD_NORMAL; recinfo[0].length=1; /* For NULL bits */ 00074 recinfo[1].type=key_field; 00075 recinfo[1].length= (key_field == FIELD_BLOB ? 4+mi_portable_sizeof_char_ptr : 00076 key_length); 00077 if (key_field == FIELD_VARCHAR) 00078 recinfo[1].length+= HA_VARCHAR_PACKLENGTH(key_length);; 00079 recinfo[2].type=extra_field; 00080 recinfo[2].length= (extra_field == FIELD_BLOB ? 4 + mi_portable_sizeof_char_ptr : 24); 00081 if (extra_field == FIELD_VARCHAR) 00082 recinfo[2].length+= HA_VARCHAR_PACKLENGTH(recinfo[2].length); 00083 if (opt_unique) 00084 { 00085 recinfo[3].type=FIELD_CHECK; 00086 recinfo[3].length=MI_UNIQUE_HASH_LENGTH; 00087 } 00088 rec_length=recinfo[0].length+recinfo[1].length+recinfo[2].length+ 00089 recinfo[3].length; 00090 00091 if (key_type == HA_KEYTYPE_VARTEXT1 && 00092 key_length > 255) 00093 key_type= HA_KEYTYPE_VARTEXT2; 00094 00095 /* Define a key over the first column */ 00096 keyinfo[0].seg=keyseg; 00097 keyinfo[0].keysegs=1; 00098 keyinfo[0].block_length= 0; /* Default block length */ 00099 keyinfo[0].key_alg=HA_KEY_ALG_BTREE; 00100 keyinfo[0].seg[0].type= key_type; 00101 keyinfo[0].seg[0].flag= pack_seg; 00102 keyinfo[0].seg[0].start=1; 00103 keyinfo[0].seg[0].length=key_length; 00104 keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0; 00105 keyinfo[0].seg[0].null_pos=0; 00106 keyinfo[0].seg[0].language= default_charset_info->number; 00107 if (pack_seg & HA_BLOB_PART) 00108 { 00109 keyinfo[0].seg[0].bit_start=4; /* Length of blob length */ 00110 } 00111 keyinfo[0].flag = (uint8) (pack_keys | unique_key); 00112 00113 bzero((byte*) flags,sizeof(flags)); 00114 if (opt_unique) 00115 { 00116 uint start; 00117 uniques=1; 00118 bzero((char*) &uniquedef,sizeof(uniquedef)); 00119 bzero((char*) uniqueseg,sizeof(uniqueseg)); 00120 uniquedef.seg=uniqueseg; 00121 uniquedef.keysegs=2; 00122 00123 /* Make a unique over all columns (except first NULL fields) */ 00124 for (i=0, start=1 ; i < 2 ; i++) 00125 { 00126 uniqueseg[i].start=start; 00127 start+=recinfo[i+1].length; 00128 uniqueseg[i].length=recinfo[i+1].length; 00129 uniqueseg[i].language= default_charset_info->number; 00130 } 00131 uniqueseg[0].type= key_type; 00132 uniqueseg[0].null_bit= null_fields ? 2 : 0; 00133 uniqueseg[1].type= HA_KEYTYPE_TEXT; 00134 if (extra_field == FIELD_BLOB) 00135 { 00136 uniqueseg[1].length=0; /* The whole blob */ 00137 uniqueseg[1].bit_start=4; /* long blob */ 00138 uniqueseg[1].flag|= HA_BLOB_PART; 00139 } 00140 else if (extra_field == FIELD_VARCHAR) 00141 uniqueseg[1].flag|= HA_VAR_LENGTH_PART; 00142 } 00143 else 00144 uniques=0; 00145 00146 if (!silent) 00147 printf("- Creating isam-file\n"); 00148 bzero((char*) &create_info,sizeof(create_info)); 00149 create_info.max_rows=(ulong) (rec_pointer_size ? 00150 (1L << (rec_pointer_size*8))/40 : 00151 0); 00152 if (mi_create(filename,1,keyinfo,3+opt_unique,recinfo, 00153 uniques, &uniquedef, &create_info, 00154 create_flag)) 00155 goto err; 00156 if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) 00157 goto err; 00158 if (!silent) 00159 printf("- Writing key:s\n"); 00160 00161 my_errno=0; 00162 row_count=deleted=0; 00163 for (i=49 ; i>=1 ; i-=2 ) 00164 { 00165 if (insert_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } 00166 j=i%25 +1; 00167 create_record(record,j); 00168 error=mi_write(file,record); 00169 if (!error) 00170 row_count++; 00171 flags[j]=1; 00172 if (verbose || error) 00173 printf("J= %2d mi_write: %d errno: %d\n", j,error,my_errno); 00174 } 00175 00176 /* Insert 2 rows with null values */ 00177 if (null_fields) 00178 { 00179 create_record(record,0); 00180 error=mi_write(file,record); 00181 if (!error) 00182 row_count++; 00183 if (verbose || error) 00184 printf("J= NULL mi_write: %d errno: %d\n", error,my_errno); 00185 error=mi_write(file,record); 00186 if (!error) 00187 row_count++; 00188 if (verbose || error) 00189 printf("J= NULL mi_write: %d errno: %d\n", error,my_errno); 00190 flags[0]=2; 00191 } 00192 00193 if (!skip_update) 00194 { 00195 if (opt_unique) 00196 { 00197 if (!silent) 00198 printf("- Checking unique constraint\n"); 00199 create_record(record,j); 00200 if (!mi_write(file,record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE) 00201 { 00202 printf("unique check failed\n"); 00203 } 00204 } 00205 if (!silent) 00206 printf("- Updating rows\n"); 00207 00208 /* Update first last row to force extend of file */ 00209 if (mi_rsame(file,read_record,-1)) 00210 { 00211 printf("Can't find last row with mi_rsame\n"); 00212 } 00213 else 00214 { 00215 memcpy(record,read_record,rec_length); 00216 update_record(record); 00217 if (mi_update(file,read_record,record)) 00218 { 00219 printf("Can't update last row: %.*s\n", 00220 keyinfo[0].seg[0].length,read_record+1); 00221 } 00222 } 00223 00224 /* Read through all rows and update them */ 00225 pos=(my_off_t) 0; 00226 found=0; 00227 while ((error=mi_rrnd(file,read_record,pos)) == 0) 00228 { 00229 if (update_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } 00230 memcpy(record,read_record,rec_length); 00231 update_record(record); 00232 if (mi_update(file,read_record,record)) 00233 { 00234 printf("Can't update row: %.*s, error: %d\n", 00235 keyinfo[0].seg[0].length,record+1,my_errno); 00236 } 00237 found++; 00238 pos=HA_OFFSET_ERROR; 00239 } 00240 if (found != row_count) 00241 printf("Found %ld of %ld rows\n", (ulong) found, (ulong) row_count); 00242 } 00243 00244 if (!silent) 00245 printf("- Reopening file\n"); 00246 if (mi_close(file)) goto err; 00247 if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err; 00248 if (!skip_update) 00249 { 00250 if (!silent) 00251 printf("- Removing keys\n"); 00252 00253 for (i=0 ; i <= 10 ; i++) 00254 { 00255 /* testing */ 00256 if (remove_count-- == 0) { VOID(mi_close(file)) ; exit(0) ; } 00257 j=i*2; 00258 if (!flags[j]) 00259 continue; 00260 create_key(key,j); 00261 my_errno=0; 00262 if ((error = mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT))) 00263 { 00264 if (verbose || (flags[j] >= 1 || 00265 (error && my_errno != HA_ERR_KEY_NOT_FOUND))) 00266 printf("key: '%.*s' mi_rkey: %3d errno: %3d\n", 00267 (int) key_length,key+test(null_fields),error,my_errno); 00268 } 00269 else 00270 { 00271 error=mi_delete(file,read_record); 00272 if (verbose || error) 00273 printf("key: '%.*s' mi_delete: %3d errno: %3d\n", 00274 (int) key_length, key+test(null_fields), error, my_errno); 00275 if (! error) 00276 { 00277 deleted++; 00278 flags[j]--; 00279 } 00280 } 00281 } 00282 } 00283 if (!silent) 00284 printf("- Reading rows with key\n"); 00285 for (i=0 ; i <= 25 ; i++) 00286 { 00287 create_key(key,i); 00288 my_errno=0; 00289 error=mi_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT); 00290 if (verbose || 00291 (error == 0 && flags[i] == 0 && unique_key) || 00292 (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND))) 00293 { 00294 printf("key: '%.*s' mi_rkey: %3d errno: %3d record: %s\n", 00295 (int) key_length,key+test(null_fields),error,my_errno,record+1); 00296 } 00297 } 00298 00299 if (!silent) 00300 printf("- Reading rows with position\n"); 00301 for (i=1,found=0 ; i <= 30 ; i++) 00302 { 00303 my_errno=0; 00304 if ((error=mi_rrnd(file,read_record,i == 1 ? 0L : HA_OFFSET_ERROR)) == -1) 00305 { 00306 if (found != row_count-deleted) 00307 printf("Found only %ld of %ld rows\n", (ulong) found, 00308 (ulong) (row_count - deleted)); 00309 break; 00310 } 00311 if (!error) 00312 found++; 00313 if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED && 00314 error != HA_ERR_END_OF_FILE)) 00315 { 00316 printf("pos: %2d mi_rrnd: %3d errno: %3d record: %s\n", 00317 i-1,error,my_errno,read_record+1); 00318 } 00319 } 00320 if (mi_close(file)) goto err; 00321 my_end(MY_CHECK_ERROR); 00322 00323 return (0); 00324 err: 00325 printf("got error: %3d when using myisam-database\n",my_errno); 00326 return 1; /* skip warning */ 00327 } 00328 00329 00330 static void create_key_part(char *key,uint rownr) 00331 { 00332 if (!unique_key) 00333 rownr&=7; /* Some identical keys */ 00334 if (keyinfo[0].seg[0].type == HA_KEYTYPE_NUM) 00335 { 00336 sprintf(key,"%*d",keyinfo[0].seg[0].length,rownr); 00337 } 00338 else if (keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT1 || 00339 keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT2) 00340 { /* Alpha record */ 00341 /* Create a key that may be easily packed */ 00342 bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B'); 00343 sprintf(key+keyinfo[0].seg[0].length-2,"%-2d",rownr); 00344 if ((rownr & 7) == 0) 00345 { 00346 /* Change the key to force a unpack of the next key */ 00347 bfill(key+3,keyinfo[0].seg[0].length-4,rownr < 10 ? 'a' : 'b'); 00348 } 00349 } 00350 else 00351 { /* Alpha record */ 00352 if (keyinfo[0].seg[0].flag & HA_SPACE_PACK) 00353 sprintf(key,"%-*d",keyinfo[0].seg[0].length,rownr); 00354 else 00355 { 00356 /* Create a key that may be easily packed */ 00357 bfill(key,keyinfo[0].seg[0].length,rownr < 10 ? 'A' : 'B'); 00358 sprintf(key+keyinfo[0].seg[0].length-2,"%-2d",rownr); 00359 if ((rownr & 7) == 0) 00360 { 00361 /* Change the key to force a unpack of the next key */ 00362 key[1]= (rownr < 10 ? 'a' : 'b'); 00363 } 00364 } 00365 } 00366 } 00367 00368 00369 static void create_key(char *key,uint rownr) 00370 { 00371 if (keyinfo[0].seg[0].null_bit) 00372 { 00373 if (rownr == 0) 00374 { 00375 key[0]=1; /* null key */ 00376 key[1]=0; /* Fore easy print of key */ 00377 return; 00378 } 00379 *key++=0; 00380 } 00381 if (keyinfo[0].seg[0].flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART)) 00382 { 00383 uint tmp; 00384 create_key_part(key+2,rownr); 00385 tmp=strlen(key+2); 00386 int2store(key,tmp); 00387 } 00388 else 00389 create_key_part(key,rownr); 00390 } 00391 00392 00393 static char blob_key[MAX_REC_LENGTH]; 00394 static char blob_record[MAX_REC_LENGTH+20*20]; 00395 00396 00397 static void create_record(char *record,uint rownr) 00398 { 00399 char *pos; 00400 bzero((char*) record,MAX_REC_LENGTH); 00401 record[0]=1; /* delete marker */ 00402 if (rownr == 0 && keyinfo[0].seg[0].null_bit) 00403 record[0]|=keyinfo[0].seg[0].null_bit; /* Null key */ 00404 00405 pos=record+1; 00406 if (recinfo[1].type == FIELD_BLOB) 00407 { 00408 uint tmp; 00409 char *ptr; 00410 create_key_part(blob_key,rownr); 00411 tmp=strlen(blob_key); 00412 int4store(pos,tmp); 00413 ptr=blob_key; 00414 memcpy_fixed(pos+4,&ptr,sizeof(char*)); 00415 pos+=recinfo[1].length; 00416 } 00417 else if (recinfo[1].type == FIELD_VARCHAR) 00418 { 00419 uint tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1); 00420 create_key_part(pos+pack_length,rownr); 00421 tmp= strlen(pos+pack_length); 00422 if (pack_length == 1) 00423 *(uchar*) pos= (uchar) tmp; 00424 else 00425 int2store(pos,tmp); 00426 pos+= recinfo[1].length; 00427 } 00428 else 00429 { 00430 create_key_part(pos,rownr); 00431 pos+=recinfo[1].length; 00432 } 00433 if (recinfo[2].type == FIELD_BLOB) 00434 { 00435 uint tmp; 00436 char *ptr;; 00437 sprintf(blob_record,"... row: %d", rownr); 00438 strappend(blob_record,max(MAX_REC_LENGTH-rownr,10),' '); 00439 tmp=strlen(blob_record); 00440 int4store(pos,tmp); 00441 ptr=blob_record; 00442 memcpy_fixed(pos+4,&ptr,sizeof(char*)); 00443 } 00444 else if (recinfo[2].type == FIELD_VARCHAR) 00445 { 00446 uint tmp, pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1); 00447 sprintf(pos+pack_length, "... row: %d", rownr); 00448 tmp= strlen(pos+pack_length); 00449 if (pack_length == 1) 00450 *(uchar*) pos= (uchar) tmp; 00451 else 00452 int2store(pos,tmp); 00453 } 00454 else 00455 { 00456 sprintf(pos,"... row: %d", rownr); 00457 strappend(pos,recinfo[2].length,' '); 00458 } 00459 } 00460 00461 /* change row to test re-packing of rows and reallocation of keys */ 00462 00463 static void update_record(char *record) 00464 { 00465 char *pos=record+1; 00466 if (recinfo[1].type == FIELD_BLOB) 00467 { 00468 char *column,*ptr; 00469 int length; 00470 length=uint4korr(pos); /* Long blob */ 00471 memcpy_fixed(&column,pos+4,sizeof(char*)); 00472 memcpy(blob_key,column,length); /* Move old key */ 00473 ptr=blob_key; 00474 memcpy_fixed(pos+4,&ptr,sizeof(char*)); /* Store pointer to new key */ 00475 if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM) 00476 default_charset_info->cset->casedn(default_charset_info, 00477 blob_key, length, blob_key, length); 00478 pos+=recinfo[1].length; 00479 } 00480 else if (recinfo[1].type == FIELD_VARCHAR) 00481 { 00482 uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1); 00483 uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos); 00484 default_charset_info->cset->casedn(default_charset_info, 00485 pos + pack_length, length, 00486 pos + pack_length, length); 00487 pos+=recinfo[1].length; 00488 } 00489 else 00490 { 00491 if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM) 00492 default_charset_info->cset->casedn(default_charset_info, 00493 pos, keyinfo[0].seg[0].length, 00494 pos, keyinfo[0].seg[0].length); 00495 pos+=recinfo[1].length; 00496 } 00497 00498 if (recinfo[2].type == FIELD_BLOB) 00499 { 00500 char *column; 00501 int length; 00502 length=uint4korr(pos); 00503 memcpy_fixed(&column,pos+4,sizeof(char*)); 00504 memcpy(blob_record,column,length); 00505 bfill(blob_record+length,20,'.'); /* Make it larger */ 00506 length+=20; 00507 int4store(pos,length); 00508 column=blob_record; 00509 memcpy_fixed(pos+4,&column,sizeof(char*)); 00510 } 00511 else if (recinfo[2].type == FIELD_VARCHAR) 00512 { 00513 /* Second field is longer than 10 characters */ 00514 uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1); 00515 uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos); 00516 bfill(pos+pack_length+length,recinfo[2].length-length-pack_length,'.'); 00517 length=recinfo[2].length-pack_length; 00518 if (pack_length == 1) 00519 *(uchar*) pos= (uchar) length; 00520 else 00521 int2store(pos,length); 00522 } 00523 else 00524 { 00525 bfill(pos+recinfo[2].length-10,10,'.'); 00526 } 00527 } 00528 00529 00530 static struct my_option my_long_options[] = 00531 { 00532 {"checksum", 'c', "Undocumented", 00533 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00534 #ifndef DBUG_OFF 00535 {"debug", '#', "Undocumented", 00536 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 00537 #endif 00538 {"delete_rows", 'd', "Undocumented", (gptr*) &remove_count, 00539 (gptr*) &remove_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, 00540 {"help", '?', "Display help and exit", 00541 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00542 {"insert_rows", 'i', "Undocumented", (gptr*) &insert_count, 00543 (gptr*) &insert_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, 00544 {"key_alpha", 'a', "Use a key of type HA_KEYTYPE_TEXT", 00545 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00546 {"key_binary_pack", 'B', "Undocumented", 00547 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00548 {"key_blob", 'b', "Undocumented", 00549 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00550 {"key_cache", 'K', "Undocumented", (gptr*) &key_cacheing, 00551 (gptr*) &key_cacheing, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 00552 {"key_length", 'k', "Undocumented", (gptr*) &key_length, (gptr*) &key_length, 00553 0, GET_UINT, REQUIRED_ARG, 6, 0, 0, 0, 0, 0}, 00554 {"key_multiple", 'm', "Undocumented", 00555 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00556 {"key_prefix_pack", 'P', "Undocumented", 00557 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00558 {"key_space_pack", 'p', "Undocumented", 00559 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00560 {"key_varchar", 'w', "Test VARCHAR keys", 00561 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00562 {"null_fields", 'N', "Define fields with NULL", 00563 (gptr*) &null_fields, (gptr*) &null_fields, 0, GET_BOOL, NO_ARG, 00564 0, 0, 0, 0, 0, 0}, 00565 {"row_fixed_size", 'S', "Undocumented", 00566 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00567 {"row_pointer_size", 'R', "Undocumented", (gptr*) &rec_pointer_size, 00568 (gptr*) &rec_pointer_size, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 00569 {"silent", 's', "Undocumented", 00570 (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 00571 {"skip_update", 'U', "Undocumented", (gptr*) &skip_update, 00572 (gptr*) &skip_update, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 00573 {"unique", 'C', "Undocumented", (gptr*) &opt_unique, (gptr*) &opt_unique, 0, 00574 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 00575 {"update_rows", 'u', "Undocumented", (gptr*) &update_count, 00576 (gptr*) &update_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, 00577 {"verbose", 'v', "Be more verbose", (gptr*) &verbose, (gptr*) &verbose, 0, 00578 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 00579 {"version", 'V', "Print version number and exit", 00580 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 00581 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} 00582 }; 00583 00584 00585 static my_bool 00586 get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 00587 char *argument) 00588 { 00589 switch(optid) { 00590 case 'a': 00591 key_type= HA_KEYTYPE_TEXT; 00592 break; 00593 case 'c': 00594 create_flag|= HA_CREATE_CHECKSUM; 00595 break; 00596 case 'R': /* Length of record pointer */ 00597 if (rec_pointer_size > 3) 00598 rec_pointer_size=0; 00599 break; 00600 case 'P': 00601 pack_keys= HA_PACK_KEY; /* Use prefix compression */ 00602 break; 00603 case 'B': 00604 pack_keys= HA_BINARY_PACK_KEY; /* Use binary compression */ 00605 break; 00606 case 'S': 00607 if (key_field == FIELD_VARCHAR) 00608 { 00609 create_flag=0; /* Static sized varchar */ 00610 } 00611 else if (key_field != FIELD_BLOB) 00612 { 00613 key_field=FIELD_NORMAL; /* static-size record */ 00614 extra_field=FIELD_NORMAL; 00615 } 00616 break; 00617 case 'p': 00618 pack_keys=HA_PACK_KEY; /* Use prefix + space packing */ 00619 pack_seg=HA_SPACE_PACK; 00620 key_type=HA_KEYTYPE_TEXT; 00621 break; 00622 case 'm': 00623 unique_key=0; 00624 break; 00625 case 'b': 00626 key_field=FIELD_BLOB; /* blob key */ 00627 extra_field= FIELD_BLOB; 00628 pack_seg|= HA_BLOB_PART; 00629 key_type= HA_KEYTYPE_VARTEXT1; 00630 break; 00631 case 'k': 00632 if (key_length < 4 || key_length > MI_MAX_KEY_LENGTH) 00633 { 00634 fprintf(stderr,"Wrong key length\n"); 00635 exit(1); 00636 } 00637 break; 00638 case 'w': 00639 key_field=FIELD_VARCHAR; /* varchar keys */ 00640 extra_field= FIELD_VARCHAR; 00641 key_type= HA_KEYTYPE_VARTEXT1; 00642 pack_seg|= HA_VAR_LENGTH_PART; 00643 create_flag|= HA_PACK_RECORD; 00644 break; 00645 case 'K': /* Use key cacheing */ 00646 key_cacheing=1; 00647 break; 00648 case 'V': 00649 printf("test1 Ver 1.2 \n"); 00650 exit(0); 00651 case '#': 00652 DBUG_PUSH (argument); 00653 break; 00654 case '?': 00655 usage(); 00656 exit(1); 00657 } 00658 return 0; 00659 } 00660 00661 00662 /* Read options */ 00663 00664 static void get_options(int argc, char *argv[]) 00665 { 00666 int ho_error; 00667 00668 if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) 00669 exit(ho_error); 00670 00671 return; 00672 } /* get options */ 00673 00674 00675 static void usage() 00676 { 00677 printf("Usage: %s [options]\n\n", my_progname); 00678 my_print_help(my_long_options); 00679 my_print_variables(my_long_options); 00680 }
1.4.7

