Skip to content
Permalink
Browse files

Adding tests for modifiers in INSERT queries

  • Loading branch information...
lorenzo committed Feb 22, 2016
1 parent cbd51e3 commit 4123ba1a7c19813827c70e2d97c1b6270a22a3db
Showing with 39 additions and 1 deletion.
  1. +5 −1 src/Database/QueryCompiler.php
  2. +34 −0 tests/TestCase/Database/QueryTest.php
@@ -70,7 +70,7 @@ class QueryCompiler
*
* @var array
*/
protected $_insertParts = ['insert', 'modifier', 'values', 'epilog'];
protected $_insertParts = ['insert', 'values', 'epilog'];
/**
* Indicate whether or not this query dialect supports ordered unions.
@@ -289,6 +289,10 @@ protected function _buildInsertPart($parts, $query, $generator)
$columns = $this->_stringifyExpressions($parts[1], $generator);
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
if ($modifiers !== null) {
$modifiers .= ' ';
}
return sprintf('INSERT %sINTO %s (%s)', $modifiers, $table, implode(', ', $columns));
}
@@ -3635,6 +3635,40 @@ public function testBetweenExpressionAndTypeMap()
$this->assertCount(2, $query->execute()->fetchAll());
}
/**
* Test use of modifiers in a INSERT query
*
* Testing the generated SQL since the modifiers are usually different per driver
*
* @return void
*/
public function testInsertModifiers()
{
$query = new Query($this->connection);
$result = $query
->insert(['title'])
->into('articles')
->values(['title' => 'foo'])
->modifier('IGNORE');
$this->assertQuotedQuery(
'INSERT IGNORE INTO <articles> \(<title>\) VALUES \(:c0\)',
$result->sql(),
!$this->autoQuote
);
$query = new Query($this->connection);
$result = $query
->insert(['title'])
->into('articles')
->values(['title' => 'foo'])
->modifier(['IGNORE', 'LOW_PRIORITY']);
$this->assertQuotedQuery(
'INSERT IGNORE LOW_PRIORITY INTO <articles> \(<title>\) VALUES \(:c0\)',
$result->sql(),
!$this->autoQuote
);
}
/**
* Assertion for comparing a table's contents with what is in it.
*

0 comments on commit 4123ba1

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