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

Open
opened 2026-01-22 13:19:55 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 20, 2011).

Originally assigned to: @beberlei on GitHub.

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 = DATE_ADD(CURRENT_DATE(), 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(CURRENT_DATE, INTERVAL0 DAY)

The DATE_ADD(CURRENT_DATE, 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.

Originally created by @doctrinebot on GitHub (Jul 20, 2011). Originally assigned to: @beberlei on GitHub. 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 = DATE_ADD(CURRENT_DATE(), 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(CURRENT_DATE, INTERVAL0 DAY) The DATE_ADD(CURRENT_DATE, 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.
admin added the Bug label 2026-01-22 13:19:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1612