Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions Sources/Db/APIs/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,40 @@ protected function replacement__callback(array $matches, array $db_values, objec

break;

case 'array_uuid':
if (\is_array($replacement)) {
if (empty($replacement)) {
$this->error_backtrace('Database error, given array of UUID values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
}

foreach ($replacement as $key => $value) {
if ($value instanceof Uuid) {
$replacement[$key] = \sprintf('UUID_TO_BIN(\'%1$s\')', (string) $value);
continue;
}

$uuid = @Uuid::createFromString($value, false);

if (
str_replace(['{', '-', '}'], '', strtolower($value)) === str_replace('-', '', (string) $uuid)
|| $value === $uuid->getBinary()
|| $value === $uuid->getShortForm(false)
|| $value === $uuid->getShortForm(true)
) {
$replacement[$key] = \sprintf('UUID_TO_BIN(\'%1$s\')', (string) $uuid);
continue;
}

$this->error_backtrace('Wrong value type sent to the database. Array of UUIDs expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
}

return implode(', ', $replacement);
}

$this->error_backtrace('Wrong value type sent to the database. Array of UUIDs expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);

break;

case 'date':
if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
return \sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
Expand Down Expand Up @@ -2778,12 +2812,17 @@ protected function replacement__callback(array $matches, array $db_values, objec

case 'uuid':
if ($replacement instanceof Uuid) {
return \sprintf('UUID_TO_BIN(\'%1$s\')', \strval($replacement));
return \sprintf('UUID_TO_BIN(\'%1$s\')', (string) $replacement);
}

$uuid = @Uuid::createFromString($replacement, false);

if (\in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) {
if (
str_replace(['{', '-', '}'], '', strtolower($replacement)) === str_replace('-', '', (string) $uuid)
|| $replacement === $uuid->getBinary()
|| $replacement === $uuid->getShortForm(false)
|| $replacement === $uuid->getShortForm(true)
) {
return \sprintf('UUID_TO_BIN(\'%1$s\')', (string) $uuid);
}

Expand Down
41 changes: 40 additions & 1 deletion Sources/Db/APIs/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,40 @@ protected function replacement__callback(array $matches, array $db_values, objec

break;

case 'array_uuid':
if (\is_array($replacement)) {
if (empty($replacement)) {
$this->error_backtrace('Database error, given array of UUID values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
}

foreach ($replacement as $key => $value) {
if ($value instanceof Uuid) {
$replacement[$key] = \sprintf('\'%1$s\'::uuid', (string) $value);
continue;
}

$uuid = @Uuid::createFromString($value, false);

if (
str_replace(['{', '-', '}'], '', strtolower($value)) === str_replace('-', '', (string) $uuid)
|| $value === $uuid->getBinary()
|| $value === $uuid->getShortForm(false)
|| $value === $uuid->getShortForm(true)
) {
$replacement[$key] = \sprintf('\'%1$s\'::uuid', (string) $uuid);
continue;
}

$this->error_backtrace('Wrong value type sent to the database. UUID expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
}

return implode(', ', $replacement);
}

$this->error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);

break;

case 'date':
if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
return \sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date';
Expand Down Expand Up @@ -2675,7 +2709,12 @@ protected function replacement__callback(array $matches, array $db_values, objec

$uuid = @Uuid::createFromString($replacement, false);

if (\in_array($replacement, [(string) $uuid, $uuid->getShortForm(), $uuid->getBinary()])) {
if (
str_replace(['{', '-', '}'], '', strtolower($replacement)) === str_replace('-', '', (string) $uuid)
|| $replacement === $uuid->getBinary()
|| $replacement === $uuid->getShortForm(false)
|| $replacement === $uuid->getShortForm(true)
) {
return \sprintf('\'%1$s\'::uuid', (string) $uuid);
}

Expand Down
Loading