Closed NattyNarwhal closed 1 day ago
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"
}
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.
I was reproducing this on 7.2, but the user was running 7.3.
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.