core/SqlSelector.php
public function getSegment()
    {
        $data = [];
        $data['table'] = $this->table;
        $field = '*';
        if ($this->fieldItem !== null) {
            $field = $this->fieldItem->sql;
            if ($this->fieldItem->args !== null) {
                $field = Mysql::format($field, $this->fieldItem->args);
            }
        }
        $data['field'] = $field;
        $data['alias'] = $this->alias;
        $data['where'] = '';
        $frame = $this->condition->getFrame();
        if (!empty($frame['sql'])) {
            if (preg_match('@^(AND|OR)\s+@i', $frame['sql'])) {
                $data['where'] = 'where ' . preg_replace('@^(AND|OR)\s+@i', '', $frame['sql']);
            } else {
                $data['where'] = 'where ' . $frame['sql'];
            }
            if ($frame['args'] !== null && is_array($frame['args'])) {
                $data['where'] = Mysql::format($data['where'], $frame['args']);
            }
        }
        $data['order'] = '';
        if ($this->orderItem != null) {
            $orderSql = $this->orderItem->sql;
            $orderArgs = $this->orderItem->args;
            if (!empty($orderSql)) {
                $data['order'] = 'order ' . $orderSql;
            }
            if ($orderArgs !== null && is_array($orderArgs)) {
                $data['order'] = Mysql::format($data['order'], $orderArgs);
            }
        }
        $data['group'] = '';
        if ($this->groupItem != null) {
            $groupSql = $this->groupItem->sql;
            $groupArgs = $this->groupItem->args;
            if (!empty($groupSql)) {
                $data['group'] = 'group ' . $groupSql;
                if ($groupArgs !== null && is_array($groupArgs)) {
                    $data['group'] = Mysql::format($data['group'], $groupArgs);
                }
            }
        }
        $data['having'] = '';
        if ($this->havingItem != null) {
            $frame = $this->havingItem->getFrame();
            if (!empty($frame['sql'])) {
                if (preg_match('@^(AND|OR)\s+@i', $frame['sql'])) {
                    $data['having'] = 'having ' . preg_replace('@^(AND|OR)\s+@i', '', $frame['sql']);
                } else {
                    $data['having'] = 'having ' . $frame['sql'];
                }
                if ($frame['args'] !== null && is_array($frame['args'])) {
                    $data['having'] = Mysql::format($data['having'], $frame['args']);
                }
            }
        }
        $data['union'] = '';
        if ($this->unionItem) {
            $union = [];
            array_unshift($union, '(');
            $union[] = ')';
            foreach ($this->unionItem as $item) {
                $temp = $item->selector->createSql(0);
                $uItem = '';
                if ($item->all) {
                    $uItem = 'union all ( ' . $temp['sql'] . ' )';
                } else {
                    $uItem = 'union ( ' . $temp['sql'] . ' )';
                }
                if (!empty($temp['args'])) {
                    $uItem = Mysql::format($temp, $frame['args']);
                }
                if (!empty($uItem)) {
                    $union[] = $uItem;
                }
            }
            $data['union'] = join(' ', $union);
        }
        $data['join'] = '';
        if ($this->joinItem !== null) {
            $joinSql = $this->joinItem->sql;
            if ($this->joinItem->args !== null) {
                $joinSql = Mysql::format($joinSql, $this->joinItem->args);
            }
            if (!empty($joinSql)) {
                $data['join'] = $joinSql;
            }
        }

        $data['limit'] = $this->limit;
        $data['param'] = $this->param;
        return $data;
    }
public function getSegment()
    {
        $data = [];
        $data['table'] = $this->table;
        $field = '*';
        if ($this->fieldItem !== null) {
            $field = $this->fieldItem->sql;
            if ($this->fieldItem->args !== null) {
                $field = Mysql::format($field, $this->fieldItem->args);
            }
        }
        $data['field'] = $field;
        $data['alias'] = $this->alias;
        $data['where'] = '';
        $frame = $this->condition->getFrame();
        if (!empty($frame['sql'])) {
            if (preg_match('@^(AND|OR)\s+@i', $frame['sql'])) {
                $data['where'] = 'where ' . preg_replace('@^(AND|OR)\s+@i', '', $frame['sql']);
            } else {
                $data['where'] = 'where ' . $frame['sql'];
            }
            if ($frame['args'] !== null && is_array($frame['args'])) {
                $data['where'] = Mysql::format($data['where'], $frame['args']);
            }
        }
        $data['order'] = '';
        if ($this->orderItem != null) {
            $orderSql = $this->orderItem->sql;
            $orderArgs = $this->orderItem->args;
            if (!empty($orderSql)) {
                $data['order'] = 'order ' . $orderSql;
            }
            if ($orderArgs !== null && is_array($orderArgs)) {
                $data['order'] = Mysql::format($data['order'], $orderArgs);
            }
        }
        $data['group'] = '';
        if ($this->groupItem != null) {
            $groupSql = $this->groupItem->sql;
            $groupArgs = $this->groupItem->args;
            if (!empty($groupSql)) {
                $data['group'] = 'group ' . $groupSql;
                if ($groupArgs !== null && is_array($groupArgs)) {
                    $data['group'] = Mysql::format($data['group'], $groupArgs);
                }
            }
        }
        $data['having'] = '';
        if ($this->havingItem != null) {
            $frame = $this->havingItem->getFrame();
            if (!empty($frame['sql'])) {
                if (preg_match('@^(AND|OR)\s+@i', $frame['sql'])) {
                    $data['having'] = 'having ' . preg_replace('@^(AND|OR)\s+@i', '', $frame['sql']);
                } else {
                    $data['having'] = 'having ' . $frame['sql'];
                }
                if ($frame['args'] !== null && is_array($frame['args'])) {
                    $data['having'] = Mysql::format($data['having'], $frame['args']);
                }
            }
        }
        $data['union'] = '';
        if ($this->unionItem) {
            $union = [];
            array_unshift($union, '(');
            $union[] = ')';
            foreach ($this->unionItem as $item) {
                $temp = $item->selector->createSql(0);
                $uItem = '';
                if ($item->all) {
                    $uItem = 'union all ( ' . $temp['sql'] . ' )';
                } else {
                    $uItem = 'union ( ' . $temp['sql'] . ' )';
                }
                if (!empty($temp['args'])) {
                    $uItem = Mysql::format($temp, $frame['args']);
                }
                if (!empty($uItem)) {
                    $union[] = $uItem;
                }
            }
            $data['union'] = join(' ', $union);
        }
        $data['join'] = '';
        if ($this->joinItem !== null) {
            $joinSql = $this->joinItem->sql;
            if ($this->joinItem->args !== null) {
                $joinSql = Mysql::format($joinSql, $this->joinItem->args);
            }
            if (!empty($joinSql)) {
                $data['join'] = $joinSql;
            }
        }

        $data['limit'] = $this->limit;
        $data['param'] = $this->param;
        return $data;
    }
数据片段
@return array