|
Chris, See the do...while and other suggestions inserted below. Vince Rowe MIS Marietta Corp. Cortland, NY USA On Friday 16 July 2004 12:26 pm, Chris Wolcott wrote: > I am trying to write my first SQLC program to get a file field > description from QSYS2/SQLCOLUMNS. It compiles fine. When I run it the > COUNT(*) retunrs 18 into :cnt, which is correct for the specified file. > However, the FETCH only returns 1 row. I can not see *SQLCA in debug. > (We are coding for V4R5M0) > > Also, if I try to add a 'printf' command, the SQL parser chokes on the > edit string saying it is not delimited. How can I do regular C and SQL > if the SQL is going to try to validate all my non-SQL C code? > > I tried COL_NAME & COL_DFT as VARCHARs as well, no difference. I tried > to FETCH FOR :cnt ROWS, still no difference. > > CALL CPYIFS2DB2 PARM('IFS.FILE' 'DB2FILE *CURLIB ') > > Here is my code: > > = = = = = = = = = = = = > > #include "copyright.h" > > #include <stdlib.h> > > #include <string.h> > > #include <fcntl.h> > > #include <unistd.h> > > #include <decimal.h> > > #include <setjmp.h> > > #include <recio.h> > > EXEC SQL BEGIN DECLARE SECTION; > > long cnt; > > char db2Fn[10], db2Lb[10]; > > _Packed struct FLD_DTA { > > long ORD_POS; > > char COL_NAME[1130]; > > char DTA_TYPE; > > long STORAGE; > > long LENGTH; > > long DP; > > char AlwNUL; > > char hasDFT; > > char COL_DFT[2002]; > > } FLD_TBL[2048]; > > _Packed struct { > > short ind[4]; > > } FLD_IND[2048]; > > EXEC SQL > > INCLUDE SQLCA ; exec sql whenever sqlerror go to sqlerrorexit; > > EXEC SQL END DECLARE SECTION; > > /** > > * @param argv[1] IFS File name > > * @param argv[2] Qualified DB2 File name > > * @return Success Indicator > > */ > > int main(int argc, char *argv[]) { > > memcpy(db2Fn, argv[2]+00, 10); > > memcpy(db2Lb, argv[2]+10, 10); > > EXEC SQL > > SELECT COUNT(*) > > INTO :cnt > > FROM QSYS2/SYSCOLUMNS > > WHERE (TABLE_SCHEMA = :db2Lb) AND (TABLE_NAME = :db2Fn); > > EXEC SQL > > DECLARE FLDCUR CURSOR FOR > > SELECT ORDINAL_POSITION, COLUMN_NAME, DATA_TYPE, STORAGE, LENGTH, > > NUMERIC_PRECISION, IS_NULLABLE, HAS_DEFAULT, COLUMN_DEFAULT > > FROM QSYS2/SYSCOLUMNS > > WHERE (TABLE_SCHEMA = :db2Lb) AND (TABLE_NAME = :db2Fn) > > ORDER BY ORDINAL_POSITION ; > > EXEC SQL > > OPEN FLDCUR ; > > EXEC SQL > > FETCH FLDCUR > > FOR 18 ROWS > > INTO :FLD_TBL:FLD_IND ; > > // Tried to put printf here to display SQLCODE & SQLSTATE exec sql whenever not found go to done; do { exec sql fetch FLDCUR for 18 rows into :FLD_TBL, :FLD_IND; printf.......whatever; } while (SQLCODE == 0) done: exec sql close FLDCUR; > > return(cnt); sqlerrorexit: printf........some error message here; > > }
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.