diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-06-17 17:07:48 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-06-17 17:07:48 +0200 |
commit | 3751f9362b731f5f3d2e63176c364d6281fdf415 (patch) | |
tree | 021aaa7860391360bcaf0c9b5bd8296cb55c8fae /system/database | |
parent | 929fd2d52beb779e46681d35f8ff138aa65cb8df (diff) |
Add join() USING support
Diffstat (limited to 'system/database')
-rw-r--r-- | system/database/DB_query_builder.php | 14 |
1 files changed, 11 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) { |