Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL error with strict mode if message too long #3170

Closed
effone opened this issue Apr 28, 2018 · 0 comments · Fixed by #3236
Closed

MySQL error with strict mode if message too long #3170

effone opened this issue Apr 28, 2018 · 0 comments · Fixed by #3236
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Milestone

Comments

@effone
Copy link
Member

effone commented Apr 28, 2018

If the message is longer than the limit of the message field in the database, with MySQL strict mode enabled it throws an error instead of cutting the message after the limit.

Code:SQL Error:
1406 - Data too long for column 'message' at row 1
To avoid this error in our forum, I added in function verify_message() in inc/datahandlers/post.php below

PHP Code:// If this board has a maximum message length check if we're over it. Use strlen because SQL limits are in byteselse if(strlen($post['message']) > $mybb->settings['maxmessagelength'] && $mybb->settings['maxmessagelength'] > 0 && !is_moderator($post['fid'], "", $post['uid'])){    $this->set_error("message_too_long", array($mybb->settings['maxmessagelength'], strlen($post['message'])));    return false;} 
a check:

PHP Code:// If the message length is over SQL limitselse if(strlen($post['message']) > 65535){    global $db;    $fieldlength = $db->show_fields_from("posts");    if(is_array($fieldlength))    {        foreach ($fieldlength as $key => $fields)        {            if($fields['Field'] == 'message')            {                switch($fields['Type'])                {                    case 'text':                    {                        $maximum = 65535;                    }                    break;                    case 'mediumtext':                    {                        $maximum = 16777215;                    }                    break;                    case 'longtext':                    {                        $maximum = 4294967295;                    }                    break;                    default:                        $maximum = 65535;                }            }        }    }    if(isset($maximum) && strlen($post['message']) > $maximum)    {        $this->set_error("message_too_long", array($maximum, strlen($post['message'])));        return false;    }} 

Original thread: MySQL error with strict mode if message too long

@effone effone added b:1.8 Branch: 1.8.x t:bug Type: Bug. An issue causing error / flaw / malfunction s:confirmed Status: Confirmed. Retested and found the issue exists labels Apr 28, 2018
@effone effone added s:resolved Status: Resolved. Solution implemented or scheduled and removed s:confirmed Status: Confirmed. Retested and found the issue exists labels Jun 3, 2018
@effone effone added this to the 1.8.16 milestone Jun 3, 2018
Shade- pushed a commit that referenced this issue Jun 8, 2018
* sql-textfield-lengthlimit

* error message revision
euantorano pushed a commit that referenced this issue Jun 27, 2018
…ed (#3286)

* message length dblimit

* comments

* Logic update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:1.8 Branch: 1.8.x s:resolved Status: Resolved. Solution implemented or scheduled t:bug Type: Bug. An issue causing error / flaw / malfunction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant