Skip to content
Snippets Groups Projects
Commit f8a123fd authored by Morton Jonuschat's avatar Morton Jonuschat
Browse files

[TASK] Doctrine: Extend ExpressionBuilder with bitwise and support

Extend the ExpressionBuilder with support for creating bitwise and
operations. Oracle needs a special SQL function to perform an &
operation and the core requires bitwise operations.

Releases: master
Resolves: #75563
Change-Id: I2ae7e20a9a4ced5b16330c94a3e9a6f156ba5f61
Reviewed-on: https://review.typo3.org/47760


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarNicole Cordes <typo3@cordes.co>
Tested-by: default avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
parent 02dbc9ad
Branches
Tags
No related merge requests found
...@@ -326,6 +326,32 @@ class ExpressionBuilder ...@@ -326,6 +326,32 @@ class ExpressionBuilder
} }
} }
/**
* Creates a bitwise AND expression with the given arguments.
*
* @param string $fieldName The fieldname. Will be quoted according to database platform automatically.
* @param int $value Argument to be used in the bitwise AND operation
* @return string
*/
public function bitAnd(string $fieldName, int $value): string
{
switch ($this->connection->getDatabasePlatform()->getName()) {
case 'oci8':
case 'pdo_oracle':
return sprintf(
'BITAND(%s, %s)',
$this->connection->quoteIdentifier($fieldName),
$value
);
default:
return $this->comparison(
$this->connection->quoteIdentifier($fieldName),
'&',
$value
);
}
}
/** /**
* Quotes a given input parameter. * Quotes a given input parameter.
* *
......
...@@ -271,6 +271,39 @@ class ExpressionBuilderTest extends UnitTestCase ...@@ -271,6 +271,39 @@ class ExpressionBuilderTest extends UnitTestCase
$this->assertSame('any(string_to_array("aField", \',\')) = \'1\'', $result); $this->assertSame('any(string_to_array("aField", \',\')) = \'1\'', $result);
} }
/**
* @test
*/
public function defaultBitwiseAnd()
{
$databasePlatform = $this->prophesize(MockPlatform::class);
$this->connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($args) {
return '"' . $args[0] . '"';
});
$this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatform->reveal());
$this->assertSame('"aField" & 1', $this->subject->bitAnd('aField', 1));
}
/**
* @test
*/
public function bitwiseAndForOracle()
{
$databasePlatform = $this->prophesize(MockPlatform::class);
$databasePlatform->getName()->willReturn('pdo_oracle');
$this->connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($args) {
return '"' . $args[0] . '"';
});
$this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatform->reveal());
$this->assertSame('BITAND("aField", 1)', $this->subject->bitAnd('aField', 1));
}
/** /**
* @test * @test
*/ */
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment