1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Query\AST\Functions; |
21
|
|
|
|
22
|
|
|
use Doctrine\ORM\Query\SqlWalker; |
23
|
|
|
use Doctrine\ORM\Query\QueryException; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* "DATE_ADD(date1, interval, unit)" |
27
|
|
|
* |
28
|
|
|
* |
29
|
|
|
* @link www.doctrine-project.org |
30
|
|
|
* @since 2.0 |
31
|
|
|
* @author Guilherme Blanco <[email protected]> |
32
|
|
|
* @author Benjamin Eberlei <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class DateSubFunction extends DateAddFunction |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @override |
38
|
|
|
* @inheritdoc |
39
|
|
|
*/ |
40
|
6 |
View Code Duplication |
public function getSql(SqlWalker $sqlWalker) |
41
|
|
|
{ |
42
|
6 |
|
switch (strtolower($this->unit->value)) { |
43
|
6 |
|
case 'second': |
44
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubSecondsExpression( |
45
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
46
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
47
|
|
|
); |
48
|
5 |
|
case 'minute': |
49
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMinutesExpression( |
50
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
51
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
52
|
|
|
); |
53
|
4 |
|
case 'hour': |
54
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression( |
55
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
56
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
57
|
|
|
); |
58
|
3 |
|
case 'day': |
59
|
|
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression( |
60
|
|
|
$this->firstDateExpression->dispatch($sqlWalker), |
61
|
|
|
$this->intervalExpression->dispatch($sqlWalker) |
62
|
|
|
); |
63
|
3 |
|
case 'week': |
64
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubWeeksExpression( |
65
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
66
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
67
|
|
|
); |
68
|
2 |
|
case 'month': |
69
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMonthExpression( |
70
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
71
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
72
|
|
|
); |
73
|
1 |
|
case 'year': |
74
|
1 |
|
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubYearsExpression( |
75
|
1 |
|
$this->firstDateExpression->dispatch($sqlWalker), |
76
|
1 |
|
$this->intervalExpression->dispatch($sqlWalker) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
default: |
80
|
|
|
throw QueryException::semanticalError( |
81
|
|
|
'DATE_SUB() only supports units of type second, minute, hour, day, week, month and year.' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|