Page MenuHomeIn-Portal Phabricator

D415.id1031.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 9:00 AM

D415.id1031.diff

Index: core/kernel/db/db_connection.php
===================================================================
--- core/kernel/db/db_connection.php
+++ core/kernel/db/db_connection.php
@@ -808,8 +808,10 @@
array_pop($value_sqls);
}
- $sql = strtoupper($type) . ' INTO `' . $table . '` (' . $fields_sql . ') VALUES (' . implode('),(', $value_sqls) . ')';
- $value_sqls = Array (); // reset before query to prevent repeated call from error handler to insert 2 records instead of 1
+ $sql = strtoupper($type) . ' INTO ' . $table . ' (' . $fields_sql . ') VALUES (' . implode('),(', $value_sqls) . ')';
+
+ // Reset before query to prevent repeated call from error handler to insert 2 records instead of 1.
+ $value_sqls = array();
$insert_result = $this->ChangeQuery($sql);
}
@@ -838,7 +840,7 @@
// don't use preg here, as it may fail when string is too long
$fields_sql = rtrim($fields_sql, ',');
- $sql = 'UPDATE `'.$table.'` SET '.$fields_sql.' WHERE '.$key_clause;
+ $sql = 'UPDATE ' . $table . ' SET ' . $fields_sql . ' WHERE ' . $key_clause;
return $this->ChangeQuery($sql);
}
Index: core/kernel/db/dblist.php
===================================================================
--- core/kernel/db/dblist.php
+++ core/kernel/db/dblist.php
@@ -1658,21 +1658,40 @@
* Discovers LEFT JOINs based on given sql
*
* @return void
- * @access private
+ * @throws RuntimeException When failed to parse a LEFT JOIN expression.
*/
private function parseJoins()
{
- if ( !preg_match_all('/LEFT\s+JOIN\s+(.*?|.*?\s+AS\s+.*?|.*?\s+.*?)\s+ON\s+(.*?\n|.*?$)/si', $this->sql, $regs) ) {
- $this->joins = Array ();
+ $joins_found = preg_match_all(
+ '/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 => $match) {
- $match_parts = preg_split('/\s+AS\s+|\s+/i', $match, 2);
- $table_alias = count($match_parts) == 1 ? $match : $match_parts[1];
+ // 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);
+ }
+
+ $joined_table_name = $match_parts[1];
+ $table_alias = isset($match_parts[5]) && $match_parts[5] !== '' ? $match_parts[5] : $joined_table_name;
- $this->joins[$table_alias] = Array (
- 'table' => $match_parts[0],
+ $this->joins[$table_alias] = array(
+ 'table' => $joined_table_name,
'join_clause' => $regs[0][$index],
);
}

Event Timeline