Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-697

Support for DateTime in query parameters

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-BETA3
    • Component/s: DQL
    • Security Level: All
    • Labels:
      None

      Description

      Supports native DateTime in query parameters. (for more universal using)

      Column definition
      /**
       * @var DateTime
       *
       * @Column(type="datetime")
       */
      private $published;
      
      Query
      $qb = $em->getRepository('Entities\Foo')->createQueryBuilder('f');
      $qb->where("f.published <= ?1");
      $qb->setParameter(1, new \DateTime('2012-12-21 23:59:59'));
      

      Now display "Object of class DateTime could not be converted to string" error

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This is another case for possible optimizations in my opinion, is it possible to access the parameter needles from the ResultSetMapping? If so then we should add a convertToParam method to each Doctrine\DBAL\Types\Type and allow conversions to take place or just do nothing. This woulld help with this issue, aswell as with other more complex types to be bound.

        Show
        Benjamin Eberlei added a comment - This is another case for possible optimizations in my opinion, is it possible to access the parameter needles from the ResultSetMapping? If so then we should add a convertToParam method to each Doctrine\DBAL\Types\Type and allow conversions to take place or just do nothing. This woulld help with this issue, aswell as with other more complex types to be bound.
        Hide
        Benjamin Eberlei added a comment -

        This affects the following loop inside Doctrine\ORM\Query:

        http://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query.php#L234

        Show
        Benjamin Eberlei added a comment - This affects the following loop inside Doctrine\ORM\Query: http://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query.php#L234
        Hide
        Benjamin Eberlei added a comment -

        According to Roman this should already be possible with:

        $qb->setParameter(1, new \DateTime('2012-12-21 23:59:59'), \Doctrine\DBAL\Types\Type::DATETIME);
        

        can you verify this?

        Show
        Benjamin Eberlei added a comment - According to Roman this should already be possible with: $qb->setParameter(1, new \DateTime('2012-12-21 23:59:59'), \Doctrine\DBAL\Types\Type::DATETIME); can you verify this?
        Hide
        Patrik Votoček added a comment - - edited
        $qb->setParameter(1, new \DateTime('2012-12-21 23:59:59'), \Doctrine\DBAL\Types\Type::DATETIME);
        

        No this featrue not work for me. (Same error message) I'm tested at latest BETA release & latest code from master branch (GitHub).

        Show
        Patrik Votoček added a comment - - edited $qb->setParameter(1, new \DateTime('2012-12-21 23:59:59'), \Doctrine\DBAL\Types\Type::DATETIME); No this featrue not work for me. (Same error message) I'm tested at latest BETA release & latest code from master branch (GitHub).
        Hide
        Benjamin Eberlei added a comment -

        Fixed, QueryBuilder::setParameter() and QueryBuilder::setParameters() did not yet support setting parameter types.

        Show
        Benjamin Eberlei added a comment - Fixed, QueryBuilder::setParameter() and QueryBuilder::setParameters() did not yet support setting parameter types.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Patrik Votoček
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: