Doctrine 1
  1. Doctrine 1
  2. DC-398

PORTABILITY_EMPTY_TO_NULL doesn't do anything for statements

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.14, 1.1.6, 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: Connection
    • Labels:
      None

      Description

      I found this ticket on the old Trac system, but not on JIRA. It is still broken in the 1.1 branch, as of revision 7004. It is also broken in 1.0.14, 1.1.6, and 1.2.1. (These were the 'stable' releases at the time I reported this bug.) It is likely broken in older releases as well.

      When saving to the database, Doctrine ignores the setting of PORTABILITY_EMPTY_TO_NULL. Currently, it will never change empty strings to NULL, no matter what the setting is for ATRR_PORTABILITY. This is because there is an error in the following 'if' statement:

      Doctrine_Connection_Statement starting on line: 234

      if ($this->_conn->getAttribute(Doctrine::PORTABILITY_EMPTY_TO_NULL)) {
          foreach ($params as $key => $value) {
              if ($value == '') {
                  $params[$key] = null;
              }
          }
      }
      

      the first test in this block should be (Portability Mode Attributes must be handled this way):

      if ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL) {
      

      the second test should be:

      if (is_string($value) && $value === '')
      

      In newer versions of php(not sure which), test for empty string must look like '===' not only '=='. It prevents integer and boolean value 0 to be handled as an empty string.

      1. patch.diff
        0.8 kB
        Thomas Albright

        Activity

        Hide
        Dorian added a comment -

        It's the same problem with.

        $oDCon->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_RTRIM);

        I think Doctrine::ATTR_ don't work.

        Show
        Dorian added a comment - It's the same problem with. $oDCon->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_RTRIM); I think Doctrine::ATTR_ don't work.
        Hide
        Erin Millard added a comment -

        It would be really great to see this issue fixed. As for the suggested changes above, I believe the === operator checks against type also, and therefore the is_string() call is redundant.

        Show
        Erin Millard added a comment - It would be really great to see this issue fixed. As for the suggested changes above, I believe the === operator checks against type also, and therefore the is_string() call is redundant.
        Hide
        Thomas Albright added a comment -

        Here is a patch for 1.2.1.

        Show
        Thomas Albright added a comment - Here is a patch for 1.2.1.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Thomas Albright
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: