summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorShang Ning <jvyyuie@gmail.com>2017-08-29 13:57:50 +0200
committerShang Ning <jvyyuie@gmail.com>2017-08-29 13:57:50 +0200
commit4a9110e120b105c0ad29d028c721c312f405f75a (patch)
tree2293d3d4d02c48cca1388bdaa3ffeb048531a681 /system/database
parentcbe27d76f0aaba7b40f4b23904e4258964bdc50c (diff)
add NATURAL JOIN types to fix #5240
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_query_builder.php24
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)
{