Skip to content
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

[5.6] Fix dateBasedWhere() with raw expressions in SQLite #24102

Merged
merged 2 commits into from
May 4, 2018
Merged

[5.6] Fix dateBasedWhere() with raw expressions in SQLite #24102

merged 2 commits into from
May 4, 2018

Conversation

staudenmeir
Copy link
Contributor

whereDate(), whereMonth() etc. don't work with raw expressions in SQLite:

DB::table('users')->whereDate('created_at', DB::raw('NOW()'))->toSql();
// expected: select * from "users" where strftime('%Y-%m-%d', "created_at") = NOW()
// actual:   select * from "users" where strftime('%Y-%m-%d', "created_at") = ?

This line causes the problem:

$value = str_pad($where['value'], 2, '0', STR_PAD_LEFT);

The code looks like it pads days/months from 1 to 01 when calling whereDay()/whereMonth().

But since the value is added to the bindings before this is called, it has no effect. In the next line $this->parameter() replaces it with the placeholder ?.

This PR adds raw expression tests for all databases and also missing whereDate() tests.

@taylorotwell taylorotwell merged commit 682f8af into laravel:5.6 May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants