Skip to content

Commit be77d4f

Browse files
committed
Fix pdo type of column type NUMERIC
1 parent 3a8ff53 commit be77d4f

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

src/Propel/Generator/Model/PropelTypes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class PropelTypes
482482
self::LONGVARCHAR => PDO::PARAM_STR,
483483
self::CLOB => PDO::PARAM_STR,
484484
self::CLOB_EMU => PDO::PARAM_STR,
485-
self::NUMERIC => PDO::PARAM_INT,
485+
self::NUMERIC => PDO::PARAM_STR,
486486
self::DECIMAL => PDO::PARAM_STR,
487487
self::TINYINT => PDO::PARAM_INT,
488488
self::SMALLINT => PDO::PARAM_INT,

tests/Fixtures/bookstore/schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<column name="job_title" type="VARCHAR" size="32" description="Employee job title"/>
166166
<column name="supervisor_id" type="INTEGER" description="Fkey to supervisor."/>
167167
<column name="photo" type="BLOB" lazyLoad="true"/>
168+
<column name="salary" type="NUMERIC" size="12" scale="2"/>
168169
<foreign-key foreignTable="bookstore_employee" phpName="Supervisor" refPhpName="Subordinate" onDelete="setnull">
169170
<reference local="supervisor_id" foreign="id"/>
170171
</foreign-key>

tests/Fixtures/bookstore/types-schema.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
</foreign-key>
1515
</table>
1616

17+
<table name="type_numeric" identifierQuoting="true">
18+
<column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/>
19+
<column name="numeric" type="NUMERIC" size="12" scale="4"/>
20+
<column name="decimal" type="DECIMAL" size="12" scale="4"/>
21+
</table>
22+
1723
</database>

tests/Propel/Tests/Generator/Model/ColumnTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public static function providePdoTypes()
451451
['LONGVARCHAR', PDO::PARAM_STR],
452452
['CLOB', PDO::PARAM_STR],
453453
['CLOB_EMU', PDO::PARAM_STR],
454-
['NUMERIC', PDO::PARAM_INT],
454+
['NUMERIC', PDO::PARAM_STR],
455455
['DECIMAL', PDO::PARAM_STR],
456456
['TINYINT', PDO::PARAM_INT],
457457
['SMALLINT', PDO::PARAM_INT],

tests/Propel/Tests/Runtime/ActiveQuery/ModelCriteriaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ public function testJoinAliasQuery()
11261126
$c->join('sup.Subordinate sub');
11271127
$c->where('sub.Name = ?', 'Foo');
11281128
$employees = BookstoreEmployeeQuery::create(null, $c)->find($con);
1129-
$expectedSQL = $this->getSql("SELECT bookstore_employee.id, bookstore_employee.class_key, bookstore_employee.name, bookstore_employee.job_title, bookstore_employee.supervisor_id FROM bookstore_employee INNER JOIN bookstore_employee sup ON (bookstore_employee.supervisor_id=sup.id) INNER JOIN bookstore_employee sub ON (sup.id=sub.supervisor_id) WHERE sub.name = 'Foo'");
1129+
$expectedSQL = $this->getSql("SELECT bookstore_employee.id, bookstore_employee.class_key, bookstore_employee.name, bookstore_employee.job_title, bookstore_employee.supervisor_id, bookstore_employee.salary FROM bookstore_employee INNER JOIN bookstore_employee sup ON (bookstore_employee.supervisor_id=sup.id) INNER JOIN bookstore_employee sub ON (sup.id=sub.supervisor_id) WHERE sub.name = 'Foo'");
11301130
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'join() allows the use of relation alias in further joins()');
11311131
}
11321132

tests/Propel/Tests/Runtime/TypeTests/TypeTest.php

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88

99
namespace Propel\Tests\Runtime\TypeTests;
1010

11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use Propel\Tests\Bookstore\Map\TypeObjectTableMap;
13+
use Propel\Tests\Bookstore\TypeNumeric;
14+
use Propel\Tests\Bookstore\TypeNumericQuery;
1215
use Propel\Tests\Bookstore\TypeObject;
1316
use Propel\Tests\Bookstore\TypeObjectQuery;
1417
use Propel\Tests\Helpers\Bookstore\BookstoreTestBase;
1518
use Propel\Tests\Runtime\TypeTests\DummyObjectClass;
16-
use Propel\Tests\Runtime\TypeTests\TypeObjectInterface;
1719
use ReflectionClass;
1820

1921
/**
22+
* NOTE: Uses classes from bookstore/types-schema.xml.
23+
*
2024
* @group database
2125
*/
2226
class TypeTest extends BookstoreTestBase
2327
{
28+
public static function setUpBeforeClass(): void
29+
{
30+
parent::setUpBeforeClass();
31+
TypeNumericQuery::create()->deleteAll();
32+
}
33+
2434
/**
2535
* @return void
2636
*/
@@ -47,20 +57,6 @@ public function testTypeHintArray()
4757
$this->assertTrue($param->allowsNull());
4858
}
4959

50-
/**
51-
* @return void
52-
*/
53-
public function testInterface()
54-
{
55-
$this->markTestSkipped('Setting interface on fk-relations was removed');
56-
$reflection = new ReflectionClass(TypeObject::class);
57-
$method = $reflection->getMethod('setTypeObject');
58-
$param = $method->getParameters()[0];
59-
60-
$this->assertEquals(TypeObjectInterface::class, $param->getType()->getName());
61-
$this->assertTrue($param->allowsNull());
62-
}
63-
6460
/**
6561
* @return void
6662
*/
@@ -128,4 +124,34 @@ public function testObjectType()
128124

129125
$this->assertEquals($q, $typeObjectEntity->getDetails());
130126
}
127+
128+
public static function DecimalValuesDataProvider(): array
129+
{
130+
$values = [ // string $inputValue, string $storedValue
131+
['12345.333', '12345.3330'],
132+
['12345', '12345.0000'],
133+
];
134+
135+
return [ // string $columnName, string $inputValue, string $storedValue
136+
...array_map(fn ($dataSet) => ['Decimal', ...$dataSet], $values),
137+
...array_map(fn ($dataSet) => ['Numeric', ...$dataSet], $values),
138+
];
139+
}
140+
141+
#[DataProvider('DecimalValuesDataProvider')]
142+
public function testDecimalType(string $columnName, string $inputValue, string $storedValue): void
143+
{
144+
if (static::runningOnSQLite()) {
145+
$this->markTestSkipped('Sqlite stores decimals as strings.');
146+
}
147+
148+
$o = new TypeNumeric();
149+
$o->setByName($columnName, $inputValue)->save();
150+
151+
$o->reload();
152+
$this->assertSame($storedValue, $o->getByName($columnName));
153+
154+
$foundValue = TypeNumericQuery::create()->filterBy($columnName, $storedValue)->findOne();
155+
$this->assertSame($o, $foundValue);
156+
}
131157
}

0 commit comments

Comments
 (0)