Search code examples
mysqlmagentozend-dbmagento-1.8

Magento, modify Zend_Db_Select SET group_concat_max_len


I'm trying to update / add a setting to a Magento getSelect() query statement, but I'm not quite sure where to add it.

I need to make sure that SET group_concat_max_len = 32768 for the following query:

$this->getSelect()->joinLeft(array('order_item_tbl'=>$this->getTable('sales/order_item')),
                    'order_item_tbl.order_id = main_table.entity_id',
                    array(
                        'product_names' => new Zend_Db_Expr('GROUP_CONCAT(order_item_tbl.`name` SEPARATOR \'\n\')'),
                        'skus' => new Zend_Db_Expr('GROUP_CONCAT(order_item_tbl.`sku` SEPARATOR \'\n\')'),
                        'product_ids' => new Zend_Db_Expr('GROUP_CONCAT(order_item_tbl.`product_id` SEPARATOR \'\n\')'),
                        'product_options' => new Zend_Db_Expr('GROUP_CONCAT(order_item_tbl.`product_options` SEPARATOR \'^\')'),
                        'total_qty_refunded' => new Zend_Db_Expr('SUM(order_item_tbl.`qty_refunded`)'),
                        'total_qty_invoiced' => new Zend_Db_Expr('SUM(order_item_tbl.`qty_invoiced`)')
                    ))
                    ->where('order_item_tbl.`parent_item_id` IS NULL');

Solution

  • I guess this should work ,get connection from core resource as write mode usually used for insert/update purpose but you can also run your query

    $res=Mage::getSingleton('core/resource');
    
    $connection = $res->getConnection('core_write');
    
    $connection->query('SET group_concat_max_len = 32768');
    

    Raw queries in mangento