Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6.1 is here with critical security patches. One of them has been publicly disclosed.
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

It hit the bonk screen everytime click on "save" when run in Mysql strict mode

This discussion is related to the Basic Pages addon.
chanhchanh OngETC.com - CMS Researcher ✭✭

This is the screen I got every time I click on "save" when run in Mysql strict mode.

Something has gone wrong.

We've run into a problem and are unable to handle this request right now.
Please check back in a little while.

I suspect due to this value here but not sure how to go about fixing it.
->Column('RawBody', 'tinyint(1)', 0)
->Column('SiteMenuLink', 'tinyint(1)', 0)

This set the colume to "NOT NULL" and have a default value of '0' but in the code whenever it "save" a page, this two fields are blank when it is not click on the check box thus cause a "bonk"

What do you think?

Comments

  • businessdadbusinessdad Stealth contributor MVP

    As far as I know, Vanilla doesn't work very well with MySQL in strict mode (see previous discussion).

    Surely there must be a way to fix it, but I suspect that it will require a good deal of fiddling with the core files, which may not always be a good idea as changes would get lost when updates are applied.

  • chanhchanh OngETC.com - CMS Researcher ✭✭

    I added these line before the "Save" and it seems to work with MySql strict mode.

         if($FormValues['RawBody'] == '') 
             $FormValues['RawBody'] = '0';             
         if($FormValues['SiteMenuLink'] == '') 
             $FormValues['SiteMenuLink'] = '0';             
            $PageID = $this->PageModel->Save($FormValues);
    

    What do you think about these fixes?

    Thanks

  • ShadowdareShadowdare π Moderator
    edited March 2014

    The fixes look okay and I might add it in a future release. Thanks!


    MySQL strict mode expects data to match up with each column's data type, so using strict mode introduces some advantages, but it depends on the application.

    Presume that a column expects an integral data type and a program wants to pass in a 1. You should pass in the actual integer 1 instead of the string '1'. Also, MySQL does not have a real boolean data type dealing with values of false and true, so if you pass in the PHP boolean value true in a SQL query, the PHP database driver being used or MySQL probably has a procedure coded in to automatically convert it to 1. I do not recall if strict mode would show a warning about these kinds of things.

    After all, some PHP programs do not work well with MySQL in strict mode because PHP is a dynamically typed language. Automatic casts to types programmers do not expect happen a lot.

    Add Pages to Vanilla with the Basic Pages app | Publish articles with the Articles app

  • businessdadbusinessdad Stealth contributor MVP
    edited March 2014

    Or you can just typecast:

    $FormValues['RawBody'] = (int)$FormValues['RawBody'];
    $FormValues['SiteMenuLink'] = (int)$FormValues['SiteMenuLink'];
    

    Avoiding an ugly chain of if statements. :smile:

    ShadowdareR_JUnderDog
  • chanhchanh OngETC.com - CMS Researcher ✭✭

    Sound good! Thanks

Sign In or Register to comment.