History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-1856
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Major Major
Assignee: Simon Mundy
Reporter: Bill Monkman
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Using subquery in from() is broken because of new schema logic

Created: 15/Aug/07 05:51 PM   Updated: 26/Feb/08 12:55 PM
Component/s: Zend_Db_Select
Affects Version/s: 1.0.1
Fix Version/s: 1.0.4

Time Tracking:
Original Estimate: 1 day
Original Estimate - 1 day
Remaining Estimate: 1 day
Remaining Estimate - 1 day
Time Spent: Not Specified
Remaining Estimate - 1 day

 Public Fields   Internal Project Management Fields   
Tags:
Participants: Bill Monkman, julien PAULI, Simon Mundy and Thomas Weidner
Fix Version Priority: Should Have


 Description  « Hide
Using a subquery as the table argument in the from() call used to work fine, like so:

$select = $db->select();
$select->from("(select people.id from people)", "count(id)");

I know there are cleaner ways to get the same result, but this is a simplified version and in some cases it is necessary to do a select like this, for example when doing your own pagination you may want to put the sql from one query into a call like this to find out the number of rows returned from it.

When doing this, if the code in the table argument contains a period, the new schema code on line 358 in Select.php will break the query:

// Schema from table name overrides schema argument
if (false !== strpos($tableName, '.')) { list($schema, $tableName) = explode('.', $tableName); }



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Thomas Weidner - 16/Aug/07 01:30 PM
Assigned to Bill

julien PAULI - 27/Nov/07 02:24 PM
Same behavior with subselect queries with Zend_Db_Select :
$db->select()
->from ('table1', array('t1_label'))
->joinInner(
      array('T2' => new Zend_Db_Expr (
         '('.
         $db->select()
         ->from('table2', array('t2_label'))
         ->where('condition')
         .')'
      )),
      'table1.t2_id = T2.t2_id',
      array('t2_label')
)

breaks it as well :

`(SELECT
``table2```.```t2_label``
FROM ``table2``
WHERE condition)`

patch could be :

if (!$tableName instanceof Zend_Db_Expr && false !== strpos($tableName, '.')) {
            list($schema, $tableName) = explode('.', $tableName);
        }

Simon Mundy - 18/Jan/08 09:38 PM
This use-case can be avoided by using the Zend_Db_Expr object to enclose the subquery.