Fixed for the string truncation for "latin1" charset

This commit is contained in:
Michael 2024-10-07 05:26:51 +00:00
parent 452cdadaa3
commit d8bcf38a78

View file

@ -8,7 +8,9 @@
namespace Friendica\Database\Definition;
use Exception;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\DI;
/**
* Stores the whole database definition
@ -65,12 +67,18 @@ class DbaDefinition
$fields = [];
$charset = DI::config()->get('database', 'charset') ?? '';
// Assign all field that are present in the table
foreach ($fieldNames as $field) {
if (isset($data[$field])) {
// Limit the length of varchar, varbinary, char and binary fields
if (is_string($data[$field]) && preg_match("/char\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
$data[$field] = mb_substr($data[$field], 0, $result[1]);
if ($charset == 'latin1') {
$data[$field] = substr($data[$field], 0, $result[1]);
} else {
$data[$field] = mb_substr($data[$field], 0, $result[1]);
}
} elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
$data[$field] = substr($data[$field], 0, $result[1]);
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') {