Re: Problem opening/closing more Informix C-isam files
Posted in 2003
Topics: General Discussion
Stefan Smeets wrote: > Hi, > I have the following problem in Informix C-Isam under Windows 2000, with > Microsoft Visual C/C++: > I open f.e. 5 isam files together. > Then I close these 5 files. > The program gives an exception after opening the 3th file. > It gives also an exception when I close the second file, if two files are > open. > Is there a problem with the c-isam library, or with the compilation option ? > I use Informix C-Isam v.7.25 (mentioned on CD-ROM). > Here the code of testing: > > #include <stdio.h> > #include <fcntl.h> > #include <sys/types.h> > #include <sys/stat.h> > #include <io.h> > #include <errno.h> > #include <isam.h> > > main() Should be int main(void) on most systems - MS Win2K might have other views. > { > int i,j; > int fd[2048]; > char fname[256]; > int RecordSize=128; > struct keydesc sKey; // Pointer to key descriptor > > sKey.k_flags = ISNODUPS; > sKey.k_nparts = 1; > sKey.k_part[0].kp_start = 0; > sKey.k_part[0].kp_leng = 10; > sKey.k_part[0].kp_type = CHARTYPE; > > for (i=1;i<100i++) { > sprintf(fname,"c:\\\\temp\\\\file%04d",i); > if ((fd[i] = isbuild(fname,RecordSize,&sKey,ISINOUT+ISEXCLLOCK)) < 0) { > fprintf(stderr, "Error opening is file %s - errno: %d iserrno: > %d\\n",fname, errno, iserrno); > j=i-1; > i=2048; > } > } That's some pretty weird logic. You start as if you're going to run i from 1 to 99, but then you play with i setting it 2048, so the loop terminates after one cycle - creating one file. You've stashed the ISAM file descriptor into fd[1], and set j to 0. > for (i=1;i<j;i++) { > if (isclose(fd[i]) < 0) { > fprintf(stderr, "Error closing file %d\\n",i); > } > } Here you run from 1 up to a value less than 0 (j), or do no iterations of the loop. This is also excessively weird. It also bears no resemblance to the circumstances you describe in your outline. So, you'd probably best send the code that really does crash - this might or might not crash, but it doesn't open 5 files. Or have you solved the problem already? I doubt if you'll be able to open 2048 C-ISAM files - I don't think C-ISAM has that many slots in its internal table of C-ISAM file descriptors. > printf("Program ended\\n"); > exit(0); > } On most systems, you'd do as well with return(0) instead of exit(0). You should include <stdlib.h> to get the declaration of exit(). -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
Jonathan Leffler wrote: > Stefan Smeets wrote: <SNIP> > >> >> for (i=1;i<100i++) { >> sprintf(fname,"c:\\\\temp\\\\file%04d",i); >> if ((fd[i] = isbuild(fname,RecordSize,&sKey,ISINOUT+ISEXCLLOCK)) < >> 0) { >> fprintf(stderr, "Error opening is file %s - errno: %d iserrno: >> %d\\n",fname, errno, iserrno); >> j=i-1; >> i=2048; >> } >> } > > > That's some pretty weird logic. You start as if you're going to run i > from 1 to 99, but then you play with i setting it 2048, so the loop > terminates after one cycle - creating one file. You've stashed the > ISAM file descriptor into fd[1], and set j to 0. Follow the brackets. Let's reformat: for (i=1;i<100i++) /* ; missing? */ { sprintf(fname,"c:\\\\temp\\\\file%04d",i); if ((fd[i] = isbuild(fname,RecordSize,&sKey,ISINOUT+ISEXCLLOCK)) < 0) { /* On error, print the error, set to i to 2048 to end the loop, then set j to the actual number we _did_ open */ fprintf(stderr, "Error opening is file %s - errno: %d iserrno: %d\\n",fname, errno, iserrno); j=i-1; i=2048; } } > >> for (i=1;i<j;i++) { >> if (isclose(fd[i]) < 0) { >> fprintf(stderr, "Error closing file %d\\n",i); >> } >> } > > > Here you run from 1 up to a value less than 0 (j), or do no iterations > of the loop. <SNIP> for i = 1, i less than the number we succeeded in opening, add one each itteration... I think you read that last post just a little quickly... -- Scott Burns Mirrabooka Systems Tel +61 7 3857 7899 Fax +61 7 3857 1368