zendtech / IbmiToolkit

PHP frontend to XMLSERVICE for IBM i development.
BSD 3-Clause "New" or "Revised" License
46 stars 34 forks source link

Show how to handle varchars in sample code #179

Closed NattyNarwhal closed 5 months ago

NattyNarwhal commented 1 year ago

It's not obvious how to handle a program that takes in a varchar. Regular char won't work well, as the length prefix will confuse it. There's also the possibilities where the buffers are smaller. Deal with two and four byte varchars.

Adding an int16/int32 parameter and then a max length of varchar character parameter seems to work, but is this really ideal? What about varying? If it handles varchar, then we should make that clear, and if it doesn't, also make that clear.

alanseiden commented 1 year ago

Would be more efficient if XMLSERVICE had a VARCHAR type and could use the int16/int32 size to know how much of the varchar to return. No one has asked for this efficiency, but could be an interesting challenge to consider how we'd design it. As Calvin noted above, let's study how varying was implemented and if we can learn from it.

alanseiden commented 1 year ago

We only need to specify 'on' or '4' for the sixth parameter ('varying') on AddParameterChar. Varying = VARCHAR.

alanseiden commented 1 year ago

From XMLSERVICE change log (http://www.youngiprofessionals.com/wiki/index.php/XMLService/XMLSERVICEChangeLog):


1.6.11 (new 07–18–2012)     

    BUG: added varying(4) support for RPG V6+ 10A varying(4) — thanks Steph
        Toolkit wrapper (php): see Alan for availability

             Notes: Alan, i believe wrapper needs to flow "varying" parm add to data element 
            varying='on|off|2|4', 
            where varying='on' legacy remains 2 byte length for no impact current scripts 
            Something like this ...
            $ToolkitServiceObj->AddParameterChar('both', 10, 'ZZVARY', 'myVary', 'Ranger', 'on'); // 6th --'on'--is for varying
            -- new -- 
            $ToolkitServiceObj->AddParameterChar('both', 10, 'ZZVARY', 'myVary', 'Ranger', '4'); // 6th --'4'--is for varying(4)

        RAW XML (xmlservice):

              *       <data type='data types' 
              *          [dim='n' varying='on|off|2|4' enddo='label' setlen='label' offset='label'
              *           hex='on|off' before='cc1/cc2/cc3/cc4' after='cc4/cc3/cc2/cc1']> 1.6.8
alanseiden commented 5 months ago

Use of VARCHAR has now been documented on the data types page: https://github.com/zendtech/IbmiToolkit/blob/master/samples/data-types.md