Extracts triple pattern out of a given string.

@param string $where WHERE part of the query

@return array
168354
public function extractTriplePattern($where)
    {
        // remove possible PREFIX parts at the beginning
        $removeRegex = '/PREFIX\s+([a-z0-9]+)\:\s*\<([a-z0-9\:\/\.\#\-]+)\>/si';
        $where = preg_replace($removeRegex, '', $where);

        // remove FILTER clauses and their pattern to avoid false positives in the next regex-check
        $removeRegex = '/FILTER\s*regex\(.*?\)'
            .'|FILTER\s*\([a-z0-9]+\([a-z?]+\)'
            .'|"([a-z]{2,}:[^\s]*)"'
            .'|FILTER\s*\(\?[a-z\s=>0-9"]+\)'
            .'/si';
        $where = preg_replace($removeRegex, '', $where);

        /**
         * Because quads also consists of triple pattern, we first check if there are quads. In case there
         * are, return empty.
         */
        $quads = $this->extractQuads($where);

        if (0 < count($quads)) {
            return [];
        }

        /**
         * Here we know, no quads are there.
         */
        $regex = '/'.
            $this->rdfHelpers->getRegexStringForNodeRecognition(
                true, true, false, false, false, false, true
            ).'\s*|\t*'.
            $this->rdfHelpers->getRegexStringForNodeRecognition(
                true, true, false, false, false, false, true
            ).'\s*|\t*'.
            $this->rdfHelpers->getRegexStringForNodeRecognition(
                true, true, true, true, true, true, true
            ).'/is';

        preg_match_all($regex, $where, $matches);

        $lineIndex = -1;
        $pattern = [];
        $s = $p = $o = '';

        foreach ($matches[0] as $match) {
            ++$lineIndex;

            /*
             * Handle type and value of subject and predicate
             */
            if (0 == $lineIndex) {
                $s = $match;
                continue;
            } elseif (1 == $lineIndex) {
                $p = $match;
                continue;
            } elseif (2 == $lineIndex) {
                $o = $match;
                $lineIndex = -1;
            } else {
                throw new \Exception('This should never happen: '.$lineIndex);
            }

            $oIsUri = false;
            if ('<' == substr($o, 0, 1)) {
                $o = str_replace(['>', '<'], '', $o);
                $oIsUri = true;
            }

            /**
             * Determine types of subject, predicate and object.
             */
            $sType = $this->determineEntityType($s);
            $pType = $this->determineEntityType($p);
            $oType = $this->determineEntityType($o);

            /**
             * Check for prefixes and replace them with original URI.
             */
            $prefixes = $this->extractPrefixesFromQuery($this->getQuery());

            $s = $this->replacePrefixWithUri($s, $prefixes);
            $p = $this->replacePrefixWithUri($p, $prefixes);
            $o = $this->replacePrefixWithUri($o, $prefixes);

            /*
             * If S or P are starting with a ?, remove it
             */
            if ('?' == substr($s, 0, 1)) {
                $s = substr(trim($s), 1);
            }

            if ('?' == substr($p, 0, 1)) {
                $p = substr(trim($p), 1);
            }

            /**
             * Determine all aspects of the object.
             */
            $oDatatype = $this->determineObjectDatatype($o);
            $oLang = $this->determineObjectLanguage($o);
            $oValue = $this->determineObjectValue($o);

            if ($oIsUri === true) {
                $oValue = $o;
            }

            // set pattern array
            $pattern[] = [
                's' => str_replace(['<', '>'], '', $s),
                'p' => str_replace(['<', '>'], '', $p),
                'o' => $oValue,
                's_type' => $sType,
                'p_type' => $pType,
                'o_type' => $oType,
                'o_datatype' => $oDatatype,
                'o_lang' => $oLang,
            ];
        }

        return $pattern;
    }
1206169
private static function parseWhere(IQuery $query, $where)
    {
        if(null === $where)
        {
            return $query;
        }
        if(is_callable($where))
        {
            // 回调传入条件
            call_user_func($where, $query);
        }
        else
        {
            foreach($where as $k => $v)
            {
                if(is_array($v))
                {
                    $operation = array_shift($v);
                    $query->where($k, $operation, $v[0]);
                }
                else
                {
                    $query->where($k, '=', $v);
                }
            }
        }
        return $query;
    }
1189127
protected static function parseWhere($where)
    {
        if (is_array($where) && key($where) !== 0) {
            $item = [];
            foreach ($where as $key => $val) {
                $item[] = [$key, '=', $val];
            }
            return $item;
        }
        return $where;
    }
931497
public function where(Expr $where)
    {
        if ($where instanceof Parameter && $where == Expr::true()) {
            return $this;
        }

        if ($where instanceof BinOp && $where->getOperator() === BinOp::AND_) {
            $this->where($where->getLeft());
            $this->where($where->getRight());
        } else {
            $this->where[] = $where;
        }

        return $this;
    }
237543
protected function _jig_parse_filter($where, $args) {
		$parts = $this->splitLogical($where);
		if (is_int(strpos($where, ':')))
			list($parts, $args) = $this->convertNamedParams($parts, $args);
		$ncond = array();
		foreach ($parts as &$part) {
			if (preg_match('/\s*\b(AND|OR)\b\s*/i',$part))
				continue;
			// prefix field names
			$part = preg_replace('/([a-z_-]+(?:[\w-]+))/i', '@$1', $part, -1, $count);
			// value comparison
			if (is_int(strpos($part, '?'))) {
				$val = array_shift($args);
				preg_match('/(@\w+)/i', $part, $match);
				$skipVal=false;
				// find like operator
				if (is_int(strpos($upart = strtoupper($part), ' @LIKE '))) {
					if ($not = is_int($npos = strpos($upart, '@NOT')))
						$pos = $npos;
					$val = '/'.$this->_likeValueToRegEx($val).'/iu';
					$part = ($not ? '!' : '').'preg_match(?,'.$match[0].')';
				} // find IN operator
				elseif (is_int($pos = strpos($upart, ' @IN '))) {
					if ($val instanceof CortexCollection)
						$val = $val->getAll('_id',TRUE);
					if ($not = is_int($npos = strpos($upart, '@NOT')))
						$pos = $npos;
					$part = ($not ? '!' : '').'in_array('.substr($part, 0, $pos).
						',array(\''.implode('\',\'', $val).'\'))';
					$skipVal=true;
				}
				elseif($val===null && preg_match('/(\w+)\s*([!=<>]+)\s*\?/i',$part,$nmatch)
					&& ($nmatch[2]=='=' || $nmatch[2]=='==')){
					$kval=ltrim($nmatch[1],'@');
					$part = '(!array_key_exists(\''.$kval.'\',$_row) || '.
						'(array_key_exists(\''.$kval.'\',$_row) && $_row[\''.$kval.'\']===NULL))';
					unset($part);
					continue;
				}
				// add existence check
				$part = ($val===null && !$skipVal)
					? '(array_key_exists(\''.ltrim($match[0],'@').'\',$_row) && '.$part.')'
					: '(isset('.$match[0].') && '.$part.')';
				if (!$skipVal)
					$ncond[] = $val;
			} elseif ($count >= 1) {
				// field comparison
				preg_match_all('/(@\w+)/i', $part, $matches);
				$chks = array();
				foreach ($matches[0] as $field)
					$chks[] = 'isset('.$field.')';
				$part = '('.implode(' && ',$chks).' && ('.$part.'))';
			}
			unset($part);
		}
		array_unshift($ncond, implode(' ', $parts));
		return $ncond;
	}
587207
private function transmute(Where $where)
    {
        $this->stack    = $where->stack;
        $this->element  = $where->element;
        $this->operator = $where->operator;
        $this->values   = $where->values;
    }
1149980
public function findWhereNotIn(array $where, $attributes = ['*'])
    {
        return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) {
            list($attribute, $values, $boolean) = array_pad($where, 3, null);

            $this->whereNotIn($attribute, $values, $boolean);

            return $this->prepareQuery($this->createModel())->get($attributes);
        });
    }
80577
protected function getTableFieldInformationWhere(Where $where)
    {
        $sql = <<<SQL
select
    att.attname      as "name",
    case
        when name.nspname = 'pg_catalog' then typ.typname
        else format('%s.%s', name.nspname, typ.typname)
    end as "type",
    def.adsrc        as "default",
    att.attnotnull   as "is_notnull",
    dsc.description  as "comment",
    att.attnum       as "position",
    att.attnum = any(ind.indkey) as "is_primary"
from
  pg_catalog.pg_attribute att
    join pg_catalog.pg_type  typ  on att.atttypid = typ.oid
    join pg_catalog.pg_class cla  on att.attrelid = cla.oid
    join pg_catalog.pg_namespace clns on cla.relnamespace = clns.oid
    left join pg_catalog.pg_description dsc on cla.oid = dsc.objoid and att.attnum = dsc.objsubid
    left join pg_catalog.pg_attrdef def     on att.attrelid = def.adrelid and att.attnum = def.adnum
    left join pg_catalog.pg_index ind       on cla.oid = ind.indrelid and ind.indisprimary
    left join pg_catalog.pg_namespace name  on typ.typnamespace = name.oid
where
{condition}
order by
    att.attnum
SQL;

        $where = $where
            ->andWhere('att.attnum > 0')
            ->andWhere('not att.attisdropped')
            ;

        return $this->executeSql($sql, $where);
    }
1017198
private function getSelect(array $where): string
    {
        // Current table
        $table = $this->getCollection();

        // Generate where line
        $whereDetails = !empty($where)
            ? ' WHERE ' . $this->genWhere($where)
            : '';

        return "SELECT * FROM $table $whereDetails";
    }
240873
protected function formatWhere(array $where) : string {
    $where_clause = '';

    foreach ($where as $column => $value) {
      $logical_operator = null;

      if (is_numeric($column) && is_array($value)) {
        $where_clause .= "`{$value[0]}` {$value[1]} :where_{$value[0]}";
      } else if (is_numeric($column) && is_string($value)) {
        $logical_operator = $value;
      } else {
        $where_clause .= "`{$column}` = :where_{$column}";
      }

      $next_value = next($where);
      $next_key = key($where);

      if ( $next_value !== false && !is_null($next_key) && (!is_numeric($next_key) || !is_string($next_value)) )  {
        $logical_operator = $logical_operator ?? '&&';

        $where_clause .= " {$logical_operator} ";
      }
    }

    return $where_clause;
  }
1207646
protected function where($where)
    {
        foreach($where as $field => $value) {
            $this->queryBuilder->where($field, $value);
        }
    }
1367694
private static function _extractWhereConditions($conditions) 
    {
        if (!$conditions) {
            return "";
        }

        $cls    = get_called_class();
        $escape = Driver::$escape_char;

        if (is_array($conditions)) {
            // check if is a regular array or an associative one
            if (array_values($conditions) !== $conditions) {
                $conditions = self::_extractWhereAssociativeConditions($conditions, $cls, $escape);
            } else {
                $conditions = self::_extractWhereRegularConditions($conditions, $cls, $escape);
            }
        }
        return $conditions;
    }
653985
public static function endsWith(?string $what, ?string $where): bool
    {
        // check is not empty string
        if (self::likeEmpty($what) || self::likeEmpty($where)) {
            return false;
        }

        $suffix = self::sub($where, -self::length($what));
        return $suffix === $what;
    }
84588
public function delete($where = null)
    {
        if ($this->map) {
            $where = $this->map->where($where);
        }
        if ($this->fake) {
            return $this->fake->delete($where);
        }
        $pattern = 'DELETE FROM ?t WHERE ?w';
        $data = array($this->name, $where);
        return $this->db->query($pattern, $data)->ar();
    }
292258
private function createWhereExpression(array $where = [])
    {
        $criteria = [];
        foreach ($where as $index => $value) {
            if (is_int($index)) {
                $criteria[] = $value;
            } else {
                $criteria[] = $this->quote()->into($index, $value);
            }
        }
        return implode(' AND ', $criteria);
    }
47918
public static function contains(string $what, string $where): bool
    {
        return mb_strpos($where, $what, 0, 'UTF-8') !== false;
    }
1150543
static function find_all_tags_string($object, $where = array())
	{
		$data = array(
			'target_class_id IN' => array($object->extends_class_id(), $object->class_id()),
			'target_object_id' => $object->id(),
		);

		$bindings = bors_find_all('common_keyword_bind', array_merge($data, $where));
		$tag_ids = bors_field_array_extract($bindings, 'keyword_id');
		$tags = bors_find_all(__CLASS__, array('id IN' => $tag_ids));
		return join(', ', bors_field_array_extract($tags, 'title'));
	}