Welcome Guest, Not a member yet? Register   Sign In
A bug in Active Record class
#1

[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.'`';


Messages In This Thread
A bug in Active Record class - by El Forum - 12-29-2012, 03:43 AM
A bug in Active Record class - by El Forum - 12-29-2012, 08:29 AM
A bug in Active Record class - by El Forum - 12-29-2012, 11:11 AM
A bug in Active Record class - by El Forum - 12-30-2012, 05:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB