× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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

  return(cnt); 

} 


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.