I have the following struct
typedef struct {
char id[31];
char data[128];
} record;
I created MyISAM files using the following definitions:
memset(recinfo, 0, sizeof(recinfo));
memset(keyinfo, 0, sizeof(keyinfo));
/* let's define two columns like in the "record" struct */
recinfo[0].type = FIELD_NORMAL;
recinfo[0].length = sizeof(data_record.id);
recinfo[1].type = FIELD_NORMAL;
recinfo[1].length = sizeof(data_record.data);
/* lets define the key */
keyinfo[0].seg = &keyseg[0][0];
keyinfo[0].keysegs=1;
keyinfo[0].seg[0].start = 0;
keyinfo[0].seg[0].length = 30;
keyinfo[0].seg[0].type = HA_KEYTYPE_TEXT; /* sort as text */
keyinfo[0].seg[0].flag = 0;
keyinfo[0].flag = (uint8) HA_NOSAME; /* don't allow duplicates */
then I created the myisam files and filled some data into the tables
and tried to look up the data:
void
lookuptest (MI_INFO *file, char *key)
{
record rec;
int res;
memset(&rec, 0, sizeof(rec));
strcpy(rec.id, key);
res = mi_rfirst(file, (byte *) &rec, 0);
if (res != 0) {
fprintf(stderr, "*** Err: %d\n", my_errno);
return;
}
fprintf(stderr, "<RESP> id='%s' data='%s'\n", rec.id, rec.data);
}
giving the entry I am looking for in the "key" parameter. what
happens is that I just get the first row and not the one I am looking
for. what am I missing here?