summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-08-29 15:01:18 +0200
committerAndrey Andreev <narf@devilix.net>2017-08-29 15:01:18 +0200
commit66b6717e6b3ec2cd9ced7040cd330d7add19dcb6 (patch)
tree762c75f40c11b3114c39902db1270e08f6ffce11
parent941b614f6f5dfb7201954a6719615475b8aee194 (diff)
Polish changes from & add changelog entry for PR #5242
Also, further simplified the join() logic
-rw-r--r--system/database/DB_query_builder.php37
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 9 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)
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 6b75d6296..4b0a6e56a 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -78,6 +78,7 @@ Release Date: Not Released
- :doc:`Query Builder <database/query_builder>`:
- Added methods ``having_in()``, ``or_having_in()``, ``not_having_in()``, ``or_not_having_in()``.
+ - Updated method ``join()`` to allow accepting ``NATURAL`` clauses in its third parameter.
- Updated logic to allow dots in alias names.
- Helpers