Skip to content

Commit a6368a0

Browse files
committed
- Update::setExpr not takes value-parameters
1 parent dfbec3c commit a6368a0

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

src/Builder/InsertUpdateStatement.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
use Kir\MySQL\Builder\Internal\DefaultValue;
55

66
abstract class InsertUpdateStatement extends Statement {
7-
/**
8-
* @var array
9-
*/
7+
/** @var array */
108
private $mask = null;
119

1210
/**
@@ -39,6 +37,9 @@ protected function buildFieldList(array $fields, array $query = array()) {
3937
continue;
4038
}
4139
if (is_int($fieldName)) {
40+
if(is_array($fieldValue)) {
41+
$fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1));
42+
}
4243
$query[] = "\t{$fieldValue}";
4344
} else {
4445
$fieldName = $this->db()->quoteField($fieldName);

src/Builder/Traits/WhereBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait WhereBuilder {
1515
* @return $this
1616
*/
1717
public function where($expression) {
18-
$this->where[] = array($expression, array_slice(func_get_args(), 1));
18+
$this->where[] = [$expression, array_slice(func_get_args(), 1)];
1919
return $this;
2020
}
2121

src/Builder/Update.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ public function setDefault($fieldName) {
5959

6060
/**
6161
* @param string $expr
62+
* @param string[] ...$value
6263
* @return $this
6364
*/
6465
public function setExpr($expr) {
65-
$this->fields[] = $expr;
66+
$this->fields[] = func_get_args();
6667
return $this;
6768
}
6869

tests/Builder/UpdateTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function testSetExpr() {
5555
$this->assertEquals("UPDATE\n\ttest1\nSET\n\tfield1=1\n", $sql);
5656
}
5757

58+
public function testSetExprWithParams() {
59+
$sql = TestUpdate::create()
60+
->table('test1')
61+
->setExpr('field1=COALESCE(?, ?)', 1, 2)
62+
->asString();
63+
$this->assertEquals("UPDATE\n\ttest1\nSET\n\tfield1=COALESCE('1', '2')\n", $sql);
64+
}
65+
5866
public function testSetAll1() {
5967
$sql = TestUpdate::create()
6068
->table('test1')

0 commit comments

Comments
 (0)