Skip to content

Commit

Permalink
Prevent exceptions with decimal columns
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella committed Jan 2, 2017
1 parent ff035ec commit 50cf8c9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ColumnTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 50cf8c9

Please sign in to comment.