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

ID: 15879
Updated by: daniel.oconnor@gmail.com
Reported By: admin at triplevision dot nl
Summary: error sort with databasename attached.
Status: Open
Type: Bug
Package: Structures_DataGrid_DataSource_DataObject
Operating System: debian
PHP Version: 5.2.5
Roadmap Versions:
New Comment:

The text leading up to this was:
--------------------------
--- DataObject.php 2009-02-03 16:22:00.000000000 +0100
+++ 20090203_DataObject.php 2009-02-03 16:21:07.000000000 +0100
--------------------------
File to patch: DataObject.php
patching file DataObject.php
Hunk #1 FAILED at 474.
1 out of 1 hunk FAILED -- saving rejects to file DataObject.php.rej


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

[2009-02-04 09:01:56] rud5gtriplevision

i couldn't upload a patch (error: should be a text file)

so i attached it as a comment.


kind regards,

Rudger Gravestein

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

[2009-02-04 09:01:00] rud5gtriplevision

--- DataObject.php 2009-02-03 16:22:00.000000000 +0100
+++ 20090203_DataObject.php 2009-02-03 16:21:07.000000000 +0100
@@ -474,15 +474,7 @@
if (is_array($sortSpec)) {
foreach ($sortSpec as $field => $direction) {
$field = $this->_convertLinkKey($field);
- if (strpos ($field, '.') !== false) {
- $field = explode ('.', $field);
- foreach ($field as $i => $f) {
- $field[$i] = $db->quoteIdentifier ($f);
- }
- $field = implode ('.', $field);
- } else {
- $field = $db->quoteIdentifier($field);
- }
+ $field = $db->quoteIdentifier($field);
$this->_dataobject->orderBy("$field $direction");
}
} else {

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

[2009-02-04 08:46:50] rud5gtriplevision

Description:
------------
when sorting through setDefaultSort, i need to add the database name,
because i use a join with two tables with an ambiguous field: updated_ts
(on which i want to sort).

result is (part of the SQL):

...ORDER BY `tablename.updated_ts` DESC;

this gives a SQL error:
"DB Error: no such field"
[nativecode=1054 ** Unknown column 'tablename.updated_ts' in 'order
clause']

this is because, in the file:
/pear/Structures/DataGrid/DataSource/DataObject.php quoteIdentifier is
used on the entire field, which in this case also contains the
tablename.

i have an patch, which i will upload to this report.
(the patch is only used in the case of passing the sort variables as an
array, so check it.)

Test script:
---------------
$do = DB_DataObject::factory ('tablename');
$jt = DB_DataObject::factory ('jointable');

$do->joinAdd ($jt);

$dg =& new Structures_DataGrid ();
$dg->setDefaultSort (array ('tablename.updated_ts' => 'DESC'));

Expected result:
----------------
the expected result is (part of the SQL):

...ORDER BY `databasename`.`updated_ts` DESC;

Actual result:
--------------
the actual result is (part of the SQL):

...ORDER BY `databasename.updated_ts` DESC;

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

Search Discussions

  • Daniel Oconnor at Dec 27, 2011 at 5:42 am
    Edit report at https://pear.php.net/bugs/bug.php?id=15879&edit=1

    ID: 15879
    Updated by: daniel.oconnor@gmail.com
    Reported By: admin at triplevision dot nl
    Summary: error sort with databasename attached.
    -Status: Open
    +Status: Feedback
    Type: Bug
    Package: Structures_DataGrid_DataSource_DataObject
    Operating System: debian
    PHP Version: 5.2.5
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Feedback
    Thank you for taking the time to report a problem with the package.
    This problem may have been already fixed by a previous change that
    is in the SVN of the package. Please checking out the SVN
    repository of this package and upgrade

    svn checkout
    svn.php.net/repository/pear/packages/Structures_DataGrid_DataSource_DataObject/trunk
    pear upgrade package2.xml

    or

    pear upgrade package.xml

    If you are able to reproduce the bug with the latest SVN,
    please change the status back to "Open".
    Again, thank you for your continued support of PEAR.

    Either your patch is backwards or it's already fixed in git.


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

    [2011-12-27 06:40:36] doconnor

    The text leading up to this was:
    --------------------------
    --- DataObject.php 2009-02-03 16:22:00.000000000 +0100
    +++ 20090203_DataObject.php 2009-02-03 16:21:07.000000000 +0100
    --------------------------
    File to patch: DataObject.php
    patching file DataObject.php
    Hunk #1 FAILED at 474.
    1 out of 1 hunk FAILED -- saving rejects to file DataObject.php.rej

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

    [2009-02-04 09:01:56] rud5gtriplevision

    i couldn't upload a patch (error: should be a text file)

    so i attached it as a comment.


    kind regards,

    Rudger Gravestein

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

    [2009-02-04 09:01:00] rud5gtriplevision

    --- DataObject.php 2009-02-03 16:22:00.000000000 +0100
    +++ 20090203_DataObject.php 2009-02-03 16:21:07.000000000 +0100
    @@ -474,15 +474,7 @@
    if (is_array($sortSpec)) {
    foreach ($sortSpec as $field => $direction) {
    $field = $this->_convertLinkKey($field);
    - if (strpos ($field, '.') !== false) {
    - $field = explode ('.', $field);
    - foreach ($field as $i => $f) {
    - $field[$i] = $db->quoteIdentifier ($f);
    - }
    - $field = implode ('.', $field);
    - } else {
    - $field = $db->quoteIdentifier($field);
    - }
    + $field = $db->quoteIdentifier($field);
    $this->_dataobject->orderBy("$field $direction");
    }
    } else {

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

    [2009-02-04 08:46:50] rud5gtriplevision

    Description:
    ------------
    when sorting through setDefaultSort, i need to add the database name,
    because i use a join with two tables with an ambiguous field: updated_ts
    (on which i want to sort).

    result is (part of the SQL):

    ...ORDER BY `tablename.updated_ts` DESC;

    this gives a SQL error:
    "DB Error: no such field"
    [nativecode=1054 ** Unknown column 'tablename.updated_ts' in 'order
    clause']

    this is because, in the file:
    /pear/Structures/DataGrid/DataSource/DataObject.php quoteIdentifier is
    used on the entire field, which in this case also contains the
    tablename.

    i have an patch, which i will upload to this report.
    (the patch is only used in the case of passing the sort variables as an
    array, so check it.)

    Test script:
    ---------------
    $do = DB_DataObject::factory ('tablename');
    $jt = DB_DataObject::factory ('jointable');

    $do->joinAdd ($jt);

    $dg =& new Structures_DataGrid ();
    $dg->setDefaultSort (array ('tablename.updated_ts' => 'DESC'));

    Expected result:
    ----------------
    the expected result is (part of the SQL):

    ...ORDER BY `databasename`.`updated_ts` DESC;

    Actual result:
    --------------
    the actual result is (part of the SQL):

    ...ORDER BY `databasename.updated_ts` DESC;

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedDec 27, '11 at 5:40a
activeDec 27, '11 at 5:42a
posts2
users1
websitepear.php.net

1 user in discussion

Daniel Oconnor: 2 posts

People

Translate

site design / logo © 2022 Grokbase