Skip to content

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

Merged
taylorotwell merged 2 commits intolaravel:5.6from
staudenmeir:sqlite-date
May 4, 2018
Merged

[5.6] Fix dateBasedWhere() with raw expressions in SQLite#24102
taylorotwell merged 2 commits intolaravel:5.6from
staudenmeir:sqlite-date

Conversation

@staudenmeir
Copy link
Copy Markdown
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.

2 participants