Skip to content

Commit

Permalink
Merge pull request #704 from auss/patch-1
Browse files Browse the repository at this point in the history
Fixed issue with migrations and decimal or numeric table size
  • Loading branch information
willdurand committed Jun 13, 2013
2 parents 9c19ce6 + e7ecc97 commit 5886ff7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions generator/lib/reverse/pgsql/PgsqlSchemaParser.php
Expand Up @@ -284,8 +284,8 @@ private function processLengthScale($intTypmod, $strName)
return $arrRetVal;
} // if ($intTypmod == -1)

// Numeric Datatype?
if ($strName == $this->getMappedNativeType(PropelTypes::NUMERIC)) {
// Decimal Datatype?
if ($strName == $this->getMappedNativeType(PropelTypes::DECIMAL)) {
$intLen = ($intTypmod - 4) >> 16;
$intPrec = ($intTypmod - 4) & 0xffff;
$intLen = sprintf("%ld", $intLen);
Expand Down
12 changes: 8 additions & 4 deletions test/testsuite/generator/reverse/pgsql/PgsqlSchemaParserTest.php
Expand Up @@ -59,16 +59,18 @@ protected function tearDown()
public function parseDataProvider()
{
return array(
// columnDDL, expectedColumnPhpName, expectedColumnDefaultType, expectedColumnDefaultValue
array("my_column varchar(20) default null", "MyColumn", ColumnDefaultValue::TYPE_VALUE, "NULL"),
array("my_column varchar(20) default ''", "MyColumn", ColumnDefaultValue::TYPE_VALUE, ""),
// columnDDL, expectedColumnPhpName, expectedColumnDefaultType, expectedColumnDefaultValue, expectedSize, expectedScale
array("my_column varchar(20) default null", "MyColumn", ColumnDefaultValue::TYPE_VALUE, "NULL", 20, null),
array("my_column varchar(20) default ''", "MyColumn", ColumnDefaultValue::TYPE_VALUE, "", 20, null),
array("my_column numeric(11,0) default 0", "MyColumn", ColumnDefaultValue::TYPE_VALUE, 0, 11, 0),
array("my_column numeric(55,8) default 0", "MyColumn", ColumnDefaultValue::TYPE_VALUE, 0, 55, 8),
);
}

/**
* @dataProvider parseDataProvider
*/
public function testParse($columnDDL, $expectedColumnPhpName, $expectedColumnDefaultType, $expectedColumnDefaultValue)
public function testParse($columnDDL, $expectedColumnPhpName, $expectedColumnDefaultType, $expectedColumnDefaultValue, $expectedSize, $expectedScale)
{
$this->con->query("create table foo ( {$columnDDL} );");
$parser = new PgsqlSchemaParser($this->con);
Expand All @@ -90,6 +92,8 @@ public function testParse($columnDDL, $expectedColumnPhpName, $expectedColumnDef
$this->assertEquals($expectedColumnPhpName, $columns[0]->getPhpName());
$this->assertEquals($expectedColumnDefaultType, $defaultValue->getType());
$this->assertEquals($expectedColumnDefaultValue, $defaultValue->getValue());
$this->assertEquals($expectedSize, $columns[0]->getSize());
$this->assertEquals($expectedScale, $columns[0]->getScale());
}
}

Expand Down

0 comments on commit 5886ff7

Please sign in to comment.