Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid generation where expresion sql when Type in use SQLConversion (convertToPHPValueSQL, convertToDatabaseValueSQL) #9989

Open
dbannik opened this issue Aug 11, 2022 · 1 comment

Comments

@dbannik
Copy link
Contributor

dbannik commented Aug 11, 2022

Bug Report

Q A
BC Break no
Version 2.20

Summary

Invalid generation where expresion sql when Type in use SQLConversion (convertToPHPValueSQL, convertToDatabaseValueSQL)

How to reproduce

final class EncryptedType extends BlobType
{
    public const NAME = 'encrypted';

    public function getName(): string
    {
        return self::NAME;
    }

    private function getSecret(): string
    {
        return EncryptedKey::getKey();
    }

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform): string
    {
        return sprintf('AES_ENCRYPT(%s, \'%s\')', $sqlExpr, $this->getSecret());
    }

    public function convertToPHPValueSQL($sqlExpr, $platform): string
    {
        return sprintf('AES_DECRYPT(%s, \'%s\')', $sqlExpr, $this->getSecret());
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        return $value;
    }

    public function requiresSQLCommentHint(AbstractPlatform $platform): bool
    {
        return true;
    }
}
/**
 * @ORM\Table(name="User")
 * @ORM\Entity
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\Column(name="Usr_Id", type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    public int $id;

    /**
     * @ORM\Column(name="Usr_FirstName", type="encrypted", nullable=false)
     */
    public string $firstName;

    /**
     * @ORM\Column(name="Usr_LastName", type="string", nullable=false)
     */
    public string $lastName;

    /**
     * @ORM\Column(name="Usr_Created", type="datetime_immutable", nullable=false)
     */
    public DateTimeImmutable $created;

    /**
     * @ORM\Column(name="Usr_DOB", type="date_immutable", nullable=false)
     */
    public DateTimeImmutable $dob;

    public function __construct(string $firstName, string $lastName, DateTimeImmutable $created, DateTimeImmutable $dob)
    {
        $this->firstName = $firstName;
        $this->lastName  = $lastName;
        $this->created   = $created;
        $this->dob       = $dob;
    }
}
$result = $entityManager->createQueryBuilder()
    ->from(User::class, 'user')
    ->select('user.firstName')
    ->where('user.firstName like :search')
    ->setParameter('search', '%testname%')
    ->getQuery()
    ->getResult();

Expected behavior

SELECT AES_DECRYPT(u0_.Usr_FirstName, 'secretKey') AS Usr_FirstName_0 FROM User u0_ WHERE AES_DECRYPT(u0_.Usr_FirstName, 'secretKey') LIKE '%testname%'

Current behavior

SELECT AES_DECRYPT(u0_.Usr_FirstName, 'secretKey') AS Usr_FirstName_0 FROM User u0_ WHERE u0_.Usr_FirstName LIKE '%testname%'
@mpdude
Copy link
Contributor

mpdude commented Jan 19, 2023

Does this work in 2.x, and if so, could you provide a test case to help isolate the regression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants