Skip to content

Loading…

DDC-697: Support for DateTime in query parameters #5208

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user vrtak-cz:

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

/****
 * @var DateTime
 *
 * @Column(type="datetime")
 */
private $published;
$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

@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by @beberlei:

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

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

@doctrinebot

Comment created by @beberlei:

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?

@doctrinebot

Comment created by vrtak-cz:

$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).

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-BETA3 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.