Skip to content

Commit

Permalink
Numeric/decimal data type is FIELD_FIXED (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 20, 2022
1 parent f8280d6 commit b99855a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Database/Helpers.php
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_FIXED,
'REAL|DOUBLE( PRECISION)?|FLOAT\d*' => IStructure::FIELD_FLOAT,
'BOOL(EAN)?' => IStructure::FIELD_BOOL,
'TIME' => IStructure::FIELD_TIME,
'DATE' => IStructure::FIELD_DATE,
Expand Down
1 change: 1 addition & 0 deletions src/Database/IStructure.php
Expand Up @@ -21,6 +21,7 @@ interface IStructure
FIELD_BOOL = 'bool',
FIELD_INTEGER = 'int',
FIELD_FLOAT = 'float',
FIELD_FIXED = 'fixed',
FIELD_DATE = 'date',
FIELD_TIME = 'time',
FIELD_DATETIME = 'datetime',
Expand Down
1 change: 1 addition & 0 deletions src/Database/RowNormalizer.php
Expand Up @@ -40,6 +40,7 @@ public function normalizeField(mixed $value, string $type): mixed
return is_float($tmp = $value * 1) ? $value : $tmp;

case IStructure::FIELD_FLOAT:
case IStructure::FIELD_FIXED:
if (is_string($value) && ($pos = strpos($value, '.')) !== false) {
$value = rtrim(rtrim($pos === 0 ? "0$value" : $value, '0'), '.');
}
Expand Down

0 comments on commit b99855a

Please sign in to comment.