-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when using selectRaw
, array bindings are flattened
#39554
Comments
You could use like this. DB::table('whatever')
->selectRaw("SUM('case(`status` in (?)) as total_pending", [json_encode([1,2,3])])
->where('user', 1)
->groupBy('something')
->get() |
@bastien-phi no it is not fixed |
This seems to be related to #39553 and #39492 @taylorotwell I assume it's the same issue on this line
Replace @atymic / @RahulDey12 can you test this and confirm if this is the issue? |
@nuernbergerA Still same |
There is a mistake in the query:
The apostrophe before "case" is not needed. Of course, removing it will not solve the problem, but may help debugging it. I think the test for this case is: public function testBindInValuesIntoSelectRaw()
{
$expectedSql = 'select SUM(case(`status` in (?)) as total_pending from "whatever" where "user" = ? group by "something"';
$expectedBindings = [
"1,2,3",
1
];
$builder = $this->getBuilder();
$builder->selectRaw("SUM(case(`status` in (?)) as total_pending", [[1,2,3]])
->from('whatever')
->where('user', 1)
->groupBy('something');
$this->assertEquals($expectedSql, $builder->toSql());
$this->assertEquals($expectedBindings, $builder->getBindings());
} |
Should be fixed with da7aa38. Thanks |
@driesvints apologies for the delay. I don't think this is fixed for sum/case in statements. The issue seems to be that when I bind an wherein, the query builder is smart enough to put the correct amount of placeholders in, but it can't tell that when doing a selectraw with bound arrays. Will try to repro and find a workaround. |
There is a similar issue when doing something like Should I open a separate ticket for that? |
@jimktrains best if you can send in a PR with a failing test so we can verify the bug. |
Description:
Take the following query:
When laravel runs this query, the bindings are flattened, which results in
Possibly a security issue if query params are passed into a select raw? see #35865
Anyhow, I don't see why array bindings flattened, as they are supported by the database.
The text was updated successfully, but these errors were encountered: