diff options
Diffstat (limited to 'system/database')
-rw-r--r-- | system/database/DB_query_builder.php | 24 |
1 files changed, 20 insertions, 4 deletions
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) { |