Nette\Database\SqlPreprocessor::process PHP Method

process() public method

public process ( $params ) : array
return array of [sql, params]
    public function process($params)
    {
        $this->params = $params;
        $this->counter = 0;
        $prev = -1;
        $this->remaining = [];
        $this->arrayMode = NULL;
        $res = [];
        while ($this->counter < count($params)) {
            $param = $params[$this->counter++];
            if ($this->counter === 2 && count($params) === 2 || !is_scalar($param)) {
                $res[] = $this->formatValue($param, 'auto');
                $this->arrayMode = NULL;
            } elseif (is_string($param) && $this->counter > $prev + 1) {
                $prev = $this->counter;
                $this->arrayMode = NULL;
                $res[] = Nette\Utils\Strings::replace($param, '~\'[^\']*+\'|"[^"]*+"|\\?[a-z]*|^\\s*+(?:INSERT|REPLACE)\\b|\\b(?:SET|WHERE|HAVING|ORDER BY|GROUP BY|KEY UPDATE)(?=\\s*\\z|\\s*\\?)|/\\*.*?\\*/|--[^\\n]*~si', [$this, 'callback']);
            } else {
                throw new Nette\InvalidArgumentException('There are more parameters than placeholders.');
            }
        }
        return [implode(' ', $res), $this->remaining];
    }

Usage Example

 /**
  * @param  string  statement
  * @param  array
  * @return ResultSet
  */
 public function queryArgs($statement, array $params)
 {
     $this->connection->connect();
     if ($params) {
         if (!$this->preprocessor) {
             $this->preprocessor = new SqlPreprocessor($this->connection);
         }
         array_unshift($params, $statement);
         list($statement, $params) = $this->preprocessor->process($params);
     }
     try {
         $result = new ResultSet($this->connection, $statement, $params);
     } catch (\PDOException $e) {
         $e->queryString = $statement;
         $this->connection->onQuery($this->connection, $e);
         throw $e;
     }
     $this->connection->onQuery($this->connection, $result);
     return $result;
 }
All Usage Examples Of Nette\Database\SqlPreprocessor::process