#32763 closed defect (bug) (fixed)
SQL query results depend on the number of blanks in query (due to error from "wpdb->get_table_from_query")
Reported by: | klaus-b | Owned by: | pento |
---|---|---|---|
Milestone: | 4.2.3 | Priority: | normal |
Severity: | normal | Version: | 4.2 |
Component: | Database | Keywords: | fixed-major |
Focuses: | Cc: |
Description
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.
Change History (5)
Note: See
TracTickets for help on using
tickets.
A query that fails, for example purposes: