Skip to content

Commit c6b8168

Browse files
committed
Add limit bindings for having between + tests.
1 parent dbbb1c1 commit c6b8168

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ public function havingBetween($column, array $values, $boolean = 'and', $not = f
17911791

17921792
$this->havings[] = compact('type', 'column', 'values', 'boolean', 'not');
17931793

1794-
$this->addBinding($this->cleanBindings($values), 'having');
1794+
$this->addBinding(array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2), 'having');
17951795

17961796
return $this;
17971797
}

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ public function testWhereBetweens()
654654
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
655655
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
656656

657+
$builder = $this->getBuilder();
658+
$builder->select('*')->from('users')->whereBetween('id', [[1, 2, 3]]);
659+
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
660+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
661+
662+
$builder = $this->getBuilder();
663+
$builder->select('*')->from('users')->whereBetween('id', [[1], [2, 3]]);
664+
$this->assertSame('select * from "users" where "id" between ? and ?', $builder->toSql());
665+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
666+
657667
$builder = $this->getBuilder();
658668
$builder->select('*')->from('users')->whereNotBetween('id', [1, 2]);
659669
$this->assertSame('select * from "users" where "id" not between ? and ?', $builder->toSql());
@@ -1172,10 +1182,19 @@ public function testHavings()
11721182
$builder = $this->getBuilder();
11731183
$builder->select(['category', new Raw('count(*) as "total"')])->from('item')->where('department', '=', 'popular')->groupBy('category')->having('total', '>', 3);
11741184
$this->assertSame('select "category", count(*) as "total" from "item" where "department" = ? group by "category" having "total" > ?', $builder->toSql());
1185+
}
11751186

1187+
public function testHavingBetweens()
1188+
{
11761189
$builder = $this->getBuilder();
1177-
$builder->select('*')->from('users')->havingBetween('last_login_date', ['2018-11-16', '2018-12-16']);
1178-
$this->assertSame('select * from "users" having "last_login_date" between ? and ?', $builder->toSql());
1190+
$builder->select('*')->from('users')->havingBetween('id', [1, 2, 3]);
1191+
$this->assertSame('select * from "users" having "id" between ? and ?', $builder->toSql());
1192+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
1193+
1194+
$builder = $this->getBuilder();
1195+
$builder->select('*')->from('users')->havingBetween('id', [[1, 2], [3, 4]]);
1196+
$this->assertSame('select * from "users" having "id" between ? and ?', $builder->toSql());
1197+
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
11791198
}
11801199

11811200
public function testHavingShortcut()

0 commit comments

Comments
 (0)