[eluser]Unknown[/eluser]
There is a bug in the class CI_DB_active_rec.
For the SQL produced with select_max() / select_min() / select_avg() method, the field (column) name is unquoted.
While this is fine for most column names we use in our database, when I have a column name with keywords like "order", the query will not run, and produce error like that :
Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order FROM (`table_name`)' at line 1
SELECT MAX(`order`) AS order FROM (`table_name`)
But I expect the query to be
Code:
SELECT MAX(`order`) AS `order` FROM (`table_name`)
I am using the latest version of CodeIgniter, version 2.1.3.
To solve this problem, I have to modify /system/database/DB_active_rec.php, line 199, and change this :
Code:
$sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
to this
Code:
$sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS `'.$alias.'`';