mirror of
https://github.com/friendica/friendica
synced 2025-01-03 17:22:20 +00:00
Fixed for the string truncation for "latin1" charset
This commit is contained in:
parent
452cdadaa3
commit
d8bcf38a78
1 changed files with 9 additions and 1 deletions
|
@ -8,7 +8,9 @@
|
||||||
namespace Friendica\Database\Definition;
|
namespace Friendica\Database\Definition;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\DI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the whole database definition
|
* Stores the whole database definition
|
||||||
|
@ -65,12 +67,18 @@ class DbaDefinition
|
||||||
|
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
|
||||||
|
$charset = DI::config()->get('database', 'charset') ?? '';
|
||||||
|
|
||||||
// Assign all field that are present in the table
|
// Assign all field that are present in the table
|
||||||
foreach ($fieldNames as $field) {
|
foreach ($fieldNames as $field) {
|
||||||
if (isset($data[$field])) {
|
if (isset($data[$field])) {
|
||||||
// Limit the length of varchar, varbinary, char and binary fields
|
// 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)) {
|
if (is_string($data[$field]) && preg_match("/char\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
||||||
|
if ($charset == 'latin1') {
|
||||||
|
$data[$field] = substr($data[$field], 0, $result[1]);
|
||||||
|
} else {
|
||||||
$data[$field] = mb_substr($data[$field], 0, $result[1]);
|
$data[$field] = mb_substr($data[$field], 0, $result[1]);
|
||||||
|
}
|
||||||
} elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
} elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
||||||
$data[$field] = substr($data[$field], 0, $result[1]);
|
$data[$field] = substr($data[$field], 0, $result[1]);
|
||||||
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') {
|
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') {
|
||||||
|
|
Loading…
Reference in a new issue