We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Howdy,
    I was working away with revision 122 and decided to update it earlier tonight to revision 131 because there had been several interesting-looking changes.
    I just found one thing that caused a bug in my application.
    I have a users object, and I was setting some datetime fields to NULL (db schema allows NULL)
    $User->set('date_approved', NULL);
    ...
    $User->save();
    

    I now get an error when I save, whereas I did not before.
    I traced through the code and found that in pdo.class.php, when the execute method is replacing bound parameters, it was just replacing the parameter with an empty string, where I would have expected NULL. So the SQL statement had this " ’stuff’, ’thing’, , ,’’) " kinda problem.
    I haven’t taken the time to understand exactly what this method is doing, but I added one line, $v= NULL, as shown here:
    if (!$v) {
      switch ($type) {
        case PDO_PARAM_INT:
          $v= '0';
          break;
        case PDO_PARAM_BOOL:
          $v= '0';
          break;
        default:
          $v= 'NULL';
          break;
      }
    }
    

    This has solved my problem, but I don’t know if it is the proper fix. I’m not sure about what that "if(!$v)" test is trying to do; maybe the change should be up there instead?
      Mike Schell
      Lead Developer, MODX Cloud
      Email: [email protected]
      GitHub: https://github.com/netProphET/
      Twitter: @mkschell
    • Seems you updated right in the middle of me checking in fixes for the NULL problem already. Last week, I had addressed being able to insert NULL values into dates, which was broken previously, and ended up creating some wierd issues that were very hard to track down depending on which version of PHP I was testing. I was spending most of the night last night addressing this, and I believe I found the problem, so try updating again, at least to 135.

      BTW, in your schema for the datetime field, do you have just null="true" or do you also have default="NULL"? If you do have default="NULL", can you also try it without default="NULL" and see if you get different results?
      • OpenGeek,
        I’m out the door in about an hour for the weekend. I’ll check that out on Sunday night or Monday if it’s not too late.
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell