ZF-2739: Zend_Db_Select and Oracle with clause limit()
Description
Until rev.7576, the implementation of the clause limit() functioned in Oracle. The new operation of __toString() broke the functionality.
For information: Oracle has no clause limit(), we must simulate it with subqueries and ROWNUM. So we obtain a string like this: "SUBQUERY . SQL . SUBQUERY".
The new __toString() implode the differents elements.
Instead of:
SELECT z2.* FROM
( SELECT ROWNUM AS zend_db_rownum, z1.* FROM (
SELECT tab_charge.num_charge
FROM tab_charge
ORDER BY date_charge DESC ) z1
) z2
WHERE z2.zend_db_rownum BETWEEN 1 AND 15
I have:
SELECT tab_charge.num_charge
FROM tab_charge
ORDER BY date_charge DESC
SELECT z2.* FROM
( SELECT ROWNUM AS zend_db_rownum, z1.* FROM ( ) z1
) z2
WHERE z2.zend_db_rownum BETWEEN 1 AND 15
Comments
Posted by Darby Felton (darby) on 2008-02-27T13:11:47.000+0000
Assigning to [~peptolab] for initial review.
Posted by Mickael Perraud (mikaelkael) on 2008-03-12T05:54:42.000+0000
Andre Vignaud in this message propose modifications in Zend_Db_Select:
and
Posted by Simon Mundy (peptolab) on 2008-03-12T09:05:10.000+0000
I've refactored Zend_Db_Select to more gracefully handle the various transformations to the query. Can you please verify the limit() method is now behaving itself?
Fixed in trunk r8784
Posted by Wil Sinclair (wil) on 2008-04-21T15:03:16.000+0000
Was this fixed in 1.5.1? If not, could you get it verified, merge back to 1.5 branch, and mark it fixed for 1.5? If so, could you mark it fixed for 1.5.1?
Thanks.
Posted by Mickael Perraud (mikaelkael) on 2008-04-21T15:41:54.000+0000
This was fixed effectively for me in rév. 8784 (for 1.5.1) but not merge back to 1.5.0.
Posted by Gabriel Baez (gabriel) on 2008-05-28T06:25:56.000+0000
I'm using Zend Framework 1.5.2 and this function is not working for me, I get the following error:
SQLSTATE[HY000]: General error: 918 OCIStmtExecute: ORA-00918: column ambiguously defined
(ext\pdo_oci\oci_statement.c:146)
PHO Code:
$select = $this->db->select() ->from(array('p' => 'HARDWARE_JOBS_VW'), array('HARDWARE_ID','NAME','ACCOUNT','PASSWORD','TYPE_NAME','GROUP_ID','PLATFORM_NAME'))
->join(array('pf' =>'USERS_IN_GROUPS'), 'p.GROUP_ID=pf.GROUP_ID')
->where('pf.USER_ID= ?', $id)
->where('p.GROUP_ID= ?',$groupid) ->limit($page,$limit);
Posted by Gabriel Baez (gabriel) on 2008-05-28T06:30:56.000+0000
This is the output from __toString();
{quote} SELECT z2.*
, pf.* FROM HARDWARE_JOBS_VW p
INNER JOIN USERS_IN_GROUPS pf ON p.GROUP_ID=pf.GROUP_ID WHERE (pf.USER_ID= '8') AND (p.GROUP_ID= '21'
)
{/quote}
Posted by Mickael Perraud (mikaelkael) on 2008-05-28T09:11:54.000+0000
Hi,
It is not due to the limit() part but this is due to "join(array('pf' =>'USERS_IN_GROUPS')". In this you select also pf.GROUP_ID so in Z1, you have p.GROUP_ID and pf.GROUP_ID. To resolve this you can add an alias to the first table like this:
Posted by Gabriel Baez (gabriel) on 2008-05-28T11:02:06.000+0000
Thanks that fixed it.