diff --git a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php index 6de9cc1ed2cf..4c9e26172e2d 100755 --- a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php @@ -138,9 +138,7 @@ protected function whereTime(Builder $query, $where) */ protected function dateBasedWhere($type, Builder $query, $where) { - $value = str_pad($where['value'], 2, '0', STR_PAD_LEFT); - - $value = $this->parameter($value); + $value = $this->parameter($where['value']); return "strftime('{$type}', {$this->wrap($where['column'])}) {$where['operator']} {$value}"; } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index b4f6a36130e4..1448cde5392e 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -289,7 +289,7 @@ public function testDateBasedWheresAcceptsTwoArguments() $this->assertEquals('select * from `users` where month(`created_at`) = ?', $builder->toSql()); $builder = $this->getMySqlBuilder(); - $builder->select('*')->from('users')->whereyear('created_at', 1); + $builder->select('*')->from('users')->whereYear('created_at', 1); $this->assertEquals('select * from `users` where year(`created_at`) = ?', $builder->toSql()); } @@ -300,6 +300,18 @@ public function testDateBasedWheresExpressionIsNotBound() $this->assertEquals([true], $builder->getBindings()); } + public function testWhereDateMySql() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', '=', '2015-12-21'); + $this->assertEquals('select * from `users` where date(`created_at`) = ?', $builder->toSql()); + $this->assertEquals([0 => '2015-12-21'], $builder->getBindings()); + + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', '=', new Raw('NOW()')); + $this->assertEquals('select * from `users` where date(`created_at`) = NOW()', $builder->toSql()); + } + public function testWhereDayMySql() { $builder = $this->getMySqlBuilder(); @@ -378,6 +390,10 @@ public function testWhereDatePostgres() $builder->select('*')->from('users')->whereDate('created_at', '=', '2015-12-21'); $this->assertEquals('select * from "users" where "created_at"::date = ?', $builder->toSql()); $this->assertEquals([0 => '2015-12-21'], $builder->getBindings()); + + $builder = $this->getPostgresBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', new Raw('NOW()')); + $this->assertEquals('select * from "users" where "created_at"::date = NOW()', $builder->toSql()); } public function testWhereDayPostgres() @@ -412,6 +428,18 @@ public function testWhereTimePostgres() $this->assertEquals([0 => '22:00'], $builder->getBindings()); } + public function testWhereDateSqlite() + { + $builder = $this->getSQLiteBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', '=', '2015-12-21'); + $this->assertEquals('select * from "users" where strftime(\'%Y-%m-%d\', "created_at") = ?', $builder->toSql()); + $this->assertEquals([0 => '2015-12-21'], $builder->getBindings()); + + $builder = $this->getSQLiteBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', new Raw('NOW()')); + $this->assertEquals('select * from "users" where strftime(\'%Y-%m-%d\', "created_at") = NOW()', $builder->toSql()); + } + public function testWhereDaySqlite() { $builder = $this->getSQLiteBuilder(); @@ -452,6 +480,18 @@ public function testWhereTimeOperatorOptionalSqlite() $this->assertEquals([0 => '22:00'], $builder->getBindings()); } + public function testWhereDateSqlServer() + { + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', '=', '2015-12-21'); + $this->assertEquals('select * from [users] where cast([created_at] as date) = ?', $builder->toSql()); + $this->assertEquals([0 => '2015-12-21'], $builder->getBindings()); + + $builder = $this->getSqlServerBuilder(); + $builder->select('*')->from('users')->whereDate('created_at', new Raw('NOW()')); + $this->assertEquals('select * from [users] where cast([created_at] as date) = NOW()', $builder->toSql()); + } + public function testWhereDaySqlServer() { $builder = $this->getSqlServerBuilder();