Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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

chanhchanh - 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?


  • Options
    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.

  • Options
    chanhchanh - 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?


  • Options
    ShadowdareShadowdare r_j MVP
    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

  • Options
    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:

  • Options
    chanhchanh - CMS Researcher ✭✭

    Sound good! Thanks

Sign In or Register to comment.