CIsam question (isopen cf. iseek)
Posted in 2000
Topics: General Discussion
Can someone tell me what is the difference between isopen and iseek in CIsam? I need to access a file on two keys. I think I should be using isopen??? I have a multi level index and need to fetch all records with certain values in TWO of the keys. What should I be doing? Kate Sent via Deja.com http://www.deja.com/ Before you buy.
Kate Juliff wrote: > Can someone tell me what is the difference between isopen and iseek in > CIsam? Am I raining on the parade if I simply point out that isopen() is a C-ISAM function and iseek() is not? > I need to access a file on two keys. I think I should be using isopen??? You need to use isopen() to gain access to the file at all. You may need to open the file twice (two separate calls to isopen()), or there again, that may achieve nothing. Do you need to be able to position in the same file at the same time using two separate indexes? You can only use one key at a time on one C-ISAM file descriptor, so the only way it could work is if you open the file twice. However, C-ISAM tends to have a rather dogmatic view about what constitutes opening a file (so that if you do a chdir(2) between two opens and try to open a new file with the same name but in two different directories, you will get the same file opened twice). I'm not certain that you will not get two independent C-ISAM file descriptors, but be wary of the issue. > I have a multi level index and need to fetch all records with certain > values in TWO of the keys. What should I be doing? Let's assume I'm being overly pessimistic. Suppressing error checking: int isfd1 = isopen("file", ...); int isfd2 = isopen("file", ...); struct keydesc key1; struct keydesc key2; key1.k_flags = ..; key1.k_nparts = ...; key1.k_part[0].kp_start = ...; key1.k_part[0].kp_leng = ...; key1.k_part[0].kp_type = ...; ... key2.k_flags = ..; key2.k_nparts = ...; key2.k_part[0].kp_start = ...; key2.k_part[0].kp_leng = ...; key2.k_part[0].kp_type = ...; ... isstart(isfd1, &key1, keyval1len, keyval1, ISFIRST); isstart(isfd2, &key2, keyval2len, keyval2, ISFIRST); isread(isfd1, rec1, ISCURR+ISLOCK); isread(isfd2, rec2, ISCURR+ISLOCK); -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>
> Am I raining on the parade if I simply point out that > isopen() is a C-ISAM function and iseek() is not? Sorry. I meant to write isstart.... In the manual I have it says: If your C-Isam file has other indexes, you can find and retrieve records (with isread) using the keys of the another index after you choose the index with the isstart function call. Does this mean I can retrieve according to two indxex values? And yes, I "need to be able to position in the same file at the same time using two separate indexes?" Kate > > > I need to access a file on two keys. I think I should be using isopen??? > > You need to use isopen() to gain access to the file at all. > > You may need to open the file twice (two separate calls > to isopen()), or there again, that may achieve nothing. > > Do you need to be able to position in the same file at the > same time using two separate indexes? You can only use one > key at a time on one C-ISAM file descriptor, so the only way > it could work is if you open the file twice. However, C-ISAM > tends to have a rather dogmatic view about what constitutes > opening a file (so that if you do a chdir(2) between two opens > and try to open a new file with the same name but in two > different directories, you will get the same file opened twice). > I'm not certain that you will not get two independent C-ISAM > file descriptors, but be wary of the issue. > Sent via Deja.com http://www.deja.com/ Before you buy.
Kate Juliff wrote: > > Am I raining on the parade if I simply point out that > > isopen() is a C-ISAM function and iseek() is not? > > Sorry. I meant to write isstart.... > > In the manual I have it says: > If your C-Isam file has other indexes, you can find and retrieve > records (with isread) using the keys of the another index after you > choose the index with the isstart function call. > > Does this mean I can retrieve according to two index values? > > And yes, I "need to be able to position in the same file at the > same time using two separate indexes?" I think the only way you can do that is by opening the file twice. The prototype for the isread() function is: int isread(int isfd, char *record, int mode); Granted, the record is used both for input and output (yuck!), but you cannot change the index in use with isread(). Compare with isstart(): int isstart(int isfd, struct keydesc *key, int keylen, char *record, int mode); The struct keydesc part tells it which index to use. I'm prepared to believe I was being unduly pessimistic when I cautioned against opening the same file twice with C-ISAM; I have not tested that you can actually do so, though, and the SE optimizer never tries to do it. However, that may be more of a comment on the optimizer than on C-ISAM. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>