summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-17 17:07:48 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-17 17:07:48 +0200
commit3751f9362b731f5f3d2e63176c364d6281fdf415 (patch)
tree021aaa7860391360bcaf0c9b5bd8296cb55c8fae
parent929fd2d52beb779e46681d35f8ff138aa65cb8df (diff)
Add join() USING support
-rw-r--r--system/database/DB_query_builder.php14
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 12 insertions, 3 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 27f9f363b..4c54b1c0a 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -368,12 +368,20 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$newcond .= $m[0][$i][0];
}
- $cond = $newcond;
+ $cond = ' ON '.$newcond;
}
// Split apart the condition and protect the identifiers
elseif ($escape === TRUE && preg_match('/([\[\w\.-]+)([\W\s]+)(.+)/i', $cond, $match))
{
- $cond = $this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
+ $cond = ' ON '.$this->protect_identifiers($match[1]).$match[2].$this->protect_identifiers($match[3]);
+ }
+ elseif ( ! $this->_has_operator($cond))
+ {
+ $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')';
+ }
+ else
+ {
+ $cond = ' ON '.$cond;
}
// Do we want to escape the table name?
@@ -383,7 +391,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
}
// Assemble the JOIN statement
- $this->qb_join[] = $join = $type.'JOIN '.$table.' ON '.$cond;
+ $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 4054a04ff..b39d43b1a 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -79,6 +79,7 @@ Release Date: Not Released
- Added new methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Added an optional parameter that allows to disable escaping (useful for custom fields) for methods join(), order_by(), where_in(), or_where_in(), where_not_in(), or_where_not_in().
- Added support for join() with multiple conditions.
+ - Added support for USING in join().
- Improved support for the MySQLi driver, including:
- OOP style of the PHP extension is now used, instead of the procedural aliases.
- Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query.