Active Record - from() and alias escaping (MySQL)
$this->db->select('update.*, user.*');
$this->db->where('user.id = update.user_id', null);
$this->db->from('issue_updates AS update');
$this->db->from('users AS user');
$query = $this->db->get();
This results in the query:
SELECT `update`.*, `user`.* FROM (`issue_updates` AS update, `users` AS user) WHERE `user`.`id` = update.user_id
Resulting error:
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 'update,
usersAS user) WHEREuser.id= update.user_id' at line 2
Apparently the table name alias is not escaped, so "update" causes an error.
Is this with CI 2.1 or the develop branch code?
This is CI 2.1.0.
(Sorry, forgot.)
Turns out both are affected anyway, I'll look into it probably tomorrow.
@joellimberg See the referenced commit for the fix.
Thanks, works perfectly.
I wanted to comment about there being a bug about _escape_identifiers() vs escape_identifiers(), but this is just because I'm using 2.1.0, and only merged the few changed lines.
Well, it is a bug - escape_identifiers() doesn't exist in the 2.1-stable branch. Fixed in the last commit, you can just put the underscore in front of it. :)
This fix broke session deletion when using the mysql db backend with CI 2.1.1:
DELETE FROM `ci_sessions` WHERE `last_activity` `< 1339434355`
Notice that the quote is before the < instead of after it.