1 | <?php |
||
36 | class DateAddFunction extends FunctionNode |
||
37 | { |
||
38 | public $firstDateExpression = null; |
||
39 | public $intervalExpression = null; |
||
40 | public $unit = null; |
||
41 | |||
42 | /** |
||
43 | * @override |
||
44 | */ |
||
45 | 3 | public function getSql(SqlWalker $sqlWalker) |
|
46 | { |
||
47 | 3 | switch (strtolower($this->unit->value)) { |
|
48 | 3 | case 'second': |
|
49 | 1 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression( |
|
50 | 1 | $this->firstDateExpression->dispatch($sqlWalker), |
|
51 | 1 | $this->intervalExpression->dispatch($sqlWalker) |
|
52 | ); |
||
53 | |||
54 | 2 | case 'hour': |
|
55 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression( |
||
56 | $this->firstDateExpression->dispatch($sqlWalker), |
||
57 | $this->intervalExpression->dispatch($sqlWalker) |
||
58 | ); |
||
59 | 2 | case 'day': |
|
60 | 2 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression( |
|
61 | 2 | $this->firstDateExpression->dispatch($sqlWalker), |
|
62 | 2 | $this->intervalExpression->dispatch($sqlWalker) |
|
63 | ); |
||
64 | |||
65 | 1 | case 'month': |
|
66 | 1 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression( |
|
67 | 1 | $this->firstDateExpression->dispatch($sqlWalker), |
|
68 | 1 | $this->intervalExpression->dispatch($sqlWalker) |
|
69 | ); |
||
70 | |||
71 | default: |
||
72 | throw QueryException::semanticalError( |
||
73 | 'DATE_ADD() only supports units of type second, hour, day and month.' |
||
74 | ); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @override |
||
80 | */ |
||
81 | 4 | public function parse(Parser $parser) |
|
94 | } |
||
95 |