Implodes parts of SQL query to a single string.

@param string[] $parts
@return string
174282
protected function implodeSQL(array $parts): string
    {
        $result = '';
        foreach ($parts as $part) {
            if ($part === '') {
                continue;
            }

            $result .= ($result === '' ? '' : "\n").$part;
        }

        return $result;
    }
466010
protected static function tokenize( array $parts ) {
		$tokens = [];
		$index  = 0;

		foreach ( $parts as $part ) {
			if ( \preg_match( self::_RE_SPACE, $part ) ) {
				$tokens[ $index ] = new Token( $part, Token::SPACE );
			} elseif ( \preg_match( self::_RE_PUNCTUATION, $part ) ) {
				$tokens[ $index ] = new Token( $part, Token::PUNCTUATION );
			} elseif ( \preg_match( self::_RE_WORD, $part ) ) {
				// Make sure that things like email addresses and URLs are not broken up
				// into words and punctuation not preceeded by an 'other'.
				self::parse_ambiguous_token( Token::WORD, $part, $tokens, $index );
			} else {
				// Make sure that things like email addresses and URLs are not broken up into words
				// and punctuation not preceeded by an 'other' or 'word'.
				self::parse_ambiguous_token( Token::OTHER, $part, $tokens, $index );
			}

			$index++;
		}

		return $tokens;
	}
1227834
private function encodePart($part)
    {
        if (strpos($part, '?') !== false) {
            if (strpos($part, '?') === 0) {
                $output = '?';
                $part = substr($part, 1);
            } else {
                $pe = explode('?', $part);
                $output = $pe[0].'/?';
                $part = $pe[1];
                unset($pe);
            }

            if (strpos($part, '&')) {
                $parts = explode('&', $part);
            } else {
                $parts = [$part];
            }
            foreach ($parts as &$p) {
                if (strpos($p, '=') !== false) {
                    $pe = explode('=', $p);
                    $p = $pe[0].'='.urlencode($pe[1]);
                }
            }
            unset($p, $pe);

            $output .= implode('&', $parts);

            return $output;
        }

        if (strpos($part, '#') !== false) {
            if (strpos($part, '#') === 0) {
                if (substr($part, 1, 1) === '!') {
                    return '#!'.rawurlencode(substr($part, 2));
                }

                return '#'.rawurlencode(substr($part, 1));
            }

            $pe = explode('#', $part);
            if (substr($pe[1], 0, 1) === '!') {
                return $pe[0].'/#!'.rawurlencode(substr($pe[1], 1));
            }

            return $pe[0].'/#'.rawurlencode($pe[1]);
        }

        return rawurlencode($part);
    }
352342
protected function generateSelectAllSQL()
        {
            $sql_parts = [];
            foreach ($this->query->getSelectionColumns() as $selection) {
                $sql_parts[] = $selection->getSql();
            }
            return implode(', ', $sql_parts);
        }
83473
private function prepareQuery($params = []) {
		if(!is_array($params)) {
			return $params;
		}

		$query = [];

		foreach($params as $key => $value) {
			if(is_array($value)) {
				foreach($value as $element) {
					$query[] = sprintf(
						'%s[]=%s',
						$key,
						urlencode($element)
					);
				}
			} else {
				$query[] = sprintf(
					'%s=%s',
					$key,
					urlencode($value)
				);
			}
		}

		return implode("&",$query);
	}
301670
public function toString()
    {
        $parts = [];

        if ($this->operand) {
            $parts[] = (string)$this->operand;
        }

        if ($this->constraint) {
            $parts[] = (string)$this->constraint;
        }

        return implode(' ', $parts);
    }
461066
public function joinRows($rows, $separator = ', ')
    {
        $ret = array();
        foreach ($rows as $r) {
            $ret[] = $r.'';
        }

        return implode($separator, $ret);
    }
738935
protected function parametersToString(array $parameters)
    {
        $pieces = array();
        foreach ($parameters as $key => $val) {
            $pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val)));
        }

        return implode(', ', $pieces);
    }
666133
protected function concatenateQuery(array $pieces): string
    {
        $str = '';
        foreach ($pieces as $piece) {
            $str = trim($str) . ' ' . trim($piece);
        }

        return trim($str);
    }
578626
public static function generateQueryString(array $parts)
    {
        $return = "";

        foreach ($parts as $part) {
            if ($part instanceof Table) {
                $return .= "`{$part->getTableName()}`";
                if ($part->getTableAs() !== null) {
                    $return .= " " . $part->getTableAs();
                }

                $return .= ",";
            }
        }

        return ($return !== "" ? substr($return, 0, -1) : "*");
    }
390127
protected function getColumnsSQLDeclaration(array $columns)
    {
        $columnsDeclaration = array();

        foreach ($columns as $column) {
            $columnsDeclaration[] = $this->getColumnSQLDeclaration($column);
        }

        return implode(', ', $columnsDeclaration);
    }
1368195
public function extract($parts = null) {
        if ($parts === null) {
            return $this->data;
        }

        if (is_array($parts)) {
            $result = array();

            foreach ($this->data as $match) {
                $row = array();
                foreach ($parts as $key) {
                    if (isset($match[$key])) {
                        $row[$key] = isset($match[$key])?$match[$key]:null;
                    }
                }

                $result[] = $row;
            }

            return $result;
        }

        $result = array();
        foreach ($this->data as $match) {
            $result[] = isset($match[$parts])?$match[$parts]:null;
        }

        return $result;
    }
756165
private static String concat(final String... parts) {

		final StringBuilder buf = new StringBuilder();

		for (final String part : parts) {

			// handle nulls gracefully (ignore)
			if (part != null) {

				buf.append(part);
			}
		}

		return buf.toString();
	}
851359
protected function getFields(array $queryParts)
    {
        if (isset($queryParts['fields'])) {
            if (is_array($queryParts['fields']) && !empty($queryParts['fields'])) {
                $quoted = array();

                foreach ($queryParts['fields'] as $field) {
                    $quoted[] = $this->quoteIdentifier($field);
                }

                return implode(', ', $quoted);
            } else {
                return (string)$queryParts['fields'];
            }
        }

        return null;
    }
764930
protected function implodeClauses(array $clauses)
    {
        $str = '';
        $op = false;
        foreach ($clauses as $clause) {
            // an 'OR' token will change the operator used
            // when concatenating the next clause
            if ($clause == 'OR') {
                $op = ' OR ';
                continue;
            }

            if ($op && $str) {
                $str .= $op;
            }

            $str .= $clause;
            $op = ' AND ';
        }

        return $str;
    }
924397
protected function joins(array $joins): string
	{
		if(empty($joins))
		{
			return '';
		}

		$sql = [];

		foreach($joins as $join)
		{
			$sql[] = $join->getType() . ' JOIN ' . $this->table($join->getTable()) . ' ON ' . $this->joinConditions($join);
		}

		return ' ' . implode(' ', $sql);
	}
470585
protected static function r_implode($element)
    {
        $string = '';

        if (is_array($element)) {
            reset($element);
            foreach ($element as $value) {
                $string .= ' ' . self::r_implode($value);
            }
        }
        else {
            return $element;
        }

        return '(' . trim($string) . ')';
    }