Skip to content
Permalink
Browse files

Starting to add the modifier clause to insert, update and delete

  • Loading branch information...
lorenzo committed Feb 21, 2016
1 parent dd7cd46 commit cbd51e3750ee5561bf5d16520f1e1e4444481591
Showing with 26 additions and 10 deletions.
  1. +19 −9 src/Database/QueryCompiler.php
  2. +7 −1 src/Database/SqlserverCompiler.php
@@ -56,21 +56,21 @@ class QueryCompiler
*
* @var array
*/
protected $_updateParts = ['update', 'set', 'where', 'epilog'];
protected $_updateParts = ['update', 'modifier', 'set', 'where', 'epilog'];
/**
* The list of query clauses to traverse for generating a DELETE statement
*
* @var array
*/
protected $_deleteParts = ['delete', 'from', 'where', 'epilog'];
protected $_deleteParts = ['delete', 'modifier', 'from', 'where', 'epilog'];
/**
* The list of query clauses to traverse for generating an INSERT statement
*
* @var array
*/
protected $_insertParts = ['insert', 'values', 'epilog'];
protected $_insertParts = ['insert', 'modifier', 'values', 'epilog'];
/**
* Indicate whether or not this query dialect supports ordered unions.
@@ -145,7 +145,7 @@ protected function _buildSelectPart($parts, $query, $generator)
$select = '(SELECT %s%s%s';
}
$distinct = $query->clause('distinct');
$modifiers = $query->clause('modifier') ?: null;
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
$normalized = [];
$parts = $this->_stringifyExpressions($parts, $generator);
@@ -160,14 +160,14 @@ protected function _buildSelectPart($parts, $query, $generator)
$distinct = 'DISTINCT ';
}
if ($modifiers !== null) {
$modifiers .= ' ';
}
if (is_array($distinct)) {
$distinct = $this->_stringifyExpressions($distinct, $generator);
$distinct = sprintf('DISTINCT ON (%s) ', implode(', ', $distinct));
}
if ($modifiers !== null) {
$modifiers = $this->_stringifyExpressions($modifiers, $generator);
$modifiers = implode(' ', $modifiers) . ' ';
}
return sprintf($select, $distinct, $modifiers, implode(', ', $normalized));
}
@@ -287,7 +287,9 @@ protected function _buildInsertPart($parts, $query, $generator)
{
$table = $parts[0];
$columns = $this->_stringifyExpressions($parts[1], $generator);
return sprintf('INSERT INTO %s (%s)', $table, implode(', ', $columns));
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf('INSERT %sINTO %s (%s)', $modifiers, $table, implode(', ', $columns));
}
/**
@@ -303,6 +305,14 @@ protected function _buildValuesPart($parts, $query, $generator)
return implode('', $this->_stringifyExpressions($parts, $generator));
}
protected function _buildModifierPart($parts, $query, $generator)
{
if ($parts === []) {
return null;
}
return implode(' ', $this->_stringifyExpressions($parts, $generator));
}
/**
* Helper function used to covert ExpressionInterface objects inside an array
* into their string representation.
@@ -68,7 +68,13 @@ protected function _buildInsertPart($parts, $query, $generator)
{
$table = $parts[0];
$columns = $this->_stringifyExpressions($parts[1], $generator);
return sprintf('INSERT INTO %s (%s) OUTPUT INSERTED.*', $table, implode(', ', $columns));
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf('INSERT %sINTO %s (%s) OUTPUT INSERTED.*',
$modifiers,
$table,
implode(', ', $columns)
);
}
/**

0 comments on commit cbd51e3

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