/** * Returns the SQL representation of the provided query after generating * the placeholders for the bound values using the provided generator * * @param \Cake\Database\Query $query The query that is being compiled * @param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions * @return \Closure */ public function compile(Query $query, ValueBinder $generator) { $sql = ''; $type = $query->type(); $query->traverse($this->_sqlCompiler($sql, $query, $generator), $this->{'_' . $type . 'Parts'}); return $sql; }
/** * Iterates over each of the clauses in a query looking for identifiers and * quotes them * * @param Query $query The query to have its identifiers quoted * @return Query */ public function quote(Query $query) { $binder = $query->valueBinder(); $query->valueBinder(false); if ($query->type() === 'insert') { $this->_quoteInsert($query); } else { $this->_quoteParts($query); } $query->traverseExpressions([$this, 'quoteExpression']); $query->valueBinder($binder); return $query; }
/** * Queries need a default type to prevent fatal errors * when an uninitialized query has its sql() method called. * * @return void */ public function testDefaultType() { $query = new Query($this->connection); $this->assertEquals('', $query->sql()); $this->assertEquals('select', $query->type()); }
/** * Transforms the passed query to this Driver's dialect and returns an instance * of the transformed query and the full compiled SQL string * * @param \Cake\Database\Query $query The query to compile. * @param \Cake\Database\ValueBinder $generator The value binder to use. * @return array containing 2 entries. The first entity is the transformed query * and the second one the compiled SQL */ public function compileQuery(Query $query, ValueBinder $generator) { $processor = $this->newCompiler(); $translator = $this->queryTranslator($query->type()); $query = $translator($query); return [$query, $processor->compile($query, $generator)]; }
/** * Returns the SQL representation of the provided query after generating * the placeholders for the bound values using the provided generator * * @param \Cake\Database\Query $query The query that is being compiled * @param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions * @return \Closure */ public function compile(Query $query, ValueBinder $generator) { $sql = ''; $type = $query->type(); $query->traverse($this->_sqlCompiler($sql, $query, $generator), $this->{'_' . $type . 'Parts'}); // Propagate bound parameters from sub-queries if the // placeholders can be found in the SQL statement. if ($query->valueBinder() !== $generator) { foreach ($query->valueBinder()->bindings() as $binding) { $placeholder = ':' . $binding['placeholder']; if (preg_match('/' . $placeholder . '(?:\\W|$)/', $sql) > 0) { $generator->bind($placeholder, $binding['value'], $binding['type']); } } } return $sql; }