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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- Chg #365: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov)
- Enh #359: Update `DMLQueryBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin)
- Enh #373: Adapt to `DQLQueryBuilderInterface::buildWithQueries()` signature changes in `yiisoft/db` package (@vjik)
- Chg #378: Throw exception on "unsigned" column usage (@vjik)

## 1.3.0 March 21, 2024

Expand Down
5 changes: 5 additions & 0 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder;
use Yiisoft\Db\Schema\Column\ColumnInterface;

Expand Down Expand Up @@ -38,6 +39,10 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder

public function build(ColumnInterface $column): string
{
if ($column->isUnsigned()) {
throw new NotSupportedException('The "unsigned" attribute is not supported by Oracle.');
}

return $this->buildType($column)
. $this->buildAutoIncrement($column)
. $this->buildDefault($column)
Expand Down
5 changes: 5 additions & 0 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ final class ColumnFactory extends AbstractColumnFactory
];
private const DATETIME_REGEX = "/^(?:TIMESTAMP|DATE|INTERVAL|to_timestamp(?:_tz)?\(|to_date\(|to_dsinterval\()\s*'(?:\d )?([^']+)/";

public function fromPseudoType(string $pseudoType, array $info = []): ColumnInterface
{
return parent::fromPseudoType($pseudoType, $info)->unsigned(false);
}

protected function columnDefinitionParser(): ColumnDefinitionParser
{
return new ColumnDefinitionParser();
Expand Down
11 changes: 11 additions & 0 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@

final class ColumnFactoryProvider extends \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider
{
public static function pseudoTypes(): array
{
$values = parent::pseudoTypes();

// Oracle doesn't support unsigned types
$values['upk'][1] = new IntegerColumn(primaryKey: true, autoIncrement: true, unsigned: false);
$values['ubigpk'][1] = new BigIntColumn(primaryKey: true, autoIncrement: true, unsigned: false);

return $values;
}

public static function dbTypes(): array
{
return [
Expand Down
7 changes: 6 additions & 1 deletion tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ public static function buildColumnDefinition(): array

$values = parent::buildColumnDefinition();

// Oracle does not support unsigned types
unset(
$values['bigint(15) unsigned'],
$values['unsigned()'],
);

$values[PseudoType::PK][0] = 'number(10) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
$values[PseudoType::UPK][0] = 'number(10) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
$values[PseudoType::BIGPK][0] = 'number(20) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY';
Expand Down Expand Up @@ -375,7 +381,6 @@ public static function buildColumnDefinition(): array
$values["integer()->defaultValue('')"][0] = 'number(10) DEFAULT NULL';
$values['size(10)'][0] = 'varchar2(10)';
$values['unique()'][0] = 'varchar2(255) UNIQUE';
$values['unsigned()'][0] = 'number(10)';
$values['scale(2)'][0] = 'number(10,2)';
$values['integer(8)->scale(2)'][0] = 'number(8)';
$values['reference($reference)'][0] = 'number(10) REFERENCES "ref_table" ("id") ON DELETE SET NULL';
Expand Down
Loading