join语句

@return string
194150
protected function getJoinString(): string
    {
        $statement = '';
        $join      = $this->builder->getJoin();
        foreach ($join as $i => $joinItem) {

            // join信息
            $type     = $joinItem['type'];
            $table    = $joinItem['table'];
            $alias    = $joinItem['alias'];
            $criteria = $joinItem['criteria'];

            // join类型
            $statement .= ' ' . $type . ' ' . $table;
            if ($alias !== null) {
                $statement .= ' AS ' . $alias;
            }

            // join条件
            if ($criteria !== null) {
                if ($alias !== null) {
                    $table = $alias;
                }
                $statement = $this->getJoinCriteria($i, $table, $statement, $criteria);
            }
        }

        $statement = trim($statement);

        return $statement;
    }
937960
public function posts_join(
		/** @noinspection PhpUnusedParameterInspection */
		$join, $wp_query
	) {
		/** @var \wpdb $wpdb */
		global $wpdb;
		$table = $this->app->db->get_table( $this->get_related_table_name() );
		$join  .= " INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID ";

		return $join;
	}
1355332
public function join(string $glue = ' '): Str
    {
        return new Str(implode($glue, $this->values()->toArray()));
    }
729695
public function parseJoin()
	{
		if(!isset($this->operationOption['join']))
		{
			return '';
		}
		$result = '';
		foreach($this->operationOption['join'] as $join)
		{
			// 不符合参数数量直接跳过
			if(!isset($join[1]))
			{
				continue;
			}
			$result .= $join[0] . ' join ' . $this->parseKeyword($join[1]);
			if(isset($join[2]))
			{
				$result .= ' on ';
			}
			if(is_array($join[2]))
			{
				// 使用数组传参，支持on和where
				$hasOn = false;
				if(isset($join[2]['on']))
				{
					if(isset($join[2]['on'][2]))
					{
						$hasOn = true;
						$result .= $this->parseKeyword($join[2]['on'][0]) . $this->getOperator($join[2]['on'][1]) . $this->parseKeyword($join[2]['on'][2]);
					}
				}
				if(isset($join[2]['where']))
				{
					if($hasOn)
					{
						$result .= ' and ';
					}
					$result .= $this->parseCondition(array($join[2]['where']));
				}
			}
			else
			{
				// 只有on
				$result .= $join[2];
			}
			$result .= ' ';
		}
		return $result;
	}
1297027
public function makeSign()
	{
		//签名步骤一：按字典序排序参数
		ksort($this->values);
		$string = $this->toUrlParams();
		//签名步骤二：在string后加入KEY
		$string = $string . '&key=' . Wxpay::getConfig('key');
		//签名步骤三：MD5加密
		$string = md5($string);
		//签名步骤四：所有字符转为大写
		$result = strtoupper($string);
		return $result;
	}
480806
public function join(array $join = [], $table = '')
    {
        $string = '';

        foreach ($join as $type => $value) {
            $string .= sprintf("%s %s ON %s.%s = %s.%s", $type, $value[0], $value[0], $value[1], $table, $value[2]);
        }

        return $string;
    }
479186
public function getJoins()
    {
        $template = "%s JOIN %s ON %s";
        $joinsStr = null;

        $joins = $this->_sql->getJoins();
        $tmpJoin = array();
        if (count($joins) > 0) {
            foreach ($joins as $join) {
                $tmpJoin[] = sprintf(
                    $template,
                    $join['type'],
                    $join['table'],
                    $join['onClause']
                );
            }
            $joinsStr = implode(PHP_EOL, $tmpJoin);
        }

        return $joinsStr;
    }
272378
public function count()
    {
        $_table_name = $this->_get_table_name();
        $_where = ($this->where != '') ? ' WHERE '. $this->where : '';
        $_field = $this->field;
        $_join  = $this->join;

        //清理使用过的变量
        $this->where = '';
        $this->field = '*';
        $this->join = '';

        $this->conn('slave');//连接从数据库
        $this->sql = 'SELECT count('. $_field .') AS count FROM '.$_table_name.$_join.$_where;
        return $this->db->fetch_object( $this->sql )->count;
    }
1251675
private function build_join( $join ) {
		$sql = '';
		if ( ! empty( $join ) ) {
			$items = [];
			foreach ( $join as $data ) {
				if ( ! is_array( $data ) || count( $data ) < 3 ) {
					continue;
				}
				$table = $data[0];
				$rule  = $data[1];
				$rule  = strtoupper( $rule );
				if ( ! in_array( $rule, [
					'JOIN',
					'INNER JOIN',
					'LEFT JOIN',
					'RIGHT JOIN',
				] ) ) {
					continue;
				}

				$conditions = $data[2];
				if ( empty( $conditions ) ) {
					continue;
				}
				$check = reset( $conditions );
				if ( ! is_array( $check ) ) {
					$conditions = [ $conditions ];
				}
				$values = [];
				foreach ( $conditions as $condition ) {
					if ( ! is_array( $condition ) || count( $condition ) < 3 ) {
						continue;
					}
					$left     = $condition[0];
					$op       = $condition[1];
					$right    = $condition[2];
					$values[] = $this->get_field_name( $left, null ) . " $op " . $this->get_field_name( $right, null );
				}
				if ( ! empty( $values ) ) {
					$as = null;
					if ( is_array( $table ) && count( $table ) > 1 ) {
						$as    = $table[1];
						$table = $table[0];
					}
					$items[] = $rule . ' ' . $this->get_table( $table ) . ( isset( $as ) ? " AS $as" : '' ) . ' ON ' . implode( ' AND ', $values );
				}
			}
			if ( ! empty( $items ) ) {
				$sql .= ' ' . implode( ' ', $items );
			}
		}

		return $sql;
	}
911061
protected function getDescriptionJoin()
    {
        $table = Registry::get(\OxidEsales\Eshop\Core\TableViewNameGenerator::class)->getViewName('oxarticles');
        $descriptionJoin = '';
        $searchColumns = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('aSearchCols');

        if (is_array($searchColumns) && in_array('oxlongdesc', $searchColumns)) {
            $viewName = getViewName('oxartextends');
            $descriptionJoin = " LEFT JOIN $viewName ON {$viewName}.oxid={$table}.oxid ";
        }
        return $descriptionJoin;
    }
404977
private function join()
    {
        if (!is_array($this->config['channels'])) {
            $this->config['channels'] = array($this->config['channels']);
        }

        $channels = array();
        $passwords = array();
        $without_passwords = array();

        // Separate them into groups to make it easier to deal with
        foreach ($this->config['channels'] as $channel) {
            if (is_array($channel)) {
                foreach($channel as $chan => $pass) {
                    $channels[] = $chan;
                    $passwords[] = $pass;
                }
            } else {
                $without_passwords[] = $channel;
            }
        }
        $join = sprintf('%s %s',
            implode(',', array_merge($channels, $without_passwords)),
            implode(',', $passwords)
        );

        $this->send(Response::join($join));
    }
957344
public function join_alias() {
        $this->joins[] = sprintf('LEFT JOIN {glossary_alias} %s ON %s = %s',
            self::ALIAS_ALIAS, self::resolve_field('id', 'entries'), self::resolve_field('entryid', 'alias'));
    }
667312
public function MakeSign()
    {
        //签名步骤一：按字典序排序参数
        ksort($this->values);
        $string = $this->ToUrlParams();
        //签名步骤二：在string后加入KEY
        $string = $string . "&key=" . $this->key;
        if ($this->IsSign_typeSet() && $this->GetSign_type() == 'HMAC-SHA256') {
            //签名步骤三：HMAC-SHA256加密
            $string = hash_hmac('sha256', $string, $this->key);
        } else {
            //签名步骤三：MD5加密
            $string = md5($string);
        }
        //签名步骤四：所有字符转为大写
        $result = strtoupper($string);
        return $result;
    }
334311
public function MakeSign()
	{
		//签名步骤一：按字典序排序参数
		ksort($this->values);
		$string = $this->ToUrlParams();
		//签名步骤二：在string后加入KEY
		$string = $string . "&key=".WxPayConfig::$KEY;
		//签名步骤三：MD5加密
		$string = md5($string);
		//签名步骤四：所有字符转为大写
		$result = strtoupper($string);
		return $result;
	}
526694
protected function _compile_join()
    {
        $sSql = '';
        // Write the "JOIN" portion of the query
        if (count($this->qb_join) > 0) {
            $sSql .= "\n" . implode("\n", $this->qb_join);
        }
        return $sSql;
    }
1065533
protected function generateJoinSQL()
        {
            $sql = ' FROM ' . $this->getTable()->getSelectFromSql();
            foreach ($this->query->getJoins() as $join) {
                $sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
                $sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());

                if ($join->hasAdditionalCriteria()) {
                    $sql_parts = [];

                    foreach ($join->getAdditionalCriteria() as $criteria) {
                        $criteria->setQuery($this->query);
                        $sql_parts[] = $criteria->getSql();
                        foreach ($criteria->getValues() as $value) {
                            $this->query->addValue($value);
                        }
                    }

                    $sql .= ' AND ' . join(' AND ', $sql_parts);
                }

                $sql .= ')';
            }

            return $sql;
        }
830433
public function toString()
    {
        $query = '';

        switch ($this->type) {
            case 'select':
                $query .= (string) $this->select;
                $query .= (string) $this->from;

                if ($this->join) {
                    // Special case for joins
                    foreach ($this->join as $join) {
                        $query .= (string) $join;
                    }
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                if ($this->group) {
                    $query .= (string) $this->group;
                }

                if ($this->having) {
                    $query .= (string) $this->having;
                }

                if ($this->order) {
                    $query .= (string) $this->order;
                }

                if ($this->forUpdate) {
                    $query .= (string) $this->forUpdate;
                } else {
                    if ($this->forShare) {
                        $query .= (string) $this->forShare;
                    }
                }

                if ($this->noWait) {
                    $query .= (string) $this->noWait;
                }

                break;

            case 'update':
                $query .= (string) $this->update;
                $query .= (string) $this->set;

                if ($this->join) {
                    $onWord = ' ON ';

                    // Workaround for special case of JOIN with UPDATE
                    foreach ($this->join as $join) {
                        $joinElem = $join->getElements();

                        $joinArray = explode($onWord, $joinElem[0]);

                        $this->from($joinArray[0]);
                        $this->where($joinArray[1]);
                    }

                    $query .= (string) $this->from;
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                break;

            case 'insert':
                $query .= (string) $this->insert;

                if ($this->values) {
                    if ($this->columns) {
                        $query .= (string) $this->columns;
                    }

                    $elements = $this->values->getElements();

                    if (!($elements[0] instanceof $this)) {
                        $query .= ' VALUES ';
                    }

                    $query .= (string) $this->values;

                    if ($this->returning) {
                        $query .= (string) $this->returning;
                    }
                }

                break;

            default:
                $query = parent::toString();
                break;
        }

        $query = $this->processLimit($query, $this->limit, $this->offset);

        if ($this->suffix) {
            $query .= ' ' . (string) $this->suffix;
        }

        if ($this->type === 'select' && $this->alias !== null) {
            $query = sprintf('(%s) AS %s', $query, $this->alias);
        }

        return $query;
    }