From 50cf8c9ae6befde19144f7f7fea4872587674031 Mon Sep 17 00:00:00 2001 From: guidocella Date: Mon, 2 Jan 2017 14:01:37 +0100 Subject: [PATCH] Prevent exceptions with decimal columns --- src/ColumnTypeGuesser.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ColumnTypeGuesser.php b/src/ColumnTypeGuesser.php index 1469b48..0612c6b 100644 --- a/src/ColumnTypeGuesser.php +++ b/src/ColumnTypeGuesser.php @@ -44,8 +44,17 @@ public function guessFormat(Column $column, $tableName) $maxDigits = $column->getPrecision(); $maxDecimalDigits = $column->getScale(); - return function () use ($maxDigits, $maxDecimalDigits) { - return $this->generator->randomFloat($maxDecimalDigits, 0, 10 ** ($maxDigits - $maxDecimalDigits)); + $max = 10 ** ($maxDigits - $maxDecimalDigits); + + return function () use ($maxDecimalDigits, $max) { + $value = $this->generator->randomFloat($maxDecimalDigits, 0, $max); + + // Prevents "Numeric value out of range" exceptions. + if ($value == $max) { + return $max - (1 / $maxDecimalDigits); + } + + return $value; }; case 'smallint': return function () {