dbTalk Databases Forums  

4GL Read file

comp.databases.informix comp.databases.informix


Discuss 4GL Read file in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
phallage
 
Posts: n/a

Default 4GL Read file - 10-13-2011 , 06:47 AM






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.

Reply With Quote
  #2  
Old   
Ramesh G Srinivasan
 
Posts: n/a

Default Re: 4GL Read file - 10-13-2011 , 06:58 AM






http://www.ibm.com/developerworks/da...x.html?ca=drs-




phallage <Poul (AT) Hallager (DOT) dk>
Sent by: informix-list-bounces (AT) iiug (DOT) org
13/10/2011 17:17

To
informix-list (AT) iiug (DOT) 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 (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
  #3  
Old   
phallage
 
Posts: n/a

Default Re: 4GL Read file - 10-13-2011 , 07:12 AM



On 13 Okt., 13:58, Ramesh G Srinivasan <rames... (AT) in (DOT) ibm.com> wrote:
Quote:
http://www.ibm.com/developerworks/da...cle/dm-1007inf...

phallage <P... (AT) Hallager (DOT) dk
Sent by: informix-list-boun... (AT) iiug (DOT) org
13/10/2011 17:17

To
informix-l... (AT) iiug (DOT) 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... (AT) iiug (DOT) 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.

Reply With Quote
  #4  
Old   
Marco Greco
 
Posts: n/a

Default Re: 4GL Read file - 10-13-2011 , 08:34 AM



On 13/10/11 12:47, phallage wrote:
Quote:
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 (AT) iiug (DOT) 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

Reply With Quote
  #5  
Old   
phallage
 
Posts: n/a

Default Re: 4GL Read file - 10-13-2011 , 08:56 AM



On 13 Okt., 15:34, Marco Greco <ma... (AT) 4glworks (DOT) com> wrote:
Quote:
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... (AT) iiug (DOT) 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

Reply With Quote
  #6  
Old   
Jonathan Leffler
 
Posts: n/a

Default Re: 4GL Read file - 10-16-2011 , 03:58 PM



On Thu, Oct 13, 2011 at 04:47, phallage <Poul (AT) hallager (DOT) dk> wrote:

Quote:
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:

Quote:
-4828 The field to be read from the file file_name should not be
greater than 4096 bytes.

Quote:
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 (AT) gmail (DOT) 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."

Reply With Quote
  #7  
Old   
phallage
 
Posts: n/a

Default Re: 4GL Read file - 10-17-2011 , 02:26 AM



On 16 Okt., 22:58, Jonathan Leffler <jonathan.leff... (AT) gmail (DOT) com>
wrote:
Quote:
On Thu, Oct 13, 2011 at 04:47, phallage <P... (AT) hallager (DOT) 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. *Inmy
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... (AT) gmail (DOT) 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.