Skip to content

Commit

Permalink
Numeric/decimal data type is detected as FIELD_DECIMAL
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 14, 2023
1 parent 20dabde commit 39f98a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'), '.');
}
Expand Down
1 change: 1 addition & 0 deletions src/Database/IStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 39f98a8

Please sign in to comment.