Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F871689
D415.id1159.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
Thu, May 8, 12:54 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Fri, May 9, 12:54 AM (9 h, 3 m)
Engine
blob
Format
Raw Data
Handle
617428
Attached To
D415: INP-1811 - Support partitions in grids and direct INSERT/UPDATE clauses
D415.id1159.diff
View Options
Index: branches/5.2.x/core/kernel/db/db_connection.php
===================================================================
--- branches/5.2.x/core/kernel/db/db_connection.php
+++ branches/5.2.x/core/kernel/db/db_connection.php
@@ -807,8 +807,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);
}
@@ -837,7 +839,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: branches/5.2.x/core/kernel/db/dblist.php
===================================================================
--- branches/5.2.x/core/kernel/db/dblist.php
+++ branches/5.2.x/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