Welcome Guest, Not a member yet? Register   Sign In
$this->_protect_identifiers not affected by $this->db->flush_cache();
#1

[eluser]a&w[/eluser]
Perhaps this might be more unexpected behavior than outright bug. If you flush the cache the _protect_identifiers setting remains whatever was last set, unless you explicitly pass the "$escape" parameter.

I'd suggest either some fix or at least a caution in the user guide that if you're using that 2nd parameter at all, that you should probably use it for all select statements of that query, otherwise it uses the last entry (not the default of TRUE any longer.

Code:
/**
     * Select
     *
     * Generates the SELECT portion of the query
     *
     * @access    public
     * @param    string
     * @return    object
     */
    function select($select = '*', $escape = NULL)
    {
        // Set the global value if this was sepecified    
        if (is_bool($escape))
        {
            $this->_protect_identifiers = $escape;
        }

Instead of:
Code:
function select($select = '*', $escape = NULL)
Why not use:
Code:
function select($select = '*', $escape = TRUE)

Seems like it starts off as true, so why wouldn't that be the default instead of using the last setting it was passed? That or seems like it should respect the flush cache request.
#2

[eluser]a&w[/eluser]
Seems the behavior is more widespread than I thought.

User guide has:
Quote:Protecting identifiers
In many databases it is advisable to protect table and field names - for example with backticks in MySQL. Active Record queries are automatically protected, however if you need to manually protect an identifier you can use:

$this->db->protect_identifiers('table_name');

Seems the above is also affected by whatever was last set. So if you use:

Code:
$this->db->select($select, false);

Than all subsequent $this->db->from() also will use whatever that boolean was set as.

While the user guide suggests you can set protect identifier explicitly, I don't see that to be the case as:

Code:
function protect_identifiers($item, $prefix_single = FALSE)
    {
        return $this->_protect_identifiers($item, $prefix_single);
    }
Note, no 3rd argument!!!

So when you get here, the 3rd argument is null and whatever the last setting was is used.

Code:
function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
    {
        if ( ! is_bool($protect_identifiers))
        {
            $protect_identifiers = $this->_protect_identifiers;
        }

Solution?? Just allow a 3rd argument?
Code:
function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL)
    {
        return $this->_protect_identifiers($item, $prefix_single, $protect_identifiers);
    }




Theme © iAndrew 2016 - Forum software by © MyBB