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 whereTime() on SQL Server #25316

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ protected function whereDate(Builder $query, $where)
return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value;
}

/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereTime(Builder $query, $where)
{
$value = $this->parameter($where['value']);

return 'cast('.$this->wrap($where['column']).' as time) '.$where['operator'].' '.$value;
}

/**
* Compile a "JSON contains" statement into SQL.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ public function testWhereTimeOperatorOptionalPostgres()
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereTimeSqlServer()
{
$builder = $this->getSqlServerBuilder();
$builder->select('*')->from('users')->whereTime('created_at', '22:00');
$this->assertEquals('select * from [users] where cast([created_at] as time) = ?', $builder->toSql());
$this->assertEquals([0 => '22:00'], $builder->getBindings());

$builder = $this->getSqlServerBuilder();
$builder->select('*')->from('users')->whereTime('created_at', new Raw('NOW()'));
$this->assertEquals('select * from [users] where cast([created_at] as time) = NOW()', $builder->toSql());
$this->assertEquals([], $builder->getBindings());
}

public function testWhereDatePostgres()
{
$builder = $this->getPostgresBuilder();
Expand Down