Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'kpieters-hotfix/ZF2-536' into develop

Pull Request #2325
  • Loading branch information...
commit 0fe92320c69bcadac1cc4b322d5ad1bfa9f92e48 2 parents 959f904 + 8ecdb5f
@ralphschindler ralphschindler authored
View
8 library/Zend/Db/Sql/Insert.php
@@ -98,14 +98,18 @@ public function columns(array $columns)
public function values(array $values, $flag = self::VALUES_SET)
{
if ($values == null) {
- throw new Exception\InvalidArgumentException('values() expects an array of values');
+ throw new \InvalidArgumentException('values() expects an array of values');
}
$keys = array_keys($values);
$firstKey = current($keys);
if (is_string($firstKey)) {
- $this->columns($keys);
+ if ($flag == self::VALUES_MERGE) {
+ $this->columns(array_merge($this->columns, $keys));
+ } else {
+ $this->columns($keys);
+ }
$values = array_values($values);
} elseif (is_int($firstKey)) {
$values = array_values($values);
View
14 tests/ZendTest/Db/Sql/InsertTest.php
@@ -133,4 +133,18 @@ public function test__get()
$this->assertEquals('bar', $this->insert->foo);
}
+ /**
+ * @group ZF2-536
+ */
+ public function testValuesMerge()
+ {
+ $this->insert->into('foo')
+ ->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));
+ $this->insert->into('foo')
+ ->values(array('qux' => 100), Insert::VALUES_MERGE);
+
+ $this->assertEquals('INSERT INTO "foo" ("bar", "boo", "bam", "qux") VALUES (\'baz\', NOW(), NULL, \'100\')', $this->insert->getSqlString());
+
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.