1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "isamdef.h"
static void get_options(int argc, char *argv[]);
static int rec_pointer_size=0,verbose=0,remove_ant=0,pack_keys=1,flags[50],
packed_field=FIELD_SKIP_PRESPACE;
int main(int argc, char *argv[])
{
N_INFO *file;
int i,j,error,deleted,found;
char record[128],key[32],*filename,read_record[128];
N_KEYDEF keyinfo[10];
N_RECINFO recinfo[10];
MY_INIT(argv[0]);
filename= (char*) "test1";
my_init();
get_options(argc,argv);
keyinfo[0].seg[0].base.type=HA_KEYTYPE_NUM;
keyinfo[0].seg[0].base.flag=(uint8) (pack_keys ?
HA_PACK_KEY | HA_SPACE_PACK : 0);
keyinfo[0].seg[0].base.start=0;
keyinfo[0].seg[0].base.length=6;
keyinfo[0].seg[1].base.type=HA_KEYTYPE_END;
keyinfo[0].base.flag = (uint8) (pack_keys ?
HA_NOSAME | HA_PACK_KEY : HA_NOSAME);
recinfo[0].base.type=packed_field; recinfo[0].base.length=6;
recinfo[1].base.type=FIELD_NORMAL; recinfo[1].base.length=24;
recinfo[2].base.type=FIELD_LAST;
deleted=0;
bzero((byte*) flags,sizeof(flags));
printf("- Creating isam-file\n");
if (nisam_create(filename,1,keyinfo,recinfo,
(ulong) (rec_pointer_size ? (1L << (rec_pointer_size*8))/40 :
0),10l,0,0,0L))
goto err;
if (!(file=nisam_open(filename,2,HA_OPEN_ABORT_IF_LOCKED)))
goto err;
printf("- Writing key:s\n");
strmov(record," ..... key"); strappend(record,30,' ');
my_errno=0;
for (i=49 ; i>=1 ; i-=2 )
{
j=i%25 +1;
sprintf(key,"%6d",j);
bmove(record,key,6);
error=nisam_write(file,record);
flags[j]=1;
if (verbose || error)
printf("J= %2d nisam_write: %d errno: %d\n", j,error,my_errno);
}
if (nisam_close(file)) goto err;
printf("- Reopening file\n");
if (!(file=nisam_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err;
printf("- Removing keys\n");
for (i=1 ; i<=10 ; i++)
{
if (i == remove_ant) { VOID(nisam_close(file)) ; exit(0) ; }
sprintf(key,"%6d",(j=(int) ((rand() & 32767)/32767.*25)));
my_errno=0;
if ((error = nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT)))
{
if (verbose || (flags[j] == 1 ||
(error && my_errno != HA_ERR_KEY_NOT_FOUND)))
printf("key: %s nisam_rkey: %3d errno: %3d\n",key,error,my_errno);
}
else
{
error=nisam_delete(file,read_record);
if (verbose || error)
printf("key: %s nisam_delete: %3d errno: %3d\n",key,error,my_errno);
flags[j]=0;
if (! error)
deleted++;
}
}
printf("- Reading records with key\n");
for (i=1 ; i<=25 ; i++)
{
sprintf(key,"%6d",i);
bmove(record,key,6);
my_errno=0;
error=nisam_rkey(file,read_record,0,key,0,HA_READ_KEY_EXACT);
if (verbose ||
(error == 0 && flags[i] != 1) ||
(error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND)))
{
printf("key: %s nisam_rkey: %3d errno: %3d record: %s\n",
key,error,my_errno,record+1);
}
}
printf("- Reading records with position\n");
for (i=1,found=0 ; i <= 30 ; i++)
{
my_errno=0;
if ((error=nisam_rrnd(file,read_record,i == 1 ? 0L : NI_POS_ERROR)) == -1)
{
if (found != 25-deleted)
printf("Found only %d of %d records\n",found,25-deleted);
break;
}
if (!error)
found++;
if (verbose || (error != 0 && error != 1))
{
printf("pos: %2d nisam_rrnd: %3d errno: %3d record: %s\n",
i-1,error,my_errno,read_record+1);
}
}
if (nisam_close(file)) goto err;
my_end(MY_CHECK_ERROR);
exit(0);
err:
printf("got error: %3d when using nisam-database\n",my_errno);
exit(1);
return 0; /* skipp warning */
} /* main */
/* l{ser optioner */
/* OBS! intierar endast DEBUG - ingen debuggning h{r ! */
static void get_options(int argc, char *argv[])
{
char *pos;
while (--argc >0 && *(pos = *(++argv)) == '-' ) {
switch(*++pos) {
case 'R': /* Length of record pointer */
rec_pointer_size=atoi(++pos);
if (rec_pointer_size > 3)
rec_pointer_size=0;
break;
case 'P':
pack_keys=0; /* Don't use packed key */
break;
case 'S':
packed_field=FIELD_NORMAL; /* static-size record*/
break;
case 'v': /* verbose */
verbose=1;
break;
case 'm':
remove_ant=atoi(++pos);
break;
case 'V':
printf("isamtest1 Ver 1.0 \n");
exit(0);
case '#':
DEBUGGER_ON;
DBUG_PUSH (++pos);
break;
}
}
return;
} /* get options */
|