DDC-1282: getDateAddDaysExpression() casts $days to integer preventing column based add expressions. #1895

Closed
doctrinebot opened this Issue Jul 20, 2011 · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user spiffyjr:

Take the following:

    $qb = $this->createQueryBuilder('a');
    $qb->select('partial a.{dsid,rid,activeStartDate}');
    $qb->leftJoin('a.clinic', 'c');
    $qb->leftJoin('a.patient', 'p');
    $qb->where('c.autoAppointmentReminders = 1');
    $qb->andWhere('a.enabled = 1');
    $qb->andWhere(
            $qb->expr()->eq(
                'a.activeStartDate',
                "DATE*ADD(CURRENT*DATE(), c.appointmentRemindersDaysInAdvance, 'day')"));

Which generates the DQL: SELECT partial a.{dsid,rid,activeStartDate} FROM VetLogic\Entity\Appointment a LEFT JOIN a.clinic c LEFT JOIN a.patient p WHERE c.autoAppointmentReminders = 1 AND a.enabled = 1 AND a.activeStartDate = DATEADD(CURRENTDATE(), c.appointmentRemindersDaysInAdvance, 'day')

And SQL: SELECT a0.rid AS rid0, a0_.dsid AS dsid1, a0_.activeStartDate AS activeStartDate2, a0_.dsid AS dsid3, a0_.dsid AS dsid4, a0_.clinicRid AS clinicRid5, a0_.dsid AS dsid6, a0_.patientRid AS patientRid7, a0_.dsid AS dsid8, a0_.rid AS rid9 FROM appointment a0_ LEFT JOIN clinic c1_ ON a0_.dsid = c1_.dsid AND a0_.clinicRid = c1_.rid LEFT JOIN patient p2_ ON a0_.dsid = p2_.dsid AND a0_.patientRid = p2_.rid WHERE c1_.autoAppointmentReminders = 1 AND a0_.enabled = 1 AND a0_.activeStartDate = DATE_ADD(CURRENTDATE, INTERVAL0 DAY)

The DATEADD(CURRENTDATE, INTERVAL0 DAY) is generated incorrectly because getDateAddDaysExpression($date, $days) casts $days to an integer.

The fix is simply to remove (int) from return 'DATE_ADD(' . $date . ', INTERVAL ' . (int)$days . ' DAY)';

Note: I only checked the MySQL platform so I'm not sure if other platforms are affected.

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment