Improving/Fixing count-query
svogel - March 29, 2008 - 20:12
| Project: | Ajax Table |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I nearly searched my head off why some queries do and some don't work with ajaxtables until I found.
While
$table = array(
'query' => "SELECT * FROM {node}",
...works, this
$table = array(
'query' => "select *
from {node}",
...does not! I like to format those queries a bit with newlines, especially if they are a bit longer than the example above.
But in ajaxtable.module line 358 the count is calculated as:
$count_query = preg_replace('/SELECT (.*) FROM/','SELECT COUNT(' . $count_inner . ') FROM',$table['query']);This does not match the second alternative above and so the "empty"-phrase is shown everytime.
I would suggest to turn the pattern into:
$count_query = preg_replace('/SELECT\s+(.*)\s+FROM/i','SELECT COUNT(' . $count_inner . ') FROM',$table['query']);
which allows "multiple" (at least one) whitespaces AND ignore case.
Best regards and thanks for a wonderful module
Stefan

#1
Just checked the actual stable version (5.x-1.2) and found the same issue there.