22 #include <my_global.h>
27 static int get_options(
int argc,
char *argv[]);
29 static int flag=0,verbose=0,remove_ant=0,
flags[50];
31 int main(
int argc,
char **argv)
33 int i,j,error,deleted;
45 get_options(argc,argv);
47 memset(&hp_create_info, 0,
sizeof(hp_create_info));
48 hp_create_info.max_table_size= 1024L*1024L;
49 hp_create_info.keys= 1;
50 hp_create_info.keydef= keyinfo;
51 hp_create_info.reclength= 30;
52 hp_create_info.max_records= (ulong) flag*100000L;
53 hp_create_info.min_records= 10UL;
56 keyinfo[0].seg=keyseg;
57 keyinfo[0].algorithm= HA_KEY_ALG_HASH;
58 keyinfo[0].seg[0].type=HA_KEYTYPE_BINARY;
59 keyinfo[0].seg[0].start=1;
60 keyinfo[0].seg[0].length=6;
61 keyinfo[0].seg[0].charset= &my_charset_latin1;
62 keyinfo[0].seg[0].null_bit= 0;
63 keyinfo[0].flag = HA_NOSAME;
68 printf(
"- Creating heap-file\n");
69 if (heap_create(filename, &hp_create_info, &tmp_share, &unused) ||
70 !(file= heap_open(filename, 2)))
72 printf(
"- Writing records:s\n");
73 strmov((
char*) record,
" ..... key ");
75 for (i=49 ; i>=1 ; i-=2 )
78 sprintf((
char*) key,
"%6d",j);
79 bmove(record+1,key,6);
80 error=heap_write(file,record);
81 if (heap_check_heap(file,0))
83 puts(
"Heap keys crashed");
87 if (verbose || error) printf(
"J= %2d heap_write: %d my_errno: %d\n",
92 printf(
"- Reopening file\n");
93 if (!(file=heap_open(filename, 2)))
96 printf(
"- Removing records\n");
97 for (i=1 ; i<=10 ; i++)
99 if (i == remove_ant) { (void) heap_close(file);
return (0) ; }
100 sprintf((
char*) key,
"%6d",(j=(
int) ((rand() & 32767)/32767.*25)));
101 if ((error = heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT)))
103 if (verbose || (
flags[j] == 1 ||
104 (error && my_errno != HA_ERR_KEY_NOT_FOUND)))
105 printf(
"key: %s rkey: %3d my_errno: %3d\n",(
char*) key,error,my_errno);
109 error=heap_delete(file,record);
110 if (error || verbose)
111 printf(
"key: %s delete: %d my_errno: %d\n",(
char*) key,error,my_errno);
116 if (heap_check_heap(file,0))
118 puts(
"Heap keys crashed");
123 printf(
"- Reading records with key\n");
124 for (i=1 ; i<=25 ; i++)
126 sprintf((
char*) key,
"%6d",i);
127 bmove(record+1,key,6);
129 error=heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT);
131 (error == 0 &&
flags[i] != 1) ||
132 (error && (
flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND)))
134 printf(
"key: %s rkey: %3d my_errno: %3d record: %s\n",
135 (
char*) key,error,my_errno,record+1);
139 #ifdef OLD_HEAP_VERSION
142 printf(
"- Reading records with position\n");
143 for (i=1,found=0 ; i <= 30 ; i++)
146 if ((error=heap_rrnd(file,record,i == 1 ? 0L : (ulong) -1)) ==
149 if (found != 25-deleted)
150 printf(
"Found only %d of %d records\n",found,25-deleted);
155 if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED))
157 printf(
"pos: %2d ni_rrnd: %3d my_errno: %3d record: %s\n",
158 i-1,error,my_errno,(
char*) record+1);
164 if (heap_close(file) || hp_panic(HA_PANIC_CLOSE))
166 my_end(MY_GIVE_INFO);
169 printf(
"got error: %d when using heap-database\n",my_errno);
176 static int get_options(
int argc,
char **argv)
180 while (--argc >0 && *(pos = *(++argv)) ==
'-' ) {
189 remove_ant=atoi(++pos);
192 printf(
"hp_test1 Ver 3.0 \n");