Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803891
D415.id1031.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:00 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:00 AM (10 h, 44 m)
Engine
blob
Format
Raw Data
Handle
576614
Attached To
D415: INP-1811 - Support partitions in grids and direct INSERT/UPDATE clauses
D415.id1031.diff
View Options
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
Log In to Comment