Bug #69967 [NEW]: char columns always return maximum length
From: buschmann at nidsa dot net
Operating system: Windows 8.1 x64
PHP version: 7.0.0alpha2
Package: PostgreSQL related
Bug Type: Bug
Bug description:char columns always return maximum length
Description:
------------
/* ################# ERROR Results in PHP
##############################
// the ERROR is that char strings retrieved by pg_fetch_assoc (or
similar calls) always return the maximum length of the column
// i.E when we select the fix string, the database always returns the
correct length (pgflen) but php always gives 6 (phpflen)!!!!
// for better illustration, in phpfixreplace all blanks returned are
replaced with #
// this has been tested with php 5.6.10 and php 7 alpha 2 and seems to
be similar on other versions and platforms (not tested)
// platform: windows 8.1 64 bit, Apache 64bit 2.4.12 VC14, php TS in 64
bit,
// module extension=php_pgsql.dll
below the output:
v-- ERROR
v-- ERROR
cfix = pgfix = ## pgflen = 0 phpflen = 6 phpfix = [ ] phpfixreplace =
[######]
Test script:
---------------
<?php
$conexion=pg_connect('CONNECTION_STRING');
$sqlIns="select
length(cfix) as pgflen, cfix, '#'||cfix||'#' as pgfix
,length(cvar) as pgvlen, cvar, '#'||cvar||'#' as pgvar
from ctest";
$rS=pg_query($sqlIns);
while($fs=pg_fetch_assoc($rS)){
echo "<table>";
echo "<tr><td> cfix = ".$fs['cfix']." pgfix =
".$fs['pgfix']." pgflen =
".$fs['pgflen']." phpflen = ".strlen($fs['cfix']).
" phpfix = [".$fs['cfix']."] phpfixreplace = [".str_replace('
','#',$fs['cfix'])."]</td></tr>"
;
echo "<tr><td> cvar = ".$fs['cvar']." pgvar =
".$fs['pgvar']." pgvlen =
".$fs['pgvlen']." phpvlen = ".strlen($fs['cvar']).
" phpvar = [".$fs['cvar']."] phpvarreplace = [".str_replace('
','#',$fs['cvar'])."]</td></tr>";
;
echo "</table>";
}
?>
Expected result:
----------------
/*
// create the table and fill with test strings in Postgres
create table ctest (
cfix char(6),
cvar varchar (6)
);
insert into ctest values
('',''),
('f2','v2'),
('f6f6f6','v6v6v6')
;
// select in psql
db=# select
db-# length(cfix) as flen, cfix, '#'||cfix||'#' as pgfix
db-# ,length(cvar) as vlen, cvar, '#'||cvar||'#' as pgvar
db-# from ctest
db-# ;
flen | cfix | pgfix | vlen | cvar | pgvar
------+--------+----------+------+--------+----------
0 | | ## | 0 | | ##
2 | f2 | #f2# | 2 | v2 | #v2#
6 | f6f6f6 | #f6f6f6# | 6 | v6v6v6 | #v6v6v6#
(3 Zeilen)
*/
Actual result:
--------------
below the output:
v-- ERROR
v-- ERROR
cfix = pgfix = ## pgflen = 0 phpflen = 6 phpfix = [ ] phpfixreplace =
[######]
cvar = pgvar = ## pgvlen = 0 phpvlen = 0 phpvar = [] phpvarreplace = []
cfix = f2 pgfix = #f2# pgflen = 2 phpflen = 6 phpfix = [f2 ]
phpfixreplace = [f2####]
cvar = v2 pgvar = #v2# pgvlen = 2 phpvlen = 2 phpvar = [v2]
phpvarreplace = [v2]
cfix = f6f6f6 pgfix = #f6f6f6# pgflen = 6 phpflen = 6 phpfix = [f6f6f6]
phpfixreplace = [f6f6f6]
cvar = v6v6v6 pgvar = #v6v6v6# pgvlen = 6 phpvlen = 6 phpvar = [v6v6v6]
phpvarreplace = [v6v6v6]
--
Edit bug report at https://bugs.php.net/bug.php?id=69967&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69967&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69967&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69967&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69967&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69967&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69967&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69967&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69967&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69967&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69967&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69967&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69967&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69967&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69967&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69967&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69967&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69967&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69967&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69967&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69967&r=mysqlcfg
Thread (7 messages)
- buschmann at nidsa dot net