From 66b6717e6b3ec2cd9ced7040cd330d7add19dcb6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 29 Aug 2017 16:01:18 +0300 Subject: Polish changes from & add changelog entry for PR #5242 Also, further simplified the join() logic --- system/database/DB_query_builder.php | 37 ++++++++---------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 9564e8870..d35d84d6d 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -525,26 +525,8 @@ 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)) - { - $type .= ' '; - } - elseif (in_array($type, array('NATURAL', 'NATURAL LEFT', 'NATURAL RIGHT', 'NATURAL LEFT OUTER', 'NATURAL RIGHT OUTER'), TRUE)) - { - $type .= ' '; - $natural_join = TRUE; - } - else - { - $type = ''; - } - } + $type = strtoupper(trim($type)); + preg_match('#^(NATURAL(?=\s|$)\s*)?((LEFT|RIGHT)(?=\s|$))?\s*(INNER|OUTER)?$#', $type) OR $type = ''; // Extract any aliases that might exist. We use this information // in the protect_identifiers to know whether to add a table prefix @@ -552,7 +534,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { is_bool($escape) OR $escape = $this->_protect_identifiers; - if ( ! $this->_has_operator($cond)) + if (strpos($type, 'NATURAL') === 0) + { + $cond = ''; + } + elseif ( ! $this->_has_operator($cond)) { $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')'; } @@ -601,14 +587,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } // Assemble the JOIN statement - if ($natural_join === FALSE) - { - $this->qb_join[] = $join = $type.'JOIN '.$table.$cond; - } - else - { - $this->qb_join[] = $join = $type.'JOIN '.$table; - } + $this->qb_join[] = $join = $type.' JOIN '.$table.$cond; if ($this->qb_caching === TRUE) { -- cgit v1.2.3-24-g4f1b