Skip to content
Permalink
Browse files

Fixing tests in Postgres

  • Loading branch information...
lorenzo committed Mar 9, 2013
1 parent c84b110 commit a178fb1fc98a2af3df78f7b53fa2711f9065a80d
@@ -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 {
@@ -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;
}
}
}
@@ -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)) . ')';
}
}
@@ -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]);
@@ -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);

0 comments on commit a178fb1

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