clause('epilog')) { $query->epilog('RETURNING *'); } return $query; } /** * Returns an dictionary of expressions to be transformed when compiling a Query * to SQL. Array keys are method names to be called in this class * * @return array */ protected function _expressionTranslators() { $namespace = 'Cake\Database\Expression'; return [ $namespace . '\FunctionExpression' => '_transformFunctionExpression' ]; } /** * Receives a FunctionExpression and changes it so that it conforms to this * SQL dialect. * * @param Cake\Database\Expression\FunctionExpression * @return void */ 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['value']], [$p['type']]); }); break; case 'CURRENT_DATE': $time = new FunctionExpression('LOCALTIMESTAMP', [' 0 ' => 'literal']); $expression->name('CAST')->type(' AS ')->add([$time, 'date' => 'literal']); break; case 'CURRENT_TIME': $time = new FunctionExpression('LOCALTIMESTAMP', [' 0 ' => 'literal']); $expression->name('CAST')->type(' AS ')->add([$time, 'time' => 'literal']); break; case 'NOW': $expression->name('LOCALTIMESTAMP')->add([' 0 ' => 'literal']); break; } } /** * Get the schema dialect. * * Used by Cake\Schema package to reflect schema and * generate schema. * * @return Cake\Database\Schema\PostgresSchema */ public function schemaDialect() { return new \Cake\Database\Schema\PostgresSchema($this); } }