4GL Read file
Posted in 2011
Poul asked how to detect end-of-file with Informix 4GL's newer OPEN FILE/READ/CLOSE FILE statements, since READ returns no obvious EOF flag and the developerWorks article doesn't cover it. Marco Greco said EOF detection appears impossible and pointed to his long-standing fglio I/O package (IIUG repository / 4glworks.com) as an alternative. Jonathan Leffler posted sample code checking STATUS after READ, but testing on I4GL 7.50.FC4 showed broken behaviour: error -4828 at EOF instead of NOTFOUND, plus a p-code BIGINT DISPLAY bug; he logged both as defects (idsdb00234047/234046). Poul reproduced the -4828 and planned to report it to IBM support, so no working fix is recorded beyond using fglio.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hi, I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix 4GL. Could anyone direct me to detailed documentation on it? I can't find any description on how to detect EOF in the READ statement as the READ statement does not seem to return a flag. Any help will be appreciated. Poul H.
http://www.ibm.com/developerworks/data/library/techarticle/dm-1007informix4gl/index.html?ca=drs- phallage <Poul@Hallager.dk> Sent by: informix-list-bounces@iiug.org 13/10/2011 17:17 To informix-list@iiug.org cc Subject 4GL Read file Hi, I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix 4GL. Could anyone direct me to detailed documentation on it? I can't find any description on how to detect EOF in the READ statement as the READ statement does not seem to return a flag. Any help will be appreciated. Poul H. _______________________________________________ Informix-list mailing list Informix-list@iiug.org http://www.iiug.org/mailman/listinfo/informix-list
On 13 Okt., 13:58, Ramesh G Srinivasan <rames...@in.ibm.com> wrote: > http://www.ibm.com/developerworks/data/library/techarticle/dm-1007inf... > > phallage <P...@Hallager.dk> > Sent by: informix-list-boun...@iiug.org > 13/10/2011 17:17 > > To > informix-l...@iiug.org > cc > > Subject > 4GL Read file > > Hi, > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix > 4GL. Could anyone direct me to detailed documentation on it? > I can't find any description on how to detect EOF in the READ > statement as the READ statement does not seem to return a flag. > > Any help will be appreciated. > > Poul H. > _______________________________________________ > Informix-list mailing list > Informix-l...@iiug.orghttp://www.iiug.org/mailman/listinfo/informix-list Thanks! I already read the document, but I don't find any description on how to detect EOF? Poul H.
On 13/10/11 12:47, phallage wrote: > Hi, > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix > 4GL. Could anyone direct me to detailed documentation on it? > I can't find any description on how to detect EOF in the READ > statement as the READ statement does not seem to return a flag. > > Any help will be appreciated. > > Poul H. > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list > I haven't played with it, but looking at the docs, it doesn't seem to me like you can detect EOF at all. If all else fails, in 1996 or thereabout I had written a IO package for 4gl which does exactly what you want and more: head to the IIUG software repository and look for the fglio package. Alternatively, you can find it in my little web site, at http://www.4glworks.com/misc.htm -- Ciao, Marco ______________________________________________________________________________ Marco Greco /UK /IBM Standard disclaimers apply! Structured Query Scripting Language http://www.4glworks.com/sqsl.htm 4glworks http://www.4glworks.com Informix on Linux http://www.4glworks.com/ifmxlinux.htm
On 13 Okt., 15:34, Marco Greco <ma...@4glworks.com> wrote: > On 13/10/11 12:47, phallage wrote:> Hi, > > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix > > 4GL. Could anyone direct me to detailed documentation on it? > > I can't find any description on how to detect EOF in the READ > > statement as the READ statement does not seem to return a flag. > > > Any help will be appreciated. > > > Poul H. > > _______________________________________________ > > Informix-list mailing list > > Informix-l...@iiug.org > >http://www.iiug.org/mailman/listinfo/informix-list > > I haven't played with it, but looking at the docs, it doesn't seem to me like > you can detect EOF at all. > > If all else fails, in 1996 or thereabout I had written a IO package for 4gl > which does exactly what you want and more: head to the IIUG software > repository and look for the fglio package. > Alternatively, you can find it in my little web site, athttp://www.4glworks.com/misc.htm > -- > Ciao, > Marco > ______________________________________________________________________________ > Marco Greco /UK /IBM Standard disclaimers apply! > > Structured Query Scripting Language http://www.4glworks.com/sqsl.htm > 4glworks http://www.4glworks.com > Informix on Linux http://www.4glworks.com/ifmxlinux.htm Thanks Marco, I will look at it one of these days. Regards Poul
On Thu, Oct 13, 2011 at 04:47, phallage <Poul@hallager.dk> wrote: > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix > 4GL. Could anyone direct me to detailed documentation on it? > I can't find any description on how to detect EOF in the READ > statement as the READ statement does not seem to return a flag. > I4GL programs should work off STATUS, roughly like this: -- Testing I4GL Direct File I/O and EOF handling MAIN DEFINE username VARCHAR(32) DEFINE password VARCHAR(32) DEFINE uid INTEGER DEFINE gid INTEGER DEFINE comment VARCHAR(64) DEFINE home VARCHAR(128) DEFINE shell VARCHAR(64) DEFINE fd INTEGER WHENEVER ERROR CONTINUE OPEN FILE fd FROM "/etc/passwd" OPTIONS(READ, FORMAT = 'load', DELIMITER = ':') IF STATUS != 0 THEN DISPLAY "Failed to open /etc/passwd for reading" EXIT PROGRAM 1 END IF WHILE STATUS = 0 READ FROM fd INTO username, password, uid, gid, comment, home, shell IF STATUS != 0 THEN EXIT WHILE END IF DISPLAY "Entry: ", username CLIPPED, " (", password CLIPPED, "),", " [UID=", uid USING "-----&", ", GID=", gid USING "-----&", "]", " Home = <<", home CLIPPED, ">>,", " Shell = <<", shell CLIPPED, ">>" END WHILE IF STATUS < 0 THEN DISPLAY "Read error", STATUS ELSE DISPLAY "EOF found" END IF CLOSE FILE fd END MAIN Unfortunately, this stopped abruptly with error -1215 on the machine I tested with...there was a user: nfsnobody:!!:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin The error is accurate; that number is too big to fit into a 4-byte integer. Things went downhill after that. Change the type of UID and GID to BIGINT and the display stops displaying numbers (in I4GL p-code; the c-code system worked OK). It does however end reading to the end of the file, but then generates error -4828: > -4828 The field to be read from the file file_name should not be greater than 4096 bytes. > The length of the string read from the file exceeds 4096 bytes. Check the field in the file. Possibly, the > file delimiter is misplaced. Neither is acceptable behaviour - though they are independent bugs. In my estimation, the READ should return NOTFOUND on EOF. Tested: I4GL 7.50.FC4 on RHEL 5 (Linux x86/64). The p-code DISPLAY of BIGINT bug is CQ idsdb00234046. The EOF from READ bug is CQ idsdb00234047. -- Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h> Guardian of DBD::Informix - v2011.0612 - http://dbi.perl.org "Blessed are we who can laugh at ourselves, for we shall never cease to be amused."
On 16 Okt., 22:58, Jonathan Leffler <jonathan.leff...@gmail.com> wrote: > On Thu, Oct 13, 2011 at 04:47, phallage <P...@hallager.dk> wrote: > > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix > > 4GL. Could anyone direct me to detailed documentation on it? > > I can't find any description on how to detect EOF in the READ > > statement as the READ statement does not seem to return a flag. > > I4GL programs should work off STATUS, roughly like this: > > -- Testing I4GL Direct File I/O and EOF handling > > MAIN > > DEFINE username VARCHAR(32) > DEFINE password VARCHAR(32) > DEFINE uid INTEGER > DEFINE gid INTEGER > DEFINE comment VARCHAR(64) > DEFINE home VARCHAR(128) > DEFINE shell VARCHAR(64) > DEFINE fd INTEGER > > WHENEVER ERROR CONTINUE > OPEN FILE fd FROM "/etc/passwd" OPTIONS(READ, FORMAT = 'load', > DELIMITER = ':') > IF STATUS != 0 THEN > DISPLAY "Failed to open /etc/passwd for reading" > EXIT PROGRAM 1 > END IF > WHILE STATUS = 0 > READ FROM fd INTO username, password, uid, gid, comment, home, > shell > IF STATUS != 0 THEN > EXIT WHILE > END IF > DISPLAY "Entry: ", username CLIPPED, > " (", password CLIPPED, "),", > " [UID=", uid USING "-----&", ", GID=", gid USING "-----&", > "]", > " Home = <<", home CLIPPED, ">>,", > " Shell = <<", shell CLIPPED, ">>" > END WHILE > IF STATUS < 0 THEN > DISPLAY "Read error", STATUS > ELSE > DISPLAY "EOF found" > END IF > > CLOSE FILE fd > > END MAIN > > Unfortunately, this stopped abruptly with error -1215 on the machine I > tested with...there was a user: > > nfsnobody:!!:4294967294:4294967294:Anonymous NFS > User:/var/lib/nfs:/sbin/nologin > > The error is accurate; that number is too big to fit into a 4-byte integer. > > Things went downhill after that. > > Change the type of UID and GID to BIGINT and the display stops displaying > numbers (in I4GL p-code; the c-code system worked OK). > > It does however end reading to the end of the file, but then generates error > -4828: > > > -4828 The field to be read from the file file_name should not be > > greater than 4096 bytes. > > > The length of the string read from the file exceeds 4096 bytes. Check the > > field in the file. Possibly, the > > > file delimiter is misplaced. > > Neither is acceptable behaviour - though they are independent bugs. In my > estimation, the READ should return NOTFOUND on EOF. > > Tested: I4GL 7.50.FC4 on RHEL 5 (Linux x86/64). > > The p-code DISPLAY of BIGINT bug is CQ idsdb00234046. > The EOF from READ bug is CQ idsdb00234047. > > -- > Jonathan Leffler <jonathan.leff...@gmail.com> #include <disclaimer.h> > Guardian of DBD::Informix - v2011.0612 -http://dbi.perl.org > "Blessed are we who can laugh at ourselves, for we shall never cease to be > amused." Hi Jonathan, Nice to hear from you again! Thanks for your help!. I copied your program into my own environment and modified it for my convenience, and I receive the same 4GL error at eof (-4828) as you do with any text file. The length of the last line does not exceed 4096 bytes and delimiter at end of last line is correct "\\n" as in every line in file. What is "funny" is, that when I display the content of each read line from file, the last line seems to be very long (but actually it is not). So I redirected the output from fglgo to a file to see what actually was read/displayed and I found, that at the last line it inserts 22 blanks and a null and 17 extra newline characters (\\n) before it writes the -4828 read error. So what I will do now is report the -4828 as an error in 4GL to IBM support. Thanks again to everybody for your help! Regards Poul