Welcome Guest, Not a member yet? Register   Sign In
CI_DB_driver::_protect_identifiers breaks when using table.* select
#1

[eluser]Unknown[/eluser]
Hi,

i seem to have stumbled on what looks like another "incompatibility" between _protect_identifiers() and the sql queries people want to see. Basically, if you try to select all fields from one table in a query, the star ("*") character gets the backtick treatment just as if it were a regular field name. Thus, by calling it like this:
Code:
$this->db->select('table.*')->get('table');
we get this:
Code:
SELECT `users`.`*` FROM (`users`)
instead of that:
Code:
SELECT `users`.* FROM (`users`)
It appears that the method does not check against reserved identifiers if it contains more than one segment that is also not an alias (the other cases do have the check). I hacked a small fix for that, in case someone else gets stuck with a similiar problem. All that's needed is to replace line 1281 in system/database/DB_driver.php:
Code:
$item = $this->_escape_identifiers($item);
with these four lines:
Code:
$last_part = array_pop($parts);
if(!in_array($last_part, $this->_reserved_identifiers))
    $item = $this->_escape_identifiers($item);
else
    $item = $this->_escape_identifiers(implode('.', $parts)).'.'.$last_part;
There. Hope that helps Smile

I'm not sure whether i should've filed a bug report for this, since there seem to be multiple other issues with this same function for other people...


Messages In This Thread
CI_DB_driver::_protect_identifiers breaks when using table.* select - by El Forum - 11-10-2008, 08:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB