Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

bug in Varien_Db_Adapter_Pdo_Mysql?
 
BabyPower
Jr. Member
 
Total Posts:  4
Joined:  2011-11-30
 

Maybe I just dont understand something, but i found similar questions for error (Cardinality violation: 1242 Subquery returns more than 1 row) and there was no answer. Ok, here is the deal. I’ve been asked to add related products on product view page. It was easy, yet there is _prepareData function in Related block (it is core block catalog/product/list/related) where there is a line:

Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection$quoteId);
Now interesting part. Function addExcludeProductFilter looks like this:

public function addExcludeProductFilter($collection$quoteId)
    
{
        $adapter 
$this->_getReadAdapter();
        
$exclusionSelect $adapter->select()
            ->
from($this->getTable('sales/quote_item'), array('product_id'))
            ->
where('quote_id = ?'$quoteId);
        
$condition $adapter->prepareSqlCondition('e.entity_id', array('nin' => $exclusionSelect));

        
$collection->getSelect()->where($condition);
        return 
$this;
    
}

The problem is in function prepareSqlCondition. if we print the result we will see something like this:

e.entity_id NOT IN((SELECT `sales_flat_quote_item`.`product_idFROM `sales_flat_quote_itemWHERE (quote_id '10')))

I was like wow, value in IN statement (SELECT) is in parentheses, so which will lead u to error “Cardinality violation: 1242 Subquery returns more than 1 row” if it returns more then 1 row, and will make parent query (where it will be joined), return empty selection. When i started to look into why it happens, i found that prepareSqlCondition contains for ‘nin’ statement this statement:

'nin'           => "{{fieldName}} NOT IN(?)"

And when it quotes expression you passed with Zend, Zend will make this checking if($value instanceof Zend_Db_Select ) (And it is), then it will put parentheses again ( return ‘(’ . $value->assemble() . ‘)’; ).

Sorry if my explanation was twisted. So what to do with this now.

Not sure If this is right thread i wanted to put it in developer branch. sorry.

 
Magento Community Magento Community
Magento Community
Magento Community
 
swamsley
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2010-11-01
St. Louis, MO
 

Thank you for reporting this. I have seen this problem in another area of Magento. I discussed it here: http://www.magentocommerce.com/boards/viewthread/263430/. It would be great if the core issue you pointed out could be addressed / resolved.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Manuel_
Jr. Member
 
Total Posts:  12
Joined:  2011-08-24
 

Hi,

thank you for explaining, Is there a fix?

Or is the only solution to upgrade the mysql Version?
I’m on MySQL 5.0.22.

Best Regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
R O B
Jr. Member
 
Avatar
Total Posts:  11
Joined:  2009-06-26
the Netherlands
 

You also change the addExcludeProductFilter method
app/code/core/Mage/Checkout/Model/Resource/Cart.php

$collection->getSelect()->where(new Zend_Db_Expr("e.entity_id NOT IN ({$exclusionSelect})"));
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top