[wp-trac] [WordPress Trac] #32763: SQL query results depend on the number of blanks in query (due to error from "wpdb->get_table_from_query")
WordPress Trac
noreply at wordpress.org
Tue Jun 23 12:59:06 UTC 2015
#32763: SQL query results depend on the number of blanks in query (due to error
from "wpdb->get_table_from_query")
--------------------------+-----------------------------
Reporter: klaus-b | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 4.2.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
A (non ASCII) query of form
{{{
SELECT <long fieldlist> from
(SELECT <complex subquery>) as sq1
LEFT JOIN
(SELECT <simple subquery>) as sq2
}}}
didnt deliver a result tough some was expected.
Modifying the query to:
{{{
SELECT <1000 spaces> <long fieldlist> from
(SELECT <complex subquery>) as sq1
LEFT JOIN
(SELECT <simple subquery>) as sq2
}}}
Fixed the problem.
I tracked it down to '''wpdb->get_table_from_query'''.
* In first case (for reasons I didn't investigate on)
'''wpdb->get_table_from_query''' returns '''"SELECT"'''
* In second case (for reasons mentioned below)
'''wpdb->get_table_from_query''' returns '''FALSE'''
A reason for the different results is that
'''wpdb->get_table_from_query''' only works on the first 1000 characters
of the '''$query'''. Statement 3 of '''wpdb->get_table_from_query''':
{{{
$query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', substr(
$query, 0, 1000 ) );
}}}
But this (of course) doesn't fix the problem. The correct query result is
delivered in case 2 when '''wpdb->get_table_from_query''' due to enough
blanks gives up (returning '''FALSE''') instead of delivering a wrong
result '''"SELECT"''' as in case 1.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32763>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list