From 39f98a8c5a0e67d30424ca199e0630b678bcecd5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 19 Jan 2022 15:32:56 +0100 Subject: [PATCH] Numeric/decimal data type is detected as FIELD_DECIMAL --- src/Database/Helpers.php | 5 +++-- src/Database/IStructure.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 4e8fa648d..12d0fc9ab 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -27,7 +27,8 @@ class Helpers public static array $typePatterns = [ '^_' => IStructure::FIELD_TEXT, // PostgreSQL arrays '(TINY|SMALL|SHORT|MEDIUM|BIG|LONG)(INT)?|INT(EGER|\d+| IDENTITY)?|(SMALL|BIG|)SERIAL\d*|COUNTER|YEAR|BYTE|LONGLONG|UNSIGNED BIG INT' => IStructure::FIELD_INTEGER, - '(NEW)?DEC(IMAL)?(\(.*)?|NUMERIC|REAL|DOUBLE( PRECISION)?|FLOAT\d*|(SMALL)?MONEY|CURRENCY|NUMBER' => IStructure::FIELD_FLOAT, + '(NEW)?DEC(IMAL)?(\(.*)?|NUMERIC|(SMALL)?MONEY|CURRENCY|NUMBER' => IStructure::FIELD_DECIMAL, + 'REAL|DOUBLE( PRECISION)?|FLOAT\d*' => IStructure::FIELD_FLOAT, 'BOOL(EAN)?' => IStructure::FIELD_BOOL, 'TIME' => IStructure::FIELD_TIME, 'DATE' => IStructure::FIELD_DATE, @@ -210,7 +211,7 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array } elseif ($type === IStructure::FIELD_INTEGER) { $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp; - } elseif ($type === IStructure::FIELD_FLOAT) { + } elseif ($type === IStructure::FIELD_FLOAT || $type === IStructure::FIELD_DECIMAL) { if (is_string($value) && ($pos = strpos($value, '.')) !== false) { $value = rtrim(rtrim($pos === 0 ? "0$value" : $value, '0'), '.'); } diff --git a/src/Database/IStructure.php b/src/Database/IStructure.php index d08db66b0..8c09e7497 100644 --- a/src/Database/IStructure.php +++ b/src/Database/IStructure.php @@ -21,6 +21,7 @@ interface IStructure FIELD_BOOL = 'bool', FIELD_INTEGER = 'int', FIELD_FLOAT = 'float', + FIELD_DECIMAL = 'decimal', FIELD_DATE = 'date', FIELD_TIME = 'time', FIELD_DATETIME = 'datetime',