summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_query_builder.php37
1 files changed, 8 insertions, 29 deletions
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)
{