Problem in file outputs
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
This is a multi-part message in MIME format. ------=_NextPart_000_0069_01BEE425.0F6CBD20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi All, I was wondering whether anyone could help me with the below peice of = code in ESQL/C. The result in the file 'out.txt' that I'm expecting is : "Hello. <Value from the BLOB (byte) cloumn t_byte in table t_test1> = Goodbye." But the result I'm obtaining is=20 "<Value from the BLOB (byte) cloumn t_byte in table t_test1> Hello. = Goodbye." Why is this so? Informix version 7.24 UC5 int fd; FILE *fp; fp =3D fopen("out.txt", "a+"); fprintf(fp,"%s","Hello."); close(fp); fd =3D open("out.txt", O_WRONLY); EXEC SQL connect to 'dbname'; byte1.loc_loctype =3D LOCFILE; byte1.loc_fd =3D fd; byte1.loc_oflags =3D LOC_APPEND; EXEC SQL select t_byte into :byte1 from t_test1 where t_num=3D1; EXEC SQL disconnect current; close(fd); fp =3D fopen("out.txt", "a+"); fprintf(fp,"%s","Goodbye."); close(fp); ------=_NextPart_000_0069_01BEE425.0F6CBD20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2014.210" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi All,</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>I was wondering whether anyone could = help me with=20 the below peice of code in ESQL/C.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>The result in the file 'out.txt' that = I'm expecting=20 is :</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>"Hello. <Value from the BLOB (byte) = cloumn=20 t_byte in table t_test1> Goodbye."</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>But the result I'm obtaining is = </FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2>"<Value from the BLOB (byte) cloumn = t_byte in=20 table t_test1> Hello. Goodbye."</FONT></DIV></FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Why is this so? Informix version 7.24=20 UC5</FONT></DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>int fd;</FONT></DIV> <DIV><FONT face=3DArial size=3D2>FILE *fp;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>fp =3D fopen("out.txt", = "a+");</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>fprintf(fp,"%s","Hello.");</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>close(fp);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>fd =3D open("out.txt", = O_WRONLY);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>EXEC SQL connect to = 'dbname';</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>byte1.loc_loctype =3D = LOCFILE;<BR>byte1.loc_fd =3D=20 fd;<BR>byte1.loc_oflags =3D LOC_APPEND;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>EXEC SQL select t_byte into :byte1 from = t_test1=20 where t_num=3D1;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>EXEC SQL disconnect = current;</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>close(fd);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2>fp =3D fopen("out.txt", = "a+");</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2>fprintf(fp,"%s","Goodbye.");</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2>close(fp);</FONT></DIV></FONT></DIV></BODY></HTML> ------=_NextPart_000_0069_01BEE425.0F6CBD20--
george wrote: > > This is a multi-part message in MIME format. > > ------=_NextPart_000_0069_01BEE425.0F6CBD20 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > Hi All, > > I was wondering whether anyone could help me with the below peice of = > code in ESQL/C. > The result in the file 'out.txt' that I'm expecting is : > > "Hello. <Value from the BLOB (byte) cloumn t_byte in table t_test1> = > Goodbye." > > But the result I'm obtaining is=20 > > "<Value from the BLOB (byte) cloumn t_byte in table t_test1> Hello. = > Goodbye." > > Why is this so? Informix version 7.24 UC5 > > int fd; > FILE *fp; > > fp =3D fopen("out.txt", "a+"); > > fprintf(fp,"%s","Hello."); > > close(fp); > > fd =3D open("out.txt", O_WRONLY); The file is truncated to zero bytes by this call to open, effectively discarding your previously written data. You'd have to use some other mode, probably O_RDWR, possibly some values for the (optional) 3rd argument to open. > EXEC SQL connect to 'dbname'; > > byte1.loc_loctype =3D LOCFILE; > byte1.loc_fd =3D fd; > byte1.loc_oflags =3D LOC_APPEND; > > EXEC SQL select t_byte into :byte1 from t_test1 where t_num=3D1; > > EXEC SQL disconnect current; > > close(fd); > > fp =3D fopen("out.txt", "a+"); > > fprintf(fp,"%s","Goodbye."); > > close(fp); > -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>
Related threads
- Conversion to differeent characters sets
- Problem in changing locale via dbexport/dbimport
- RE: openlink error "Unable to load locale categories"