Skip to content

Commit

Permalink
Merge branch '3.3.x' into 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Dec 17, 2021
2 parents f63c6de + 421b8e8 commit f18c5e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ public function getLengthExpression(string $string): string
return 'LENGTH(' . $string . ')';
}

/**
* Returns the SQL snippet to get the remainder of the operation of division of dividend by divisor.
*
* @param string $dividend SQL expression producing the dividend.
* @param string $divisor SQL expression producing the divisor.
*/
public function getModExpression(string $dividend, string $divisor): string
{
return 'MOD(' . $dividend . ', ' . $divisor . ')';
}

/**
* Returns the SQL snippet to trim a string.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Functional/Platform/ModExpressionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Platform;

use Doctrine\DBAL\Tests\FunctionalTestCase;

final class ModExpressionTest extends FunctionalTestCase
{
public function testModExpression(): void
{
$platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL($platform->getModExpression('5', '2'));

self::assertEquals('1', $this->connection->fetchOne($query));
}
}

0 comments on commit f18c5e3

Please sign in to comment.