Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2224

convertToDatabaseValueSQL() is not honored for DQL query parameters

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: Git Master, 2.3.1
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Following discussion on Google Groups:
      https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ

      When using a mapping type which declares convertToDatabaseValueSQL(), this method is not invoked when passing a value as parameter to a DQL query.

      For example, if I declare a mapping type MyType:

      class MyType extends \Doctrine\DBAL\Types\Type
      {
          public function canRequireSQLConversion()
          {
              return true;
          }
      
          public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
          {
              return sprintf('FUNCTION(%s)', $sqlExpr);
          }
      
          // ...
      }
      

      And pass a parameter with this type to a DQL query:

      $query = $em->createQuery('SELECT e FROM Entity e WHERE e.field = :field');
      $query->setParameter('field', $value, 'MyType');
      

      I would expect the following SQL to be generated:

      SELECT ... WHERE ... = FUNCTION(?)
      

      But the current SQL generated is the following:

      SELECT ... WHERE ... = ?
      

        Issue Links

          Activity

          Benjamin Morel created issue -
          Benjamin Morel made changes -
          Field Original Value New Value
          Description Following discussion on Google Groups:
          https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ

          When using a mapping type which declares convertToDatabaseValueSQL(), this method is not invoked when passing a value as parameter to a DQL query.

          For example, if I declare a mapping type MyType:

          {code}
          class MyType extends \Doctrine\DBAL\Types\Type {
              public function canRequireSQLConversion() {
                  return true;
              }

              public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) {
                  return sprintf('FUNCTION(%s)', $sqlExpr);
              }

              // ...
          }
          {code}

          And pass a parameter with this type to a DQL query:

          {code}
          $query = $em->createQuery('SELECT e FROM Entity e WHERE e.field = :field');
          $query->setParameter('field', $value, 'MyType');
          {code}

          I would expect the following SQL to be generated:

          {code}
          SELECT ... WHERE ... = FUNCTION(?)
          {code}

          But the current SQL generated is the following:

          {code}
          SELECT ... WHERE ... = ?
          {code}
          Following discussion on Google Groups:
          https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ

          When using a mapping type which declares {{convertToDatabaseValueSQL()}}, this method is not invoked when passing a value as parameter to a DQL query.

          For example, if I declare a mapping type {{MyType}}:

          {code}
          class MyType extends \Doctrine\DBAL\Types\Type
          {
              public function canRequireSQLConversion()
          {
                  return true;
              }

              public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
          {
                  return sprintf('FUNCTION(%s)', $sqlExpr);
              }

              // ...
          }
          {code}

          And pass a parameter with this type to a DQL query:

          {code}
          $query = $em->createQuery('SELECT e FROM Entity e WHERE e.field = :field');
          $query->setParameter('field', $value, 'MyType');
          {code}

          I would expect the following SQL to be generated:

          {code}
          SELECT ... WHERE ... = FUNCTION(?)
          {code}

          But the current SQL generated is the following:

          {code}
          SELECT ... WHERE ... = ?
          {code}
          Benjamin Morel made changes -
          Attachment DDC2224Test.php [ 11367 ]
          Benjamin Morel made changes -
          Description Following discussion on Google Groups:
          https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ

          When using a mapping type which declares {{convertToDatabaseValueSQL()}}, this method is not invoked when passing a value as parameter to a DQL query.

          For example, if I declare a mapping type {{MyType}}:

          {code}
          class MyType extends \Doctrine\DBAL\Types\Type
          {
              public function canRequireSQLConversion()
          {
                  return true;
              }

              public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
          {
                  return sprintf('FUNCTION(%s)', $sqlExpr);
              }

              // ...
          }
          {code}

          And pass a parameter with this type to a DQL query:

          {code}
          $query = $em->createQuery('SELECT e FROM Entity e WHERE e.field = :field');
          $query->setParameter('field', $value, 'MyType');
          {code}

          I would expect the following SQL to be generated:

          {code}
          SELECT ... WHERE ... = FUNCTION(?)
          {code}

          But the current SQL generated is the following:

          {code}
          SELECT ... WHERE ... = ?
          {code}
          Following discussion on Google Groups:
          https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ

          When using a mapping type which declares {{convertToDatabaseValueSQL()}}, this method is not invoked when passing a value as parameter to a DQL query.

          For example, if I declare a mapping type {{MyType}}:

          {code}
          class MyType extends \Doctrine\DBAL\Types\Type
          {
              public function canRequireSQLConversion()
              {
                  return true;
              }

              public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
              {
                  return sprintf('FUNCTION(%s)', $sqlExpr);
              }

              // ...
          }
          {code}

          And pass a parameter with this type to a DQL query:

          {code}
          $query = $em->createQuery('SELECT e FROM Entity e WHERE e.field = :field');
          $query->setParameter('field', $value, 'MyType');
          {code}

          I would expect the following SQL to be generated:

          {code}
          SELECT ... WHERE ... = FUNCTION(?)
          {code}

          But the current SQL generated is the following:

          {code}
          SELECT ... WHERE ... = ?
          {code}
          Benjamin Morel made changes -
          Comment [ A test case for this bug. ]
          Benjamin Morel made changes -
          Attachment DDC2224Test.php [ 11367 ]
          Benjamin Morel made changes -
          Attachment DDC2224Test.php [ 11369 ]
          Benjamin Eberlei made changes -
          Link This issue duplicates DDC-2240 [ DDC-2240 ]
          Benjamin Eberlei made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Invalid [ 6 ]

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Benjamin Morel
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: