RE: Problems selecting varchar using SDK 2.30UC1
Posted in 1999
>Art S. Kagel wrote:
>
> Tino Cremidis wrote:
> >
> > Hello,
> >
> > I am having strange results when fetching data
> > from a varchar column. I guess it is better to
> > show the problem rather than try to explain it.
> >
> > 1) Create a table and populate it with two rows:
> >
> > Database stores7;
> > Create table work1 (
> > col1 varchar(10)
> > )>
> OK
>
> > Insert into work1 values ('123456');
> > Insert into work1 values ('ABC');>
> So far, so good. Using what tool? Dbaccess or an ESQL/C program?
Any tool, we just need data in the table.
>
> > 2) Then, using the demo program provided by
> > informix: /usr/informix/demo/esqlc/dyn_sql.ec
>
> Hmmmmmm, here's a posible culprit.
>
> > execute the following select statement,
> > SELECT * from WORK1;> >
> > On my system the output looks something like:
> > col1 : 123456
> > col2 : ABC456
>
> Uh, huh! And what do you get from executing that select from within
> dbaccess or Jonathan's sqlcmd utility? I suspect that there is a bug in
> dyn_sql.ec which is fetching the column as ESQL/C type VARCHAR which
> strips the trailing spaces and does not NULL terminate and so the
> trailing 3 chars from the previous record are being printed out also.
>
Dbaccess returns the data correctely.
I just downloaded and compiled (using SDK-2.30-UC1), and installed
the latest version of SQLCMD (sqlcmd-48). And I still have the problem.
Attached is a small ESQL/C program that reproduces the problem.
> Art S. Kagel
>
>
> > My environment: AIX 4.3, SDK 2.30 UC1, Online 7.31.UC2A
> >
> > Any ideas?
> >
> > Tino
>
Tino
========================================
EXEC SQL include sqlhdr;
int main(int argc, char *argv[]) {
EXEC SQL BEGIN DECLARE SECTION;
varchar vardata[256];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER ERROR STOP;
EXEC SQL DATABASE "stores7";
EXEC SQL EXECUTE IMMEDIATE "CREATE TEMP TABLE WORK2 ( col1
varchar(10) )";
EXEC SQL EXECUTE IMMEDIATE "INSERT INTO WORK2 VALUES ('123456') ";
EXEC SQL EXECUTE IMMEDIATE "INSERT INTO WORK2 VALUES ('ABC') ";
EXEC SQL EXECUTE IMMEDIATE "INSERT INTO WORK2 VALUES ('1234567') ";
EXEC SQL EXECUTE IMMEDIATE "INSERT INTO WORK2 VALUES ('ABCD') ";
EXEC SQL PREPARE sel FROM "SELECT * FROM work2";
EXEC SQL DECLARE C1 CURSOR FOR sel;
EXEC SQL OPEN C1;
for ( ;; )
EXEC SQL FETCH c1 into :vardata;
if ( sqlca.sqlcode != 0 )
break;
printf("The Data --->%s<---\\n",vardata);
}
}
============================================================