Exemplo n.º 1
0
 /**
  * 构造 FROM 子句
  *
  * @return string
  */
 protected function _renderFrom()
 {
     $from = array();
     foreach ($this->_parts[self::FROM] as $alias => $table) {
         $tmp = '';
         // $this->_parts[self::FROM][$alias] = array(
         //     'join_type'      => $join_type,
         //     'table_name'     => $table_name,
         //     'schema'         => $shema,
         //     'join_cond'      => $where_sql, // 字符串
         // );
         // 如果不是第一个 FROM,则添加 JOIN
         if (!empty($from)) {
             $tmp .= ' ' . strtoupper($table['join_type']) . ' ';
         }
         if ($alias == $table['table_name']) {
             $tmp .= $this->_conn->qid("{$table['schema']}.{$table['table_name']}");
         } else {
             $tmp .= $this->_conn->qid("{$table['schema']}.{$table['table_name']}", $alias);
         }
         // 添加 JOIN 查询条件
         if (!empty($from) && !empty($table['join_cond'])) {
             $tmp .= "\n  " . self::SQL_ON . ' ' . $table['join_cond'];
         }
         $from[] = $tmp;
     }
     if (!empty($from)) {
         return "\n " . self::SQL_FROM . ' ' . implode("\n", $from);
     } else {
         return '';
     }
 }