Some simple checks for a where clause

@param $where
@return string
488467
protected function formatWhereClause($where)
    {
        if (!empty($where)) {
            if (stripos($where, 'where') === false || stripos($where, 'select') !== false) {
                $where = ' where ' . $where;
            }
        }

        return $where;
    }
781685
public function extractFilterPattern($where)
    {
        /*
         * Remaining filter clauses to cover:
         *  - FILTER (?decimal * 10 > ?minPercent )
         *  - FILTER (isURI(?person) && !bound(?person))
         */

        $pattern = [];

        preg_match_all(
            '/FILTER(\s*|\s*[a-zA-Z0-9]*)\((.*)\)/',
            $where,
            $matches
        );

        foreach ($matches[2] as $match) {
            // TODO optimize REGEX to ignore " at the end to save the lastChar check later on.

            /*
             * Covers filters such as:
             * - FILTER (?o < 40)
             * - FILTER (?s = "foo")
             */
            preg_match_all(
                '/'.
                '\?([a-zA-Z0-9\_]+)'. // e.g. ?s
                '\s*'.               // space
                '(=|<|>|!=)'.        // operator, e.g. =
                '\s*'.               // space
                '"*(.*)"*'.          // constrain, e.g. 40 or "Bar"
                '/si',
                $match,
                $parts
            );

            if (true == isset($parts[3][0])) {
                // if last char is " or ', cut it out
                $lastChar = substr($parts[3][0], strlen($parts[3][0]) - 1);
                if ('"' == $lastChar || "'" == $lastChar) {
                    $parts[3][0] = substr($parts[3][0], 0, strlen($parts[3][0]) - 1);
                }

                $entry = [
                    'type' => 'expression',
                    'sub_type' => 'relational',
                    'patterns' => [
                        [
                            'value' => $parts[1][0], // e.g. ?s
                            'type' => 'var', // its always a variable
                            'operator' => '',
                        ],
                        [
                            'value' => $parts[3][0], // e.g. "Bar"
                            'type' => 'literal',
                            'operator' => '',
                        ],
                    ],
                    'operator' => $parts[2][0], // operator, e.g. <
                ];

                // set datatype and sub_type
                if (true === ctype_digit($parts[3][0])) {
                    $entry['patterns'][1]['datatype'] =
                        'http://www.w3.org/2001/XMLSchema#integer';
                } else {
                    $entry['patterns'][1]['sub_type'] = 'literal2';
                }

                $pattern[] = $entry;

                // go to the next match
                continue;
            }

            /*
             * Covers regex filters such as:
             * - FILTER regex(?g, "aar")
             * - FILTER regex(?g, "aar", "i")
             */
            preg_match_all(
                '/FILTER\s+regex\s*\(\?([a-zA-Z0-9]*),\s*"([^"]*)"(,\s*"(.*)")*\)/si',
                $where,
                $parts
            );

            if (true == isset($parts[1][0])) {
                $entry = [
                    'args' => [
                        [
                            'value' => $parts[1][0],
                            'type' => 'var',
                            'operator' => '',
                        ],
                        [
                            'value' => $parts[2][0],
                            'type' => 'literal',
                            'sub_type' => 'literal2',
                            'operator' => '',
                        ],
                    ],
                    'type' => 'built_in_call',
                    'call' => 'regex',
                ];

                // if optional part is set, which means the regex function got 3 parameter
                if (0 < strlen($parts[4][0])) {
                    $entry['args'][] = [
                        'value' => $parts[4][0],  // optional part, i
                        'type' => 'literal',
                        'sub_type' => 'literal2',
                        'operator' => '',
                    ];
                }

                $pattern[] = $entry;

                continue;
            }

            /*
             * Covers regex filters such as:
             * - FILTER (lang(?title) = 'en')
             */
            preg_match_all(
                '/lang\(\?([a-z0-9]+)\)\s*\=\s*[\'|\"]([a-z\_]+)[\'|\"]/si',
                $match,
                $parts
            );

            if (true == isset($parts[1][0])) {
                $entry = [
                    'args' => [
                        [
                            'value' => $parts[1][0],
                            'type' => 'var',
                            'operator' => '',
                        ],
                        [
                            'value' => $parts[2][0],
                            'type' => 'literal',
                            'sub_type' => 'literal2',
                            'operator' => '',
                        ],
                    ],
                    'type' => 'built_in_call',
                    'call' => 'lang',
                ];

                $pattern[] = $entry;

                continue;
            }
        }

        return $pattern;
    }
757969
public function where($where, $controll = null)
    {

        if (!is_array($where) && !is_null($controll)) {

            $where = [
                [$where, '=', $controll]
            ];
        } elseif (is_array($where) && isset($where[0]) && isset($where[1])) {

            if (is_string($where[1])) {

                $where = [
                    [$where[0], $where[1], $where[2]]
                ];
            }
        }

        $this->doWhere($where, 'and');

        return $this;
    }
554005
def _where_clause(where):
        
        assert isinstance(where, tuple)
        if len(where) == 3:
            where_col, operator, where_val = where
        else:
            where_col, where_val = where
            operator = '='
        assert operator in SELECT_WHERE_OPERATORS

        # Concatenate WHERE clause (ex: **first_name='John'**)
        return "{0}{1}'{2}'".format(where_col, operator, where_val)
1260381
public function findWhereIn(array $where, $attributes = ['*'])
    {
        return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) {
            list($attribute, $values, $boolean, $not) = array_pad($where, 4, null);

            $this->whereIn($attribute, $values, $boolean, $not);

            return $this->prepareQuery($this->createModel())->get($attributes);
        });
    }
973153
public function where($where)
    {
        if (is_string($where)) {
            $where = [$where];
        }
        
        $this->where = array_merge($this->where, $where);
        
        return $this;
    }
1324570
protected function formatWhereToNamePlaceHolder($where)
    {
        $whereStr = '';
        $whereNew = [];
        foreach ($where as $key => $value) {
            $key = trim(str_replace(['AND', '?', '='], ['', '', ''], $key));
            $whereNew[$key] = $value;
            $whereStr .= "$key = :$key,";
        }

        return [$whereNew, rtrim($whereStr, ',')];
    }
351078
protected function prepare($where)
    {
        if (is_string($where)) {
            return str_replace('{@}', $this->alias, $where);
        }

        if (!is_array($where)) {
            return $where;
        }

        $result = [];
        foreach ($where as $column => $value) {
            if (is_string($column) && !is_int($column)) {
                $column = str_replace('{@}', $this->alias, $column);
            }

            $result[$column] = !is_array($value) ? $value : $this->prepare($value);
        }

        return $result;
    }
415557
public function getRelations(Where $where = null)
    {
        $condition = Where::createWhereIn('relkind', ['r', 'v', 'm', 'f'])
            ->andWhere($where)
            ;

        $sql = <<<SQL
select
    cl.relname      as "name",
    case
        when cl.relkind = 'r' then 'table'
        when cl.relkind = 'v' then 'view'
        when cl.relkind = 'm' then 'materialized view'
        when cl.relkind = 'f' then 'foreign table'
        else 'other'
    end             as "type",
    n.nspname       as "schema",
    cl.oid          as "oid",
    o.rolname       as "owner",
    case
        when cl.relkind = 'r' then pg_size_pretty(pg_relation_size(cl.oid::regclass))
        else null
    end             as "size",
    des.description as "comment"
from
    pg_catalog.pg_class cl
        left join pg_catalog.pg_description des on
            cl.oid = des.objoid and des.objsubid = 0
        join pg_catalog.pg_roles o on cl.relowner = o.oid
        join pg_catalog.pg_namespace n on cl.relnamespace = n.oid
where {condition}
order by name asc
SQL;

        return $this->executeSql($sql, $condition);
    }
1033442
protected function whereTime(Builder $query, $where)
    {
        $value = $this->parameter($where['value']);

        return $this->wrap($where['column']).'::time '.$where['operator'].' '.$value;
    }
1134211
public function getWhereStatement()
    {
        if (empty($this->where)) {
            return false;
        }
        $this->where[0]['operation'] = null;
        $str = '';
        foreach ($this->where as $clause) {
            $str .= trim("{$clause['operation']} {$clause['condition']}");
            $str .= " ";
        }

        return trim($str);
    }
600701
protected function whereIn(Builder $query, $where)
    {
        $values = $this->valufy($where['values']);

        return $this->wrap($where['column']).' IN ['.$values.']';
    }
107527
public function getCategory($where)
    {
        $model = Db::name('permission_category')->setConnection($this->getConnection());
        if (is_numeric($where)) {
            return $model->where('id', $where)->find();
        } else {
            return $model->where($where)->select();
        }
    }
661162
protected function whereDate(Builder $query, $where)
    {
        $value = $this->parameter($where['value']);

        return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value;
    }
1063006
public function all($where)
    {
        $where = LambdaUtils::toConditionCallable($where);
        foreach($this as $record)
        {
            if(!call_user_func($where, $record))
            {
                return false;
            }
        }
        return true;
    }
21644
public function delete(array $where)
    {
        // Current table
        $table = $this->getCollection();

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

        // Prepare query
        $statement = $this->getInstance()->prepare("DELETE FROM $table $whereDetails");

        // Bind where values
        foreach ($where as $key => $value) {
            $statement->bindValue(":where_$key", $value, $this->isPdoInt($value));
        }

        // Execute operation
        $statement->execute();

        // Return count of affected rows
        return $statement->rowCount();
    }
438411
public final function where($where = null, array $whereParams = null, string $op = null): ?string
    {
        if ($where != null) {
            $whereType = gettype($where);
            if ($whereType == 'array') {
                $op = strtoupper($op ?: 'AND');
                if (!in_array($op, ['AND', 'OR'])) {
                    throw new AgentException("Invalid operator '{$op}' given");
                }
                $where = join(' '. $op .' ', $where);
            } elseif ($whereType != 'string') {
                throw new AgentException("Invalid where type '{$whereType}' given");
            }

            $where = ($whereParams != null) ? 'WHERE ('. $this->prepare($where, $whereParams) .')'
                : 'WHERE ('. $where .')';

        }

        return $where;
    }