Skip to content
Permalink
Browse files

Fixing bug in auto quoting and adding more tests

  • Loading branch information...
lorenzo committed Nov 5, 2013
1 parent c036270 commit 842ea5bcce3ace5ea2f6a6afb721eaf5d7f999c0
Showing with 37 additions and 1 deletion.
  1. +6 −1 Cake/Database/SqlDialectTrait.php
  2. +31 −0 Cake/Test/TestCase/Database/QueryTest.php
@@ -184,7 +184,7 @@ protected function _transformDistinct($query) {
* Iterates over each of the clauses in a query looking for identifiers and
* quotes them
*
* @param string $type the type of query to be quoted
* @param string $type the type of query to be quoted
* @param Query $query The query to have its identifiers quoted
* @return Query
*/
@@ -217,6 +217,11 @@ protected function _quoteQueryIdentifiers($type, $query) {
foreach ((array)$query->clause('join') as $value) {
$alias = empty($value['alias']) ? null : $this->quoteIdentifier($value['alias']);
$value['alias'] = $alias;
if (is_string($value['table'])) {
$value['table'] = $this->quoteIdentifier($value['table']);
}
$result[$alias] = $value;
}
$query->join($result, [], true);
@@ -2072,6 +2072,37 @@ public function testQuotingFromAndAlias() {
$this->assertRegExp('/FROM \(bar\) AS [`"]foo[`"]$/', $sql);
}
/**
* Tests automatic identifier quoting for DISTINCT ON
*
* @return void
*/
public function testQuotingDistinctOn() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->distinct(['something'])->sql();
$this->assertRegExp('/[`"]something[`"]/', $sql);
}
/**
* Tests automatic identifier quoting in the join clause
*
* @return void
*/
public function testQuotingJoinsAndAlias() {
$this->connection->driver()->autoQuoting(true);
$query = new Query($this->connection);
$sql = $query->select('*')->join(['something'])->sql();
$this->assertRegExp('/JOIN [`"]something[`"]/', $sql);
$query = new Query($this->connection);
$sql = $query->select('*')->join(['foo' => 'something'])->sql();
$this->assertRegExp('/JOIN [`"]something[`"] [`"]foo[`"]/', $sql);
$query = new Query($this->connection);
$sql = $query->select('*')->join(['foo' => $query->newExpr()->add('bar')])->sql();
$this->assertRegExp('/JOIN \(bar\) [`"]foo[`"]/', $sql);
}
/**
* Assertion for comparing a table's contents with what is in it.

0 comments on commit 842ea5b

Please sign in to comment.
You can’t perform that action at this time.