| @@ 46-90 (lines=45) @@ | ||
| 43 | * @override | |
| 44 | * @inheritdoc | |
| 45 | */ | |
| 46 | public function getSql(SqlWalker $sqlWalker) | |
| 47 |     { | |
| 48 |         switch (strtolower($this->unit->value)) { | |
| 49 | case 'second': | |
| 50 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression( | |
| 51 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 52 | $this->intervalExpression->dispatch($sqlWalker) | |
| 53 | ); | |
| 54 | case 'minute': | |
| 55 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMinutesExpression( | |
| 56 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 57 | $this->intervalExpression->dispatch($sqlWalker) | |
| 58 | ); | |
| 59 | case 'hour': | |
| 60 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression( | |
| 61 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 62 | $this->intervalExpression->dispatch($sqlWalker) | |
| 63 | ); | |
| 64 | case 'day': | |
| 65 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression( | |
| 66 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 67 | $this->intervalExpression->dispatch($sqlWalker) | |
| 68 | ); | |
| 69 | case 'week': | |
| 70 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddWeeksExpression( | |
| 71 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 72 | $this->intervalExpression->dispatch($sqlWalker) | |
| 73 | ); | |
| 74 | case 'month': | |
| 75 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression( | |
| 76 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 77 | $this->intervalExpression->dispatch($sqlWalker) | |
| 78 | ); | |
| 79 | case 'year': | |
| 80 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddYearsExpression( | |
| 81 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 82 | $this->intervalExpression->dispatch($sqlWalker) | |
| 83 | ); | |
| 84 | ||
| 85 | default: | |
| 86 | throw QueryException::semanticalError( | |
| 87 | 'DATE_ADD() only supports units of type second, minute, hour, day, week, month and year.' | |
| 88 | ); | |
| 89 | } | |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * @override | |
| @@ 40-84 (lines=45) @@ | ||
| 37 | * @override | |
| 38 | * @inheritdoc | |
| 39 | */ | |
| 40 | public function getSql(SqlWalker $sqlWalker) | |
| 41 |     { | |
| 42 |         switch (strtolower($this->unit->value)) { | |
| 43 | case 'second': | |
| 44 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubSecondsExpression( | |
| 45 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 46 | $this->intervalExpression->dispatch($sqlWalker) | |
| 47 | ); | |
| 48 | case 'minute': | |
| 49 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMinutesExpression( | |
| 50 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 51 | $this->intervalExpression->dispatch($sqlWalker) | |
| 52 | ); | |
| 53 | case 'hour': | |
| 54 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression( | |
| 55 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 56 | $this->intervalExpression->dispatch($sqlWalker) | |
| 57 | ); | |
| 58 | case 'day': | |
| 59 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression( | |
| 60 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 61 | $this->intervalExpression->dispatch($sqlWalker) | |
| 62 | ); | |
| 63 | case 'week': | |
| 64 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubWeeksExpression( | |
| 65 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 66 | $this->intervalExpression->dispatch($sqlWalker) | |
| 67 | ); | |
| 68 | case 'month': | |
| 69 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMonthExpression( | |
| 70 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 71 | $this->intervalExpression->dispatch($sqlWalker) | |
| 72 | ); | |
| 73 | case 'year': | |
| 74 | return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubYearsExpression( | |
| 75 | $this->firstDateExpression->dispatch($sqlWalker), | |
| 76 | $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 | ||