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.

Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Dec 3, 2014 at 14:42

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())
David Manners
27.3k9 gold badges78 silver badges220 bronze badges
answered Dec 3, 2014 at 16:07
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. Commented Dec 3, 2014 at 16:23
  • I will know it because I can dump the query at the lib/Zend/Db* classes. Commented Dec 3, 2014 at 16:51
  • AUTO_QUOTE_IDENTIFIERS sounds good. I've dumped the config. It's already true by default Commented Dec 3, 2014 at 16:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.