Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- Chg #339: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
- New #342, #430: Add JSON overlaps condition builder (@Tigrov)
- Enh #344: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov)
- New #346, #361: Implement `ColumnFactory` class (@Tigrov)
- New #346, #361, #454: Implement `ColumnFactory` class (@Tigrov, @vjik)
- Enh #347, #353: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov)
- Bug #349, #352: Restore connection if closed by connection timeout (@Tigrov)
- Enh #354: Separate column type constants (@Tigrov)
Expand Down
1 change: 1 addition & 0 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function getColumnClass(string $type, array $info = []): string
ColumnType::TIME => DateTimeColumn::class,
ColumnType::TIMETZ => DateTimeColumn::class,
ColumnType::DATE => DateTimeColumn::class,
ColumnType::DECIMAL => StringColumn::class,
default => parent::getColumnClass($type, $info),
};
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testSelectWithPhpTypecasting(): void
$expected = [
'null' => null,
1 => 1,
'2.5' => 2.5,
'2.5' => '2.5',
'true' => 1,
'false' => 0,
'string' => 'string',
Expand Down Expand Up @@ -78,13 +78,13 @@ public function testSelectWithPhpTypecasting(): void
->withPhpTypecasting()
->queryScalar();

$this->assertSame(2.5, $result);
$this->assertSame('2.5', $result);

$result = $db->createCommand('SELECT 2.5 UNION SELECT 3.3')
->withPhpTypecasting()
->queryColumn();

$this->assertSame([2.5, 3.3], $result);
$this->assertSame(['2.5', '3.3'], $result);

$db->close();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static function dbTypes(): array
['float', ColumnType::FLOAT, DoubleColumn::class],
['real', ColumnType::FLOAT, DoubleColumn::class],
['double', ColumnType::DOUBLE, DoubleColumn::class],
['decimal', ColumnType::DECIMAL, DoubleColumn::class],
['numeric', ColumnType::DECIMAL, DoubleColumn::class],
['decimal', ColumnType::DECIMAL, StringColumn::class],
['numeric', ColumnType::DECIMAL, StringColumn::class],
['char', ColumnType::CHAR, StringColumn::class],
['varchar', ColumnType::STRING, StringColumn::class],
['string', ColumnType::STRING, StringColumn::class],
Expand Down Expand Up @@ -63,7 +63,7 @@ public static function definitions(): array
$definitions['text NOT NULL'][1] = new StringColumn(ColumnType::TEXT, dbType: 'text', notNull: true);
$definitions['char(1)'][1] = new StringColumn(ColumnType::CHAR, dbType: 'char', size: 1);
$definitions['string(126)[][]'][1] = new ArrayColumn(size: 126, dimension: 2, column: new StringColumn(size: 126));

$definitions['decimal(10,2)'][1] = new StringColumn(ColumnType::DECIMAL, dbType: 'decimal', scale: 2, size: 10);
$definitions[] = ['bit(1)', new BooleanColumn(dbType: 'bit', size: 1)];

return $definitions;
Expand Down
4 changes: 2 additions & 2 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public static function upsertReturning(): array
true,
['id_1', 'id_2'],
'INSERT INTO `notauto_pk` (`id_1`, `id_2`, `type`) SELECT `id_1`, `id_2`, `type`'
. ' FROM (SELECT 1 AS `id_1`, 2.5 AS `id_2`, :qp0 AS `type`) AS EXCLUDED'
. ' FROM (SELECT 1 AS `id_1`, :qp0 AS `id_2`, :qp1 AS `type`) AS EXCLUDED'
. ' ON DUPLICATE KEY UPDATE `type`=EXCLUDED.`type`;SELECT 1 AS `id_1`, 2.5 AS `id_2`',
[':qp0' => new Param('Test', DataType::STRING)],
[':qp0' => new Param('2.5', DataType::STRING), ':qp1' => new Param('Test', DataType::STRING)],
],
'no return columns' => [
'type',
Expand Down
10 changes: 5 additions & 5 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public static function columns(): array
'blob_col' => new BinaryColumn(
dbType: 'blob',
),
'numeric_col' => new DoubleColumn(
'numeric_col' => new StringColumn(
ColumnType::DECIMAL,
dbType: 'decimal',
size: 5,
scale: 2,
defaultValue: 33.22,
size: 5,
defaultValue: '33.22',
),
'timestamp_col' => new DateTimeColumn(
ColumnType::TIMESTAMP,
Expand Down Expand Up @@ -358,7 +358,7 @@ public static function resultColumns(): array
'len' => 4,
'precision' => 3,
]],
[new DoubleColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'numeric_col', notNull: false, size: 5, scale: 2), [
[new StringColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'numeric_col', notNull: false, scale: 2, size: 5), [
'native_type' => 'NEWDECIMAL',
'pdo_type' => 2,
'flags' => [],
Expand Down Expand Up @@ -412,7 +412,7 @@ public static function resultColumns(): array
'len' => 1,
'precision' => 0,
]],
[new DoubleColumn(ColumnType::DECIMAL, dbType: 'decimal', name: '2.5', notNull: true, size: 2, scale: 1), [
[new StringColumn(ColumnType::DECIMAL, dbType: 'decimal', name: '2.5', notNull: true, scale: 1, size: 2), [
'native_type' => 'NEWDECIMAL',
'pdo_type' => 2,
'flags' => ['not_null'],
Expand Down
Loading