Hmm, that should not be the case.  If it is, then it's a bug and we'll fix it.

In the meantime, you don't have to use Zend_Db_Select.  You could just write 
out the whole SQL query as a string, including the subquery.  There are other 
cases of complex SQL syntax that is not supported by Zend_Db_Select (such as 
UNION).

Regards,
Bill Karwin

> -----Original Message-----
> From: Bjarte Kalstveit Vebjørnsen [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, July 10, 2007 3:45 PM
> To: [email protected]
> Subject: [fw-general] Problem with Zend_Db_Select and 
> sub-query as join
> 
> Hi, I am refactoring some code from preview 0.2 to 1.0. And I 
> got some trouble in places where I used sub-queries as joins. 
> Here is a small
> example:
> 
> <?php
> require_once 'Zend/Db.php';
> require_once 'Zend/Db/Select.php';
> 
> $params = array ('host'     => '****',
>                  'username' => '****',
>                  'password' => '****',
>                  'dbname'   => '****');
> 
> $db = Zend_Db::factory('pdo_mysql', $params);
> 
> $s1 = new Zend_Db_Select($db);
> $s1->from(array('t1'=>'test'));
> 
> $s2 = new Zend_Db_Select($db);
> $s2->from(array('t2'=>'test2'));
> $s2->join(array('tj'=>new Zend_Db_Expr('('.((string) $s1).')')),
>     'on tj.id = t2.id',
>     array());
> ?>
> 
> This gives the following output:
> 
> SELECT
>       `t2`.*
> FROM `test2` AS `t2`
>  INNER JOIN `(SELECT
>       ``t1```.`*
> FROM ``test`` AS ``t1``)` AS `tj` ON on tj.id = t2.id
> 
> I have also tried without Zend_Db_Expr but no luck.
> How can I get rid of the quoting of the sub-query?
> 
> Best Regards,
> 
> Bjarte
> 

Reply via email to