BTW, I believe you CAN use a varying-length variable, but it shouldn't be based on a pointer into the DS - it should be a stand-alone variable and be set to the value in the structure.

HTH
Vern

On 1/15/2020 7:06 PM, Vernon Hamberg wrote:
I think I see the problem, Chris - EZDQLSTL is defined as an integer - it is the length of the SQL statement, not the statement itself.

There are a couple elements that are described as "varying" - IIRC, that doesn't mean they are a varying-length field, just that the length is not fixed in the data structure, and the length is in the above-noted element. In working with APIs like this, you have to use the offsets and lengths provided. The SQL statement doesn't have an offset in the DS, since it is always at a fixed point, but the "extended cursor name" DOES have an offset, because it is located at different places in the DS, depending on the length of each instance, where the statements are not the same length.

you'll need to modify things - you can use a pointer, perhaps, to the element that follows EZDQLSTL, then a substring on the variable there and use the length for that.

Have fun!! It's API heaven!

Vern

On 1/15/2020 6:44 PM, Chris Holko wrote:
This whole process is invoked through the exit point QIBM_QZDA_SQL2 with format ZDAQ0200.


Upper is 128 bytes because I needed something small enough to test with when I connected via ODBC.  We have in production statements exceeding 32k and I only log a set size which would be bigger than 128 but less than 32k

I was trying to simplify the substring of the passed data and though that varying fields would handle it.




COPY BOOK
D*******************************************************************
D*Typedef for the SQL exit point format #2 @A1A
D*******************************************************************
DEZDSQLF2         DS
D*                                             Qzda SQL Format2
D EZDUP05                 1     10
D*                                   User profile name
D EZDSID05               11     20
D*                                   Server identifier
D EZDFN06                21     28
D*                                   User exit format name
D EZDFID05               29     32I 0
D*                                   Requested function id
D EZDSN00                33     50
D*                                   Statement name
D EZDCN00                51     68
D*                                   Cursor name
D EZDPO00                69     70
D*                                   Prepare option
D EZDOA00                71     72
D*                                   Open attributes
D EZDPN01                73     82
D*                                   Package name
D EZDPLN00               83     92
D*                                   Package library name
D EZDRDACI00             93     94I 0
D*                                   DRDA connect indicator
D EZDCI00                95     95
D*                                   Commit indicator
D EZDDSQLL               96    105
D*                                   Default SQL Collection @A1A
D EZDRSV1               106    108
D*                                   Reserved               @B2A
D EZDOECN               109    112I 0
D*                                   Offset to ext'd cursor @B2A
D EZDLECN               113    116I 0
D*                                   Length of ext'd cursor @B2A
D EZDRSV2               117    234
D*                                   Res. for future use    @B2C
D EZDQLSTL              235    238I 0
D*                                   Length of SQL Stmt text@A1A
D*EZDSQLST00            239    239
D*
D*                                   Varying length
D*                                /* SQL statement text     @B2C
D*EZDECN00              240    240
D*
D*                                    Varying length        @B2A
D*                                   Extended cursor name   @B2A



On Jan 15, 2020, at 2:10 PM, Justin Taylor <JUSTIN@xxxxxxxxxxxxx> wrote:

I'd guess a pointer problem.  How is EZDQLSTL defined, and how's it loaded?



-----Original Message-----
From: Chris Holko [mailto:christopherholko@xxxxxxxxx]
Sent: Wednesday, January 15, 2020 12:43 PM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: How do I clip a vary length field?

Okay, I am truly lost here. I am missing something really simple. this is a quick test program that fails when called by the exit with RNQ0115 when it does the upper=sqlstuff

RNQ0115 is Length of varying length variable is out of range.





**FREE

/copy qsysinc/qrpglesrc,ezdaep
  Dcl-s  pEZDQLSTL  pointer  inz( %Addr( EZDQLSTL ) );

  Dcl-s  SQLStuff  VarChar(32000: 4)  Based( pEZDQLSTL  );

  Dcl-s  Upper   Varchar(128);

  dcl-pr  ODBCEXIT   extpgm('ODBCEXITN');
          allow         char(1);
          datain        likeds(EZDSQLF2);
  end-pr;

  dcl-pi  ODBCEXIT;
          allow         char(1);
          datain        likeds(EZDSQLF2);


allow = *on;
Upper = SQLStuff;  // This will truncate to 1024 if needed.

*inlr = *on;

return;


--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com



This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2020 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].