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

ID: 16765
Updated by: gspiegelberg@gmail.com
Reported By: gspiegelberg at gmail dot com
Summary: Space dropped from query results
Status: Open
Type: Bug
Package: MDB2
Operating System: CentOS 4
-Package Version: 2.4.1
+Package Version: 2.5.0b2
-PHP Version: 5.2.5
+PHP Version: 5.2.10
Roadmap Versions:
New Comment:

-Package Version: 2.4.1
+Package Version: 2.5.0b2
-PHP Version: 5.2.5
+PHP Version: 5.2.10
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.


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

[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

  • Cweiske at Nov 5, 2009 at 4:40 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=16765&edit=1

    ID: 16765
    Updated by: cweiske@php.net
    Reported By: gspiegelberg at gmail dot com
    Summary: Space dropped from query results
    Status: Open
    Type: Bug
    Package: MDB2
    Operating System: CentOS 4
    Package Version: 2.5.0b2
    PHP Version: 5.2.10
    Roadmap Versions:
    New Comment:

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


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

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

    -Package Version: 2.4.1
    +Package Version: 2.5.0b2
    -PHP Version: 5.2.5
    +PHP Version: 5.2.10
    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=''

    ------------------------------------------------------------------------
  • Gspiegelberg at Nov 5, 2009 at 6:14 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=16765&edit=1

    ID: 16765
    Comment by: gspiegelberg@gmail.com
    Reported By: gspiegelberg at gmail dot com
    Summary: Space dropped from query results
    Status: Open
    Type: Bug
    Package: MDB2
    Operating System: CentOS 4
    Package Version: 2.5.0b2
    PHP Version: 5.2.10
    Roadmap Versions:
    New Comment:

    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.


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

    [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

    -Package Version: 2.4.1
    +Package Version: 2.5.0b2
    -PHP Version: 5.2.5
    +PHP Version: 5.2.10
    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=''

    ------------------------------------------------------------------------
  • Danielc at Nov 5, 2009 at 8:50 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=16765&edit=1

    ID: 16765
    Updated by: danielc@analysisandsolutions.com
    Reported By: gspiegelberg at gmail dot com
    Summary: Space dropped from query results
    -Status: Open
    +Status: Bogus
    Type: Bug
    Package: MDB2
    Operating System: CentOS 4
    Package Version: 2.5.0b2
    PHP Version: 5.2.10
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Bogus
    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.


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

    [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

    -Package Version: 2.4.1
    +Package Version: 2.5.0b2
    -PHP Version: 5.2.5
    +PHP Version: 5.2.10
    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=''

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedNov 5, '09 at 4:37p
activeNov 5, '09 at 8:50p
posts4
users4
websitepear.php.net

People

Translate

site design / logo © 2022 Grokbase