Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/dblist.php
Show First 20 Lines • Show All 1652 Lines • ▼ Show 20 Line(s) | |||||
return $this->sql; | return $this->sql; | ||||
} | } | ||||
/** | /** | ||||
* Discovers LEFT JOINs based on given sql | * Discovers LEFT JOINs based on given sql | ||||
* | * | ||||
* @return void | * @return void | ||||
* @access private | * @throws RuntimeException When failed to parse a LEFT JOIN expression. | ||||
*/ | */ | ||||
private function parseJoins() | private function parseJoins() | ||||
{ | { | ||||
if ( !preg_match_all('/LEFT\s+JOIN\s+(.*?|.*?\s+AS\s+.*?|.*?\s+.*?)\s+ON\s+(.*?\n|.*?$)/si', $this->sql, $regs) ) { | $joins_found = preg_match_all( | ||||
$this->joins = Array (); | '/LEFT\s+JOIN\s+(.*?|.*?\s+AS\s+.*?|.*?\s+.*?)\s+ON\s+(.*?\n|.*?$)/si', | ||||
$this->sql, | |||||
$regs | |||||
); | |||||
if ( !$joins_found ) { | |||||
$this->joins = array(); | |||||
return; | |||||
} | |||||
// Get all LEFT JOIN clause info from sql (without filters). | |||||
foreach ( $regs[1] as $index => $join_expression ) { | |||||
// Format (without quotes): "tbl_name [PARTITION (partition_names)] [[AS] alias] [index_hint_list]". | |||||
$join_expression_parsed = preg_match( | |||||
'/([\S]+)(\s*PARTITION\s*\([^)]+\))?(\s*(AS\s*)?([\S]+))?((USE|IGNORE|FORCE)\s+.*)?/', | |||||
$join_expression, | |||||
$match_parts | |||||
); | |||||
if ( !$join_expression_parsed ) { | |||||
throw new RuntimeException('Unable to parse join expression: ' . $join_expression); | |||||
} | } | ||||
// get all LEFT JOIN clause info from sql (without filters) | $joined_table_name = $match_parts[1]; | ||||
foreach ($regs[1] as $index => $match) { | $table_alias = isset($match_parts[5]) && $match_parts[5] !== '' ? $match_parts[5] : $joined_table_name; | ||||
$match_parts = preg_split('/\s+AS\s+|\s+/i', $match, 2); | |||||
$table_alias = count($match_parts) == 1 ? $match : $match_parts[1]; | |||||
$this->joins[$table_alias] = Array ( | $this->joins[$table_alias] = array( | ||||
'table' => $match_parts[0], | 'table' => $joined_table_name, | ||||
'join_clause' => $regs[0][$index], | 'join_clause' => $regs[0][$index], | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Detects relations between LEFT JOINs | * Detects relations between LEFT JOINs | ||||
* | * | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |