Bug #15436 [Fbk->Dup]: Broken SQL
| From: | wiesemann@php.net | Date: | Sat, 07 Mar 2009 16:06:28 +0000 |
| Subject: | Bug #15436 [Fbk->Dup]: Broken SQL | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-108@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=15436&edit=1
ID: 15436
Updated by: wiesemann@php.net
Reported By: michael at stellarent dot com
Summary: Broken SQL
-Status: Feedback
+Status: Duplicate
Type: Bug
Package: Structures_DataGrid
Operating System: Fedora 6
Package Version: 0.9.0
PHP Version: 5.1.6
Assigned To: wiesemann
Roadmap Versions:
New Comment:
<div id="changeset">
<span class="removed">-Status: Feedback</span>
<span class="added">+Status: Duplicate</span>
</div>
No feedback. => Duplicate of bug #13339.
Previous Comments:
------------------------------------------------------------------------
[2009-01-22 16:03:10] wiesemann
Michael, thanks for the patch. And sorry about the confusion about the
complexity of the regexp -- I had another expression in mind; this one
is rather trivial, of course.
Anyway, your report is a duplicate of bug #13339, which already has
been fixed in CVS. Can you please try it with this version?
=>
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/DataSource.php?view=log
------------------------------------------------------------------------
[2009-01-16 06:05:20] mpgjunky
Hi Mark,
I have uploaded a suggested patch. On my end it works fine. Test sql
query without trailing ORDER BY and with. In both cases it works as
expected.
Hope you will consider the patch good enough to be applied.
------------------------------------------------------------------------
[2009-01-15 19:06:37] mpgjunky
Hi Mark,
The trouble is I am not getting wrong record counts, the is perfectly
fine.
The trouble is specifically with regex that reformats the query, and
appends the ORDER BY incorrectly (if there's an already an order by in a
subquery).
I would expect this to work since the documentation states:
"... and for the case of subqueries, this driver already has special
handling."
I can appreciate the complexity the regex currently employed in
parsing/reformatting the query, but at the same time the query I am
using is very valid. I am certain lots of people have similar needs.
Mike.
------------------------------------------------------------------------
[2009-01-15 11:05:55] wiesemann
Michael, thanks for your report, but this problem is already covered in
the manual:
"If you use complex queries (e.g. with complex joins or with aliases),
$datagrid->getRecordCount() might return a wrong result. For the case of
GROUP BY, UNION, or DISTINCT in your queries, and for the case of
subqueries, this driver already has special handling. However, if you
observe wrong record counts, you need to specify a special query that
returns only the number of records (e.g. 'SELECT COUNT(*) FROM ...') as
an additional option 'count_query' to the bind() call."
http://pear.php.net/manual/en/package.structures.structures-datagrid.structures-datagrid-datasource.dbquery.php
You can understand the "if you observe wrong record counts" also as "if
you observer a broken query". The regular expression that is used is
already complex, and handling more cases will make the expression even
more complex (and non-understandable).
------------------------------------------------------------------------
[2009-01-15 10:35:46] mpgjunky
Hi Daniel,
Not quite sure what you mean, but the initial (or master) sql is
static, then passed on the datagrid in the bind method. The bind method
obviously manipulates it.
The statement works, it's been tested on it's own, mysql is not at
fault, I can assure you.
It looks like it gets it's knickers in a twist when trying to add the
'ORDER BY' at the end of the statement. Somehow the order by in the left
join is confusing it.
Look at the resulting SQL from datagrid (print_r):
[last_query] => select a.*, substr(a.description,1, 30) as
description,
b.userid, b.name, c.category
from annon_tickets as a
left join (select * from users_table_new group by email order by
adate desc) as b on a.email = b.email
LEFT JOIN support_categories as c on a.id_cat = c.id,
adate
DESC LIMIT 0, 20 <<== the 'order by' is wrong.
It looks to me like the 'order by' in the left join makes it think
there's already an 'order by' on the entire statement, so the method
$dg->setDefaultSort( array('adate' => 'DESC') ) causes it to append
",
adate DESC LIMIT 0, 20" to the end of the statement.
Actual behavior should be to append " ORDER BY adate DESC LIMIT 0,
20" to the end of the statement.
I can give you a test script, but it's really not required. All that is
needed are 3 tables of your choice and my sql statement modified for
your table references/fields. Run it by mysql and it will work, run it
datagrid and it will fail.
Mike.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=15436
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=15436&edit=1