Spot\Query::whereFieldSql PHP Method

whereFieldSql() public method

WHERE field + raw SQL
public whereFieldSql ( string $field, string $sql, array $params = [] )
$field string Field name for SQL statement (will be quoted)
$sql string SQL string to put in WHERE clause
$params array
    public function whereFieldSql($field, $sql, array $params = [])
    {
        $builder = $this->builder();
        $placeholderCount = substr_count($sql, '?');
        $paramCount = count($params);
        if ($placeholderCount !== $paramCount) {
            throw new Exception("Number of supplied parameters (" . $paramCount . ") does not match the number of provided placeholders (" . $placeholderCount . ")");
        }
        $sql = preg_replace_callback('/\\?/', function ($match) use($builder, $params) {
            $param = array_shift($params);
            return $builder->createPositionalParameter($param);
        }, $sql);
        $builder->andWhere($this->escapeIdentifier($field) . ' ' . $sql);
        return $this;
    }