From 4a9110e120b105c0ad29d028c721c312f405f75a Mon Sep 17 00:00:00 2001 From: Shang Ning Date: Tue, 29 Aug 2017 19:57:50 +0800 Subject: add NATURAL JOIN types to fix #5240 --- system/database/DB_query_builder.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 102ff4ac0..98ba71dbc 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -525,20 +525,29 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function join($table, $cond, $type = '', $escape = NULL) { + $natural_join = FALSE; + if ($type !== '') { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + if (in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { - $type = ''; + $type .= ' '; } - else + elseif (in_array($type, array('NATURAL', 'NATURAL LEFT', 'NATURAL RIGHT', 'NATURAL LEFT OUTER', 'NATURAL RIGHT OUTER'), TRUE)) { $type .= ' '; + $natural_join = TRUE; + } + else + { + $type = ''; } } + + // Extract any aliases that might exist. We use this information // in the protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); @@ -594,7 +603,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } // Assemble the JOIN statement - $this->qb_join[] = $join = $type.'JOIN '.$table.$cond; + if ($natural_join === FALSE) + { + $this->qb_join[] = $join = $type.'JOIN '.$table.$cond; + } + else + { + $this->qb_join[] = $join = $type.'JOIN '.$table; + } if ($this->qb_caching === TRUE) { -- cgit v1.2.3-24-g4f1b