New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Undefined property: SQL_Translations::$previous_query #285

Open
tnjturner opened this Issue Jun 12, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@tnjturner
Copy link

tnjturner commented Jun 12, 2018

This warning Notice: Undefined property: SQL_Translations::$previous_query is thrown several times when debugging is turned on. I found that the issue points to the below method in wp-includes/translations.php. Searching it appears that this is pointing to a variable that isn't defined, but more to the point the if statement is looking at $query and then references $this->previous_query. Replacing $this->previous_query with $query solved the warnings.

    function translate_sqlcalcrows($query)
    {
        if (stripos($query, 'SQL_CALC_FOUND_ROWS') > 0 ) {
            $sql_calc_pos = stripos($query, 'SQL_CALC_FOUND_ROWS');
            $from_pos = stripos($query, 'FROM');
            $query = substr_replace($query,'* ', $sql_calc_pos, ($from_pos - $sql_calc_pos));
        }
        // catch the next query.
        if ( stripos($query, 'FOUND_ROWS()') > 0 ) {
            $from_pos = stripos($this->previous_query, 'FROM');
            $where_pos = stripos($this->previous_query, 'WHERE');
            $from_str = trim(substr($this->previous_query, $from_pos, ($where_pos - $from_pos)));
            $order_by_pos = stripos($this->previous_query, 'ORDER BY');
            $where_str = trim(substr($this->previous_query, $where_pos, ($order_by_pos - $where_pos)));
            $query = str_ireplace('FOUND_ROWS()', 'COUNT(1) as Computed ' . $from_str . ' ' . $where_str, $query);
        }
        return $query;
    }
@patrickebates

This comment has been minimized.

Copy link
Member

patrickebates commented Jun 24, 2018

I skimmed this last week, but decided I need to get deeper into it. Do you believe that you are getting the correct answers back when replacing with $query?

@tnjturner

This comment has been minimized.

Copy link
Author

tnjturner commented Jul 4, 2018

Yes the results were exactly what I was expecting to be returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment