Skip to content

Commit 8eb0a39

Browse files
committed
- Allow MySQL::quoteExpression to take less arguments than necessary. If more arguments are required than available, the last given argument is used to fill the remaining placeholders.
1 parent 45ed41e commit 8eb0a39

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 7.2
45
- 7.1
56
- 7.0
67
- 5.6

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"psr/log": "~1"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "~4.0",
16+
"phpunit/phpunit": "~5.0",
1717
"phake/phake": "1.0.5",
1818
"rkr/fakepdo": "0.1.*"
1919
},

src/Databases/MySQL.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ public function getTableFields($table) {
151151
* @return string
152152
*/
153153
public function quoteExpression($expression, array $arguments = array()) {
154-
$func = function () use ($arguments) {
155-
static $idx = -1;
156-
$idx++;
157-
$index = $idx;
154+
$index = -1;
155+
$func = function () use ($arguments, &$index) {
156+
$index++;
158157
if(array_key_exists($index, $arguments)) {
159158
$argument = $arguments[$index];
160159
$value = $this->quote($argument);
160+
} elseif(count($arguments) > 0) {
161+
$args = $arguments;
162+
$value = array_pop($args);
163+
$value = $this->quote($value);
161164
} else {
162165
$value = 'NULL';
163166
}

tests/Builder/SelectTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ public function testDBExpr() {
123123
$this->assertEquals("SELECT\n\ta\nFROM\n\ttest t\nWHERE\n\t(a < '1000')\n", $str);
124124
}
125125

126+
public function testDBExprFilter() {
127+
$str = TestSelect::create()
128+
->field('a')
129+
->from('t', 'test')
130+
->where(new DBExprFilter('a=? AND b=?', ['x' => ['y' => 1]], 'x.y'))
131+
->having(new DBExprFilter('a=? AND b=?', ['x' => ['y' => 1]], 'x.y'))
132+
->asString();
133+
$this->assertEquals("SELECT\n\ta\nFROM\n\ttest t\nWHERE\n\t(a='1' AND b='1')\nHAVING\n\t(a='1' AND b='1')\n", $str);
134+
}
135+
126136
public function testOrder() {
127137
$str = TestSelect::create()
128138
->field('a')

0 commit comments

Comments
 (0)