使用OUTER APPLY和Codeigniter活动记录

时间:2016-01-18 12:53:21

标签: sql-server codeigniter activerecord outer-apply

是否可以将SQL Server' OUTER APPLY与Codeignter的活动记录一起使用?

2 个答案:

答案 0 :(得分:1)

不可能。使用 Cross Apply 或 Outer Apply 需要在文件 system\database\DB_query_builder.php 中添加一个特定的函数

话虽如此,您可以将此功能(从 join one 修改而来)添加到所述文件中:

public function apply($table, $type = '', $escape = NULL){
    if ($type !== '')
    {
        $type = strtoupper(trim($type));

        if ( ! in_array($type, array('CROSS', 'OUTER'), TRUE))
        {
            $type = 'CROSS';
        }
    }
    else{
        $type = 'CROSS';
    }

    // 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);

    is_bool($escape) OR $escape = $this->_protect_identifiers;

    // Do we want to escape the table name?
    if ($escape === TRUE)
    {
        $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
    }

    // Assemble the APPLY statement
    $this->qb_join[] = $join = $type.' APPLY '.$table;

    if ($this->qb_caching === TRUE)
    {
        $this->qb_cache_join[] = $join;
        $this->qb_cache_exists[] = 'join';
    }

    return $this;
}

然后,你可以像使用它

$this->db->apply('(select * from table_a where table_a.id=table_z.fk_id) as tmp_table');

或者更完整的东西

$this->db->apply('(select * from table_a where table_a.id=table_z.fk_id) as tmp_table','outer',false);

答案 1 :(得分:0)

你可以通过

来完成
$this->db->join('comments', 'comments.id = blogs.id', 'outer');

或者

$this->db->query("SELECT column_name(s)
    FROM table1
    FULL OUTER JOIN table2
    ON table1.column_name=table2.column_name;");

01

Codeigniter Query BuilderOUTER APPLY示例

与Codeigniter的可能联接
(与此$this->db->join('comments', 'comments.id = blogs.id', 'outer');相关联)

  1. left outer
  2. 右外