Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix garbage in column names on IBM i #61

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Conversation

NattyNarwhal
Copy link
Member

A user reported an issue where the column names can have garbage at the end in some situations; in this case, it seems to be using QP2SHELL while also have the CCSID set to 65535. It seems SQL/CLI doesn't null terminate the names when this happens. Arguably a bug in SQL/CLI, and arguably on the user as QP2SHELL requires you to set up the environment yourself, but unfortunately CCSID 65535 and QP2SHELL usage are common.

This resolves the issue by truncating with name_length, which is still set correctly.

A user reported an issue where the column names can have garbage at the
end in some situations; in this case, it seems to be using QP2SHELL
while also have the CCSID set to 65535. It seems SQL/CLI doesn't null
terminate the names when this happens. Arguably a bug in SQL/CLI, and
arguably on the user as QP2SHELL requires you to set up the environment
yourself, but unfortunately CCSID 65535 and QP2SHELL usage are common.

This resolves the issue by truncating with `name_length`, which is still
set correctly.
@NattyNarwhal
Copy link
Member Author

NattyNarwhal commented Nov 14, 2024

Need to figure out a unit test that works, but the test program:

<?php

$c = db2_connect("*LOCAL", "", "");

$q = <<<SQL
select cusnum as "Customer Name",
        lstnam as "Last Name",
        init as "Middle Initial",
        street as "Street Address",
        state as "State",
        zipcod as "Zip Code",
        cdtlmt as "Credit Limit",
        chgcod as "Charged Cod",
        baldue as "Balance Due",
        cdtdue as "Credit Due" from qiws.qcustcdt
SQL;

$s = db2_prepare($c, $q);
db2_execute($s);
while (($r = db2_fetch_assoc($s)) != false) {
        var_dump($r);
}

Command line to reproduce on i:

chgjob ccsid(65535)
call qp2shell parm('/QOpenSys/pkgs/bin/php' '/home/calvin/long_col.php')

Results before:

 array(10) {
     ["Customer Name???"]=>
     string(6) "583990"
     ["Last NameName???"]=>
     string(8) "Abrams  "
     ["Middle Initial??"]=>
     string(3) "M T"
     ["Street Address??"]=>
     string(13) "392 Mill St  "
     ["Statet Address??"]=>
     string(2) "MN"
     ["Zip Codeddress??"]=>
     string(5) "56342"
     ["Credit Limitss??"]=>
     string(4) "9999"
     ["Charged Codtss??"]=>
     string(1) "3"
     ["Balance Duetss??"]=>
     string(6) "500.00"
     ["Credit Dueetss??"]=>
     string(3) ".00"
   }

@kadler
Copy link
Contributor

kadler commented Nov 14, 2024

AFAICT looking at the 7.3 and 7.4 CLI code, it should be null-terminating it, but I haven't tested it. Easy enough workaround.

@NattyNarwhal
Copy link
Member Author

I was reproducing this on 7.2, but the user was running 7.3.

@NattyNarwhal NattyNarwhal merged commit 8f50036 into master Nov 27, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants