FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=16765&edit=1

  ID: 16765
  Comment by: jeffjung
  Reported By: truebiz@hotmail.com
  Summary: Space dropped from query results
  Status: Bogus
  Type: Bug
  Package: MDB2
  Operating System: CentOS 4
  Package Version: 2.5.0b2
  PHP Version: 5.2.10
  New Comment:
This is intended behavior. When data is extracted from CHAR() columns,
some DBMS'es trim the extra spaces while some don't. So to provide
consistent results, MDB removes the trailing white space.

Whether to remove the trailing white space or not should be controlled
by option value to provide true consistency.


Previous Comments:
------------------------------------------------------------------------

[2009-11-05 21:50:14] danielc

<div id="changeset">
<span class="removed">-Status: Open</span>
<span class="added">+Status: Bogus</span>
</div>This is intended behavior. When data is extracted from CHAR()
columns, some DBMS'es trim the extra spaces while some don't. So to
provide consistent results, MDB removes the trailing white space.

------------------------------------------------------------------------

[2009-11-05 19:14:29] gspiegelberg

The workaround is to connect with the option
'portability' => MDB2_PORTABILITY_ALL - MDB2_PORTABILITY_RTRIM

If this is a MySQL behavior, perhaps the RTRIM option ought to be
available only if the database connection is to MySQL. IMHO, altering
the data returned by a query shouldn't be the responsibility of the
database abstraction layer.

Not sure this is a bug now. I'll leave it to the maintainers to decide.

------------------------------------------------------------------------

[2009-11-05 17:40:02] cweiske

on mysql, this was standard behavior (trailing whitespace was trimmed
before mysql 5.something)

------------------------------------------------------------------------

[2009-11-05 17:37:05] gspiegelberg

<div id="changeset">
<span class="removed">-Package Version: 2.4.1</span>
<span class="added">+Package Version: 2.5.0b2</span>
<span class="removed">-PHP Version: 5.2.5</span>
<span class="added">+PHP Version: 5.2.10</span>
</div>Meant to say in the description that I believe the test script
illustrates the problem.

Also, I have tested this using MDB2 2.5.0b2 and PHP 5.2.10. The bug is
still present.

------------------------------------------------------------------------

[2009-11-04 23:54:23] gspiegelberg

Description:
------------
I have verified that a field in a return result containing a space only
is being reduced to an empty string. I believe the test script below

Test script:
---------------
<?php
require_once('MDB2.php');
// Setup using stock pg functions
$conn = pg_connect("host=127.0.0.1 port=5432 dbname=test user=portal");
pg_exec($conn, "CREATE TABLE x (id int, chars varchar(32));");
pg_exec($conn, "INSERT INTO x VALUES (1, ' ');");
pg_exec($conn, "INSERT INTO x VALUES (2, 'z');");
// The test query
$test_sql = "SELECT * FROM x WHERE id=1 AND chars=' ';";
// Test using pg_query & pg_fetch_all
$results = pg_query($conn, $test_sql);
$rows = pg_fetch_all($results);
echo "id={$rows[0]['id']} chars='{$rows[0]['chars']}'\n";

$dbh = MDB2::connect(
  array('phptype'=>'pgsql', 'username'=>'portal',
'hostspec'=>'127.0.0.1', 'port'=>5432, 'database'=>'test'),
  array('debug'=>2,'portability'=>MDB2_PORTABILITY_ALL));
$mdb2_result = $dbh->query($test_sql);
$mdb2_rows = $mdb2_result->fetchAll(MDB2_FETCHMODE_ASSOC);
echo "id={$mdb2_rows[0]['id']} chars='{$mdb2_rows[0]['chars']}'\n";
?>

Expected result:
----------------
Expecting to see a space between the single quotes for both lines.
id=1 chars=' '
id=1 chars=' '


Actual result:
--------------
The second line doesn't have a space between the single quotes.
id=1 chars=' '
id=1 chars=''

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJun 20, '13 at 11:07a
activeJun 20, '13 at 11:07a
posts1
users1
websitepear.php.net

1 user in discussion

Jeffjung: 1 post

People

Translate

site design / logo © 2022 Grokbase