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
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())
-
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– Richard2014年12月03日 16:23:59 +00:00Commented Dec 3, 2014 at 16:23
-
I will know it because I can dump the query at the lib/Zend/Db* classes.Detzler– Detzler2014年12月03日 16:51:30 +00:00Commented Dec 3, 2014 at 16:51
-
AUTO_QUOTE_IDENTIFIERS sounds good. I've dumped the config. It's already true by defaultDetzler– Detzler2014年12月03日 16:52:19 +00:00Commented Dec 3, 2014 at 16:52