Skip to content

Commit e6fe986

Browse files
authored
Throw exception on "unsigned" column usage (#378)
1 parent 3226fd8 commit e6fe986

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- Chg #365: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov)
6464
- Enh #359: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin)
6565
- Enh #373: Adapt to `DQLQueryBuilderInterface::buildWithQueries()` signature changes in `yiisoft/db` package (@vjik)
66+
- Chg #378: Throw exception on "unsigned" column usage (@vjik)
6667

6768
## 1.3.0 March 21, 2024
6869

src/Column/ColumnDefinitionBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Yiisoft\Db\Constant\ColumnType;
88
use Yiisoft\Db\Constant\ReferentialAction;
9+
use Yiisoft\Db\Exception\NotSupportedException;
910
use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder;
1011
use Yiisoft\Db\Schema\Column\ColumnInterface;
1112

@@ -38,6 +39,10 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder
3839

3940
public function build(ColumnInterface $column): string
4041
{
42+
if ($column->isUnsigned()) {
43+
throw new NotSupportedException('The "unsigned" attribute is not supported by Oracle.');
44+
}
45+
4146
return $this->buildType($column)
4247
. $this->buildAutoIncrement($column)
4348
. $this->buildDefault($column)

src/Column/ColumnFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ final class ColumnFactory extends AbstractColumnFactory
5454
];
5555
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";
5656

57+
public function fromPseudoType(string $pseudoType, array $info = []): ColumnInterface
58+
{
59+
return parent::fromPseudoType($pseudoType, $info)->unsigned(false);
60+
}
61+
5762
protected function columnDefinitionParser(): ColumnDefinitionParser
5863
{
5964
return new ColumnDefinitionParser();

tests/Provider/ColumnFactoryProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919
final class ColumnFactoryProvider extends \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider
2020
{
21+
public static function pseudoTypes(): array
22+
{
23+
$values = parent::pseudoTypes();
24+
25+
// Oracle doesn't support unsigned types
26+
$values['upk'][1] = new IntegerColumn(primaryKey: true, autoIncrement: true, unsigned: false);
27+
$values['ubigpk'][1] = new BigIntColumn(primaryKey: true, autoIncrement: true, unsigned: false);
28+
29+
return $values;
30+
}
31+
2132
public static function dbTypes(): array
2233
{
2334
return [

tests/Provider/QueryBuilderProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ public static function buildColumnDefinition(): array
287287

288288
$values = parent::buildColumnDefinition();
289289

290+
// Oracle does not support unsigned types
291+
unset(
292+
$values['bigint(15) unsigned'],
293+
$values['unsigned()'],
294+
);
295+
290296
$values[PseudoType::PK][0] = 'number(10) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
291297
$values[PseudoType::UPK][0] = 'number(10) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
292298
$values[PseudoType::BIGPK][0] = 'number(20) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
@@ -375,7 +381,6 @@ public static function buildColumnDefinition(): array
375381
$values["integer()->defaultValue('')"][0] = 'number(10) DEFAULT NULL';
376382
$values['size(10)'][0] = 'varchar2(10)';
377383
$values['unique()'][0] = 'varchar2(255) UNIQUE';
378-
$values['unsigned()'][0] = 'number(10)';
379384
$values['scale(2)'][0] = 'number(10,2)';
380385
$values['integer(8)->scale(2)'][0] = 'number(8)';
381386
$values['reference($reference)'][0] = 'number(10) REFERENCES "ref_table" ("id") ON DELETE SET NULL';

0 commit comments

Comments
 (0)