Skip to content

Commit

Permalink
Fixing tests in Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 9, 2013
1 parent c84b110 commit a178fb1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Expand Up @@ -18,6 +18,7 @@
namespace Cake\Model\Datasource\Database\Dialect;

use Cake\Model\Datasource\Database\Expression\UnaryExpression;
use Cake\Model\Datasource\Database\Expression\FunctionExpression;
use Cake\Model\Datasource\Database\Query;

trait PostgresDialectTrait {
Expand Down Expand Up @@ -63,4 +64,29 @@ protected function _rowNumberRemover() {
};
}


protected function _expressionTranslators() {
$namespace = 'Cake\Model\Datasource\Database\Expression';
return [
$namespace . '\FunctionExpression' => '_transformFunctionExpression'
];
}

protected function _transformFunctionExpression(FunctionExpression $expression) {
switch ($expression->name()) {
case 'CONCAT':
// CONCAT function is expressed as exp1 || exp2
$expression->name('')->type(' ||');
break;
case 'DATEDIFF':
$expression
->name('')
->type('-')
->iterateParts(function($p) {
return new FunctionExpression('DATE', [$p => 'literal']);
});
break;
}
}

}
Expand Up @@ -20,7 +20,8 @@
class UnaryExpression extends QueryExpression {

public function sql() {
return $this->_conjunction . ' (' . (string)$this->_conditions[0] . ')';
reset($this->_conditions);
return $this->_conjunction . ' (' . ((string)current($this->_conditions)) . ')';
}

}
Expand Up @@ -1887,7 +1887,7 @@ public function testInsertMultipleRowsSparse() {
*/
public function testInsertFromSelect() {
$this->_insertTwoRecords();
$select = (new Query($this->connection))->select('name, "some text", 99')
$select = (new Query($this->connection))->select("name, 'some text', 99")
->from('authors')
->where(['id' => 1]);

Expand All @@ -1901,7 +1901,7 @@ public function testInsertFromSelect() {

$result = $query->sql(false);
$this->assertContains('INSERT INTO articles (title, body, author_id) SELECT', $result);
$this->assertContains('SELECT name, "some text", 99 FROM authors', $result);
$this->assertContains("SELECT name, 'some text', 99 FROM authors", $result);
$result = $query->execute();

$this->assertCount(1, $result);
Expand Down

0 comments on commit a178fb1

Please sign in to comment.