4

I've got a query which returns the orders by considering a condition on the column "maxvalue":

Mage::getModel('sales/order')->getCollection()->addFieldToFilter('maxvalue', 'bla')

It generates following invalid SQL :

SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` WHERE (maxvalue = 'bla')

Since a mysql upgrade, "maxvalue" is a reserved keyword, it can not be left unquoted. So it must be:

... WHERE (`maxvalue` = 'bla')

... addFieldToFilter('`maxvalue`', 'bla')

Is it possible to set globally a kind of auto-column-name-quotation for the query builder?

UPDATE.. I'm using an extensioon which is ioncube-obfuscated, so there is no possibility to change the code. So I thought there would be another solution e.g. auto-quotation of field names by setting a global directive.

1 Answer 1

3

If your example is really that simple you can just cheat

$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->where("`maxvalue` = 'blah'");
Mage::log((string)$collection->getSelect())
3
  • Well, you can try and set Zend_Db::AUTO_QUOTE_IDENTIFIERS, but I think the zend code looks like you actually need pass an option to quoteIdentifier to get it to obey the option. If it's obfuscated code, you won't know if that will fix it either, even if it works.
    – Richard
    Dec 3, 2014 at 16:23
  • I will know it because I can dump the query at the lib/Zend/Db* classes.
    – Detzler
    Dec 3, 2014 at 16:51
  • AUTO_QUOTE_IDENTIFIERS sounds good. I've dumped the config. It's already true by default
    – Detzler
    Dec 3, 2014 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.